Commit Graph

96 Commits

Author SHA1 Message Date
Chris Hill-Scott
d8b265b0ca Add comments to make test data clearer
It’s not clear where 103 is coming from unless you know that the code is
doing the slightly unintuitive thing of displaying the max of all return
values.
2020-10-12 14:14:12 +01:00
Chris Hill-Scott
54d4fb2a6c Allow platform admins to clear cached broadcasts
When we add a new property to the broadcast model, we need to delete any
cached broadcasts from Redis that are missing the new property. So this
adds an option to do this to the cache page in platform admin.

I’ve also tried to make it more obvious what the magic numbers in the
test fixture are doing.
2020-10-09 15:41:48 +01:00
Leo Hemsted
6eccc66115 delete template keys properly from platform admin page 2020-10-05 16:52:48 +01:00
Chris Hill-Scott
1e55a8cbbe Remove uses of .assert_not_called
I prefer to avoid `assert_not_called`, because if I make a typo like
this, the tests will still pass:
```
    app.invite_api_client.create_invite.asset_not_called()
```

It’s harder to have a false positive with the statement written this
way:
```
    assert app.invite_api_client.create_invite.called is False
```
2020-08-28 13:26:14 +01:00
Tom Byers
c715681f5c Convert DateFields to GovukDateFields
Changes those fields in the following forms:
- DateFilterForm
- RequiredDateFilterForm

Includes changes to templates that use this form
and associated tests.
2020-08-12 10:34:51 +01:00
Chris Hill-Scott
fb4076dc5b Don’t break statistics down by sending/failed/delivered
This should:
- make the page load faster because it has to render less HTML for each
  service
- make the page easier to scan for services that are sending lots of
  text messages or letters

We used to scan this page to look for services with high failure rates,
and the design of the page was gear towards this. Now we have alerting
for high failure rates, so the page can focus on volumes instead.

This commit also puts the service name above the statistics, so that
long service names don’t break the layout of the page.
2020-06-24 11:45:32 +01:00
Chris Hill-Scott
65bb72ef2f Bump WTForms to 2.3.1
This involves three changes which broke our code.

To validate email addresses, the optional dependency `email-validator`
must be installed<sup>1</sup>. But since we don’t use WTForms’ email
validation, we shouldn’t need to subclass it – it can just be its own
self contained thing. Then we don’t need to add the extra dependency.

When rendering textareas, and extra `\r\n` is inserted at the beginning
<sup>2</sup>. Browsers will strip this when displaying the textbox and
submitting the form, but some of our tests need updating to account for
this.

The error message for when you don’t choose an option from some radio
buttons has now changed. Rather than just accepting WTForms’ new
message, this commit makes the error messages like the examples from
the Design System<sup>3</sup>. By default it will say ‘Select an
option’, but by passing in an extra parameter (`thing`) it can be
customised to be more specific, for example ‘Select a type of
organisation’.

***

1. https://github.com/wtforms/wtforms/pull/429
2. https://github.com/wtforms/wtforms/issues/238
3. https://design-system.service.gov.uk/components/radios/#error-messages
2020-04-23 12:57:10 +01:00
Chris Hill-Scott
cc5701e870 Cache organisation name in Redis
A lot of pages in the admin app are now generated entirely from Redis,
without touching the API.

The one remaining API call that a lot of pages make, when the user is
platform admin or a member of an organisation, is to get the name of
the current service’s organisation.

This commit adds some code to start caching that as well, which should
speed up page load times for when we’re clicking around the admin app
(it’s typically 100ms just to get the organisation, and more than that
when the API is under load).

This means changing the service model to get the organisation from the
API by ID, not by service ID. Otherwise it would be very hard to clear
the cache if the name of the organisation ever changed.

We can’t cache the whole organisation because it has a
`count_of_live_services` field which can change at any time, without an
update being made.
2020-04-02 12:07:19 +01:00
Chris Hill-Scott
61d87bf6c0 Let platform admins delete returned letters cache
Just in case there’s ever a problem with something in these caches. We
missed this before.
2020-04-01 10:18:56 +01:00
Chris Hill-Scott
7fb8e1de92 Use statistics for returned letters on dashboard
This should be faster and more accurate than querying all the reports.
2020-04-01 10:18:55 +01:00
Chris Hill-Scott
2a76fd9ee8 Reduce usage of the platform admin index page
This page is slow to load which means:
- it’s annoying for us
- it’s potentially causing load on the database

This commit does two things to reduce the amount we’re unnecessarily
looking at this page:

1. Avoid redirecting to it when signing in as a platform admin user
2. Don’t go directly to it when clicking ‘platform admin’ at the top,
   but instead show a holding page (there’s a fair chance you’ve clicked
   that link in order to go and manage some email branding or find a
   user, not wait for stats to load)
