Commit Graph

99 Commits

Author SHA1 Message Date
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
Tom Byers
c21f0940f9 Update all single field checkboxes
Includes adding some code to govukCheckboxesField
to add a single boolean-like option by default, if
there are no choices added.
2020-07-24 11:34:01 +01:00
Tom Byers
dfcddb757e Revert "Re-introduce govuk checkboxes" 2020-07-15 13:41:34 +01:00
Tom Byers
d1ae3b812a Update all single field checkboxes
Includes adding some code to govukCheckboxesField
to add a single boolean-like option by default, if
there are no choices added.
2020-07-14 10:41:09 +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
Tom Byers
f0f461f5c9 Revert "Change checkboxes to GOVUK frontend" 2020-05-14 16:59:34 +01:00
Tom Byers
49ec2d77bb Update all single field checkboxes
Includes adding some code to govukCheckboxesField
to add a single boolean-like option by default, if
there are no choices added.
2020-05-13 17:37:44 +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
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
Chris Hill-Scott
37d844ba12 Clean up more things to do with letter validation
Missed these in https://github.com/alphagov/notifications-admin/pull/3201
2019-11-27 16:25:25 +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
Chris Hill-Scott
ef335e7601 Require IDs to be UUIDs in URLS
We mostly rely on the API returning a 404 to generate 404s for trying
to get things with non-UUID IDs. This is fine, except our tests often
mock these API calls. So it could look like everything is working fine,
except the thing your passing in might never be a valid UUID, and thus
would 404 in a non-test environment.

So this commit:
1. uses the `uuid` URL converter everywhere there’s something that looks
   like an ID in a URL parameter
2.  adds a test which automates checking for 1.
2019-11-07 13:46:25 +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
Pea Tyczynska
f2c7eb5c3e Tell user why validation failed on letter validation page - part 1 2019-11-06 12:21:18 +00:00
Rebecca Law
18e3eb6b32 Update tests for content changes. 2019-09-23 13:22:28 +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
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
b620b677d3 Have permissions decorators check user signed in
Rather than force us to write the decorators in a specific order let’s
just have one decorator call the other. This should make fewer lines of
code, and fewer annoying test failures. It also means that the same way
of raising a `401` (through the `current_app` method) is used
everywhere.
2019-07-03 09:54:35 +01:00
Chris Hill-Scott
3da9e84ece Enforce order of permissions decorators
At the moment we mostly have `user_has_permissions` execute first. It
shouldn’t matter, but it feels right for us to check that a user is
logged in before we check their permissions to a service. Otherwise a
malicious user could (maybe) check if a service ID belongs to a real
service, and go on to do something malicious with that information.

This commit adds some extra test code to enforce that the order is
always the same.

N.B. decorators in Python execute from closest to furthest (from the
line on which the function is defined).
2019-07-03 09:54:17 +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
c559ff8c97 refactored live_services_csv
with the aim of making the link between api return values and csv
column headers more apparent
2019-05-31 12:13:34 +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
Rebecca Law
8fd5fa90ff Make the letter-validation-preview url public.
In the short term I have created a duplicate version of the letter-validation-preview so that people from a service can upload a pdf and see why the letter isnot validating.

It's hard to get a precompiled letter to validate when starting to integrate with Notify. This will return the overlay of the letter validation and is now available to the services.
At the moment they send us a PDF to upload.
This is temporary because there is a story to create a one-off flow to get this overlay, that will replace this page.

There is no navigation to this on purpose.
2019-03-19 16:00:15 +00:00
Leo Hemsted
bfefb115ed move choices from form to view
so that when updating, you don't have to update two separate places
2019-02-19 11:35:34 +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
Leo Hemsted
1dcba53daf add clear cache platform admin page
a form that allows you to clear entries from the cache for all of
either users, services or templates. It'll tell you the largest amount
of keys deleted, since there are multiple keys associated with each
model.
2019-02-15 11:44:08 +00:00
Leo Hemsted
f6367f2278 move (non-api) clients (inc redis) from app/__init__.py to extensions
when clients are defined in app/__init__.py, it increases the chance of 
cyclical imports. By moving module level client singletons out to a 
separate extensions file, we stop cyclical imports, but keep the same 
code flow - the clients are still initialised in `create_app` in 
`__init__.py`.

The redis client in particular is no longer separate - previously redis 
was set up on the `NotifyAdminAPIClient` base class, but now there's one 
singleton in `app.extensions`. This was done so that we can access redis 
from outside of the existing clients.
2019-02-15 11:44:08 +00:00
Leo Hemsted
c898284c3b fix pdf download link trying to request a page count
It doesn't make sense to get a pdf for only one page - the template
preview app just returns a 400 if you try. So we shouldn't try!
2018-10-15 14:32:10 +01:00
Pea Tyczynska
291b2cf2ba Improve error handling for precompiled validation preview 2018-10-05 16:27:57 +01: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
3cdacaaf0a Introduce validation and error handling for validation preview 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