2020-03-19 10:59:21 +00:00
Katie Smith
07bcb4220e Replace column-one-third with govuk-grid-column-one-third
Also replaces `column-third`, with `govuk-grid-column-one-third`, since
this appears to be an alias of `column-one-third`.
2020-03-06 11:11:41 +00:00
Chris Hill-Scott
af8395956e Cache returned letter summary in Redis
We’re going to start using the returned letters summary to show some
info on the dashboard.

This means we will be accessing it more often than it changes. And we
know exactly when it changes because it’s us manually submitting the
references we get from DVLA.

This makes it a good candidate for being cached, and Redis is where we
cache stuff that we’d otherwise go to the API for.
2020-02-12 11:42:06 +00:00
Leo Hemsted
6ad9ec8d21 flake8 2019-11-29 15:25:37 +00:00
Chris Hill-Scott
b9de27d1c2 Remove the letter validation preview endpoints
We can use the ‘Uploads’ feature to check if letters are printable now.

This code works in a completely different way, so if we kept it we’d
have to maintain two different code paths, and make sure that they
didn’t diverge.

Also deletes the related HTML templates.
2019-11-27 14:28:42 +00:00
Pea Tyczynska
678e0bed81 Show users more detailed validation failed mesage on notification page
Show valdiation failed messages on letter notifications in red text,
not in the banner like we do on Uploads and Validation checker pages.
This is because it is a different step in the journey: the user
has already sent the notification and styling needs to be in line
with other places where user is checking the notification she already
has sent.
2019-11-07 11:10:27 +00:00
Pea Tyczynska
f12dc823cb Show dynamic message when letter fails validation in validation checker - part 2 2019-11-06 14:26:16 +00:00
Katie Smith
3b3f74bbf0 Use the new error messages when uploading a letter
We now use the pattern of showing a box at the top of the page with the
error. The error message has a heading and can have additional details.
Error messages and the invalid pages get stored in the S3 metadata.
2019-10-21 08:37:55 +01:00
Rebecca Law
18e3eb6b32 Update tests for content changes. 2019-09-23 13:22:28 +01:00
karlchillmaid
0835d1679a Replace can't with cannot 2019-09-23 13:21:08 +01:00
Katie Smith
c577416866 Add letter upload form which redirects to blank preview page
Added a form to upload a single letter. Currently this only uses the
form to validate that a file is submitted and that the file is a PDF. If
either of these validations fail, the form will display an error.
Otherwise, we redirect to a new preview page which just has the filename
as the heading for now.
2019-09-12 09:54:36 +01:00
Leo Hemsted
6412a4ab33 use a flash error message on the platform admin usage report
that makes more sense than attaching the error to a field

also fix tests and assert csv contents are correct
2019-08-29 10:49:38 +01:00
Leo Hemsted
b69321bf7a rename logged_in_platform_admin_client to platform_admin_client
of course it's logged in, it's a platform admin

also, reduce use of the `client` fixture in test_platform_admin
(replace it with platform_admin_client)
2019-08-27 16:02:15 +01:00
Rebecca Law
464a74b329 fix codestyle 2019-08-23 17:18:05 +01:00
Rebecca Law
2fe5c4a96e New report on platform-admin/reports page to get the usage for all services. 2019-08-23 17:14:04 +01:00
Katie Smith
9dc13f1d8e Add new report to show monthly notification stats for each service
This report will be used by the engagement team. There is a form to give
a start and end date for the report, and the form is then downloaded
as a CSV file when the form is submitted.
2019-07-23 11:32:28 +01:00
Chris Hill-Scott
91f2da8b68 Ensure all service route have permission decorators
We accidentally miss these sometimes. This code adds a test which
inspects the code to automatically check that any function which:
- handles a route
- accepts a service_id

For each function it checks that each of these routes have the
permissions decorator we’d expect.

Most of the introspection/AST code is adapted from here:
https://mvdwoord.github.io/exploration/2017/08/18/ast_explore.html
2019-07-03 09:47:20 +01:00
Chris Hill-Scott
8f9ade7a8b Cache organisations, not just domains in Redis
This should make the ‘All organisations’ page load a lil’ bit quicker.
Still worth caching the domains separately so the response is smaller
when we only care about domains. This is because the code that uses the
domains is part of the sign up flow, so it’s really important that it’s
snappy.
2019-06-14 11:20:19 +01:00
Leo Hemsted
fb0279b820 return free sms allowance in live services csv report 2019-05-31 12:24:18 +01:00
Leo Hemsted
daa8868fd8 make test marginally more readable 2019-05-31 12:22:54 +01:00
Chris Hill-Scott
55d4810c4b Don’t convert Excel reports to CSV before output
Converting Python data to CSV makes every field a string. This means
that in the report we return to the user every field will be a string,
even if it’s come from an `int` type in Python. This is because the CSV
‘standard’ doesn’t support any kind of typing.

Excel does support types for fields, so we can make our reports more
useful by preserving these types. This is particularly relevant in the
report we generate for performance platform, which needs the `count`
column to be a number type.

This commit adds extra code paths to the `Spreadsheet` class which mean
that it can be instantiated from either CSV data or a list of Python
data. Previously we were converting the Python data to CSV as an
intermediate step, before instantiating the class.
2019-05-07 16:07:23 +01:00
Pea (Malgorzata Tyczynska)
a7d8918ee0 Merge pull request #2951 from alphagov/performance-platform-xlsx
Provide Performance Platform report as Excel file
2019-05-03 15:59:06 +01:00
Chris Hill-Scott
3c38a7be05 Provide Performance Platform report as Excel file
This is the format we need to upload it in, so this means not having to
manually re-save it as Excel.
2019-05-03 15:40:53 +01:00
Pea Tyczynska
a53849013a Add organisation type to live services csv report 2019-05-03 14:38:33 +01:00
Pea Tyczynska
0755e81c09 Allow for empty live_date field in live services csv reports
Earlier the report broke if there were services with an empty
live date
2019-05-01 18:30:01 +01:00
Pea Tyczynska
46e8a52f2b Add performance platform csv report and format live dates
Drop redundant Response wrapper
2019-05-01 16:00:09 +01:00
Pea Tyczynska
128bbd0d5f Add yearly notifications sent stats to live services report
Update live_services_csv so it works with new endpoint
2019-05-01 16:00:01 +01:00
Pea Tyczynska
b0a8c5edf6 Get live services csv report 2019-05-01 15:59:50 +01:00
Pea Tyczynska
b643aa54ec Basic reports page, returns 200 and is visible in PA sidebar 2019-04-24 10:44:25 +01:00
Rebecca Law
42e63667f7 Updated copy on the page.
Added unit tests.
Added error when file is too big.
2019-03-20 11:31:29 +00:00
Leo Hemsted
b062a5a13f make banner green (default) instead of red (dangerous) 2019-02-18 12:09:14 +00:00
Leo Hemsted
89bfdf27ce add tests 2019-02-15 11:44:09 +00:00
Pea Tyczynska
e6e363ba3f Add antivirus scan to letter validation preview view 2018-10-05 16:27:57 +01:00
Pea Tyczynska
a61393a68e Test letter validation preview flow 2018-10-05 15:46:44 +01:00
Pea Tyczynska
3be129241f Add letter validation preview functionality
- add get/post view
- create a pdf upload form
- add a template where user can upload the file
- check boundaries of the letter by calling template-preview
- display banner messages with boundaries validation result
- display pages of the document, with visible boundaries overlay
if the document did not pass validation, and without overlay
if they do pass validation
2018-10-05 15:46:44 +01:00
Alexey Bezhan
b75681dfbc Add a platform admin page to submit returned letter references
A platform admin form accepts a list of references (one per line)
received from DVLA and sends them to the API to update notification
statuses.

References we get from DVLA start with `NOTIFY00\d`, which isn't
part of the reference we store in the database, so we remove them
before sending the data to the API.

The new `returned-letter` status should be treated as `delivered`
for now until we decide a way to display returned letters to users.
2018-09-07 11:13:01 +01:00
Chris Hill-Scott
55054b81b5 Include test key data by default on platform admin
This is the existing behaviour. It’s broken by this issue in WTForms
2.2.1: https://github.com/wtforms/wtforms/issues/401

This commit hand-crafts the default value, because WTForms is ignoring
the `default` argument on the form object attribute.

Not really sure how this ever worked 🤔
2018-08-03 14:53:40 +01:00
Katie Smith
3bbc73dfd2 Use new platform-admin page
We had kept the original platform-admin page at `/platform-admin` and
created a new page, `/platform-admin-new` for the new platform admin
page. Now that the numbers on both pages look ok we no longer need both
pages, so can replace the original page.
2018-07-10 14:39:54 +01:00
Katie Smith
b27d29805b Raise error if getting complaints page with invalid page param
If the `page` parameter passed to the `platform-admin/complaints`
pageis not an integer, we should return a `404` error page.
2018-07-04 10:38:46 +01:00
Katie Smith
6c27a17e1e Paginate complaints page
The API now returns paginated complaint data, so the
`/platform-admin/complaints` page can now be paginated.
2018-07-03 11:09:33 +01:00