Commit Graph

66 Commits

Author SHA1 Message Date
Kenneth Kehl
058a999ed0 ugh 2024-07-11 09:38:32 -07:00
stvnrlly
f600dd95d6 remove email branding 2023-12-18 16:10:12 -05:00
Carlo Costino
72c8a46b8c Reformatted a handful more tests
Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2023-10-12 10:24:48 -04:00
Kenneth Kehl
8c9721d8e2 notify-api-412 use black to enforce python coding style 2023-08-25 09:12:23 -07:00
Steven Reilly
13d0e46b52 blunt rename of org (#620) 2023-07-12 12:09:44 -04:00
stvnrlly
944715ac46 big commit with letters removal 2022-12-05 15:33:44 -05:00
stvnrlly
f16b5dd1c4 remove broadcast-related code 2022-10-04 03:04:13 +00:00
jimmoffet
69abec0bb3 change dashboard test to reflect demo changes to uploads view 2022-09-09 17:02:48 -07:00
jimmoffet
b465131338 all tests passing 2022-08-05 01:22:32 -07:00
Ben Thorner
3f2b760efb Remove redundant deletion decorators
These are superseded by the "_delete_template_cache_for_service"
call in each of these methods.
2022-03-07 13:54:00 +00:00
Ben Thorner
81d9c73543 Bump -utils to 55.0.0
This renames "delete_cache_keys_by_pattern" to match the new method
name, which will also catch exceptions if Redis is down [1].

Note that this also includes a change to RecipientCSV [2], which has
no effect because the new default is the same as the old behaviour.

[1]: https://github.com/alphagov/notifications-utils/pull/949
[2]: https://github.com/alphagov/notifications-utils/pull/947/files#diff-a8a994bf655634f89dc7439880708b4ff0d780ac1bd8033827d8aaa2692a8e0fR373
2022-03-07 13:53:57 +00:00
Katie Smith
5b52b6f9bf Clear user cache when broadcast service settings form is submitted
When the broadcast service settings form is submitted it now removes all
permissions for users in notifications-api. This means it should be
clearing the user cache.
2021-07-13 17:06:35 +01:00
Rebecca Law
77c2aa9fd6 Stop passing in today_only for the get_service_statistics method.
We now only ever call it with False.
To remove it from the api call will require a change in the API so will do that at another time.
2021-06-29 07:33:40 +01:00
Rebecca Law
44f02f2e30 To check the daily limit get the daily notification_count from redis.
The daily limit cache is set by the api when a notification is created. There is one cache key per service per day and it expires after 24 hours.
2021-06-23 15:56:05 +01:00
Andrew White
00c3943222 Disable the remaining messages check for uploads
The HTTP request for the statistics is taking more 30 seconds which leads to 504 errors from CloudFront.
2021-05-22 07:25:07 +01:00
Ben Thorner
5bfce61bcf Rename "app_" fixture to "notify_admin"
This naming was introduced in 2016 without explanation [1]. I find it
confusing because:

- It's reminiscent of "_app", which is a Python convention indicating
the variable is internal, so maybe avoid using it.

- It suggests there's some other "app" fixture I should be using (there
isn't, though).

The Python style guide describes using an underscore suffix to avoid
clashes with inbuilt names [1], which is sort of applicable if we need
to import the "app" module [2]. However, we can also avoid clashes by
choosing a different name, without the strange underscore.

[1]: 3b1d521c10
[2]: 78824f54fd/tests/app/main/views/test_forgot_password.py (L5)
2021-05-19 11:44:20 +01:00
David McDonald
f8f3d44511 Add form to set service broadcast account type
Note, no option at the moment to set the service broadcast account type
as None, or back to without the broadcast permission. This has been done
for speed of development given the chance of us needing this is very
low. We can add it later if we need to.
2021-02-23 16:03:14 +00:00
Pea Tyczynska
42b17d40b4 Test allowed attributes are really allowed 2021-02-02 16:38:56 +00:00
Rebecca Law
01a3df6edc Update _delete_template_cache_for_service to delete all template version cache and not just the one ending in "None"
Update all methods that were previous calling @cache.delete('service-{service-id}-template-None') to instead call _delete_template_cache_for_service
Remove call to get service templates, it's not needed since all template version cache is being deleted.
2021-01-25 16:28:20 +00:00
David McDonald
922d43ea1a Update tests/app/notify_client/test_service_api_client.py
Co-authored-by: Chris Hill-Scott <me@quis.cc>
2020-10-21 11:18:09 +01:00
David McDonald
2921c7302c Fix incorrect redis key deleting
We were trying to delete the old 'template-{template-id}' keys but
should have been deleting the new keys which have the service id as part
of the key name. This was causing the cache to not be correctly purged
when we did things like update sender names or set defaults. This should
fix it.
2020-10-21 11:14:23 +01:00
David McDonald
7b82ca5083 Remove deleting of old redis key
At this point we are no longer setting this key, nor are we reading from
it so we are able to delete it.
2020-10-02 15:21:30 +01:00
David McDonald
a538329d0e Use new redis key for service templates and broadcasts
We can drop use of the old key as we no longer need to read data from
the old key. Either data exists in the new key and we read it from there
or data doesn't exist in the new key and we go to the API to get it and
then set it in redis.

Note, the previous commit is important because it means we aren't at
risk of when this commit is being deployed out, of us getting stale data
from the old key.
2020-09-21 17:37:27 +01:00
David McDonald
e3baa9ba35 Step 1 of renaming cache keys for templates
We want to change cache keys for templates and broadcasts to include
their service ID. So cache keys should change from
`template-{template_id}-versions` to
`service-{service_id}-template-{template_id}-versions`.

The first step of this which needs to be deployed as a change first is
to delete both keys when updating service templates (even if they key is
not yet set). This means that when we release code in the next PR to
start setting the new key, we won't run into a case where either the old
or the new key can remain set with stale data.
2020-09-21 14:04:10 +01:00
Leo Hemsted
7e15d0c928 delete template cache when reply_to stuff is updated
sms sender, email reply to, letter contact blocks.

These are all cached within template, under `template.reply_to` - if the
template doesnt have a specific default, then that field stores the
service default. So when service default changes, we need to clear the
template cache so that it is updated to reflect that.

We already use this pattern for deleting the template cache for a bunch
of templates in `template_folder_api_client.move_to_folder`
2020-08-18 14:47:12 +01:00
Chris Hill-Scott
e0cb487093 Use new guest list API URLs
The API now[1] accepts requests on `…/guest-list` as well as
`…/whitelist`. This commit starts using the former, which means:
- the use of ‘whitelist’ is fully gone from the admin app
- the API can stop using it, at least in URLs

1. As of https://github.com/alphagov/notifications-api/pull/2928
2020-07-27 13:24:37 +01:00
Chris Hill-Scott
51e99bd828 Ask API for less detailed JSON for all templates
This should speed things up by:
- less time waiting for big blobs of JSON to come from Redis or the API
- less time spent deserialising big blobs of JSON
2020-06-19 10:32:44 +01:00
Chris Hill-Scott
16cc640822 Rename API client methods to remove term ‘whitelist’
See c31264d4c for rationale. To avoid confusion the codebase should use
the same terminology as the UI.
2020-06-12 10:27:18 +01:00
David McDonald
ee14ae33dc Use redis_client rather than wrapper method
Fixes a bug where we were calling a wrapper method when instead we
should have been calling the redis_client. This had resulted in no
actual calls to redis happening.
2020-05-27 11:56:07 +01:00
David McDonald
0fdda016e2 Refactor archive to do one sync delete of all keys rather than many
Otherwise we could be waiting on 50 sync calls to redis to happen. This
way we do it in one sync call and follow the pattern of
b98f4561fa/app/notify_client/organisations_api_client.py (L56)
2020-05-22 17:12:00 +01:00
David McDonald
a65ada0d7e Delete cached users and templates when archiving a service
When the admin app gets user objects from the API, these include a dict
of permissions by service for what the user can do to that services.
Permissions for inactive services are not included in the response as
per:
87cb6f2597/app/dao/permissions_dao.py (L66)

However, this causes a bug where a service is archived but cached user
data still tells us that the user has permissions to view the service.
This should not be the case and causes errors where users can still see
the archived service page, it's settings, and even request to go live
for it, because they are using old cached data for the user.

We solve this by deleting the users who are part of the service from the
cache.

We also delete the templates for this service from the cache as the
templates are also archived when we ask the API to archive the service
as per:
d95c0131e0/app/service/rest.py (L597)

Note, one decision I had to make was whether to delete the user cache
for just active team members or also invited users. Assuming an invited
user can't see the service until they've accepted their invite anyway, it
shouldn't make any difference whether we delete their cache or not.
2020-05-22 16:27:05 +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
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
Katie Smith
7368245c9a Show letter preview once file is uploaded
This shows the sanitised letter preview if the file had no validation
errors or the preview with the overlay if it failed validation.
2019-09-12 09:54:36 +01:00
Katie Smith
123b769771 Change code order for Redis delete decorator
Before, the delete decorator would delete the keys from Redis and then
we made the request to api to change the data. However, it is possible
that the cache could get re-populated in between these two things
happening, and so would cache outdated data.

This changes the order to send the api request first. We then always
delete the specified keys from Redis. Changing the order of the code in
the decorator changes the order in which the cache keys get deleted, so
the tests have been updated.
2019-07-26 16:29:50 +01:00
Chris Hill-Scott
17bf06d04c Let users delete letter contact blocks
Because they can delete email reply to addresses and text message
senders.
2019-07-22 11:57:11 +01:00
Chris Hill-Scott
700e073d0f Stop sending service domain to the API
The API doesn’t look at it, and the rest of the admin code isn’t calling
the method with this argument any more.
2019-04-12 17:15:51 +01:00
Katie Smith
c39f6d49ea Set folder permissions when creating and accepting invites to services
Added a folder permissions form to the page to invite users to services.
This only shows if the service has 'edit_folder_permissions' enabled,
and all folder checkboxes are checked by default. This change means that
InviteApiClient.create_invite now sends folder_permissions through to
notifications_api (so invites get created with folder permissions).

Started passing the folder_permissions through to notifications-api when
accepting an invite. This changes UserApiClient.add_user_to_service to
send folder_permissions to notifications_api so that new users get folder
permissions when they are added to the service.
2019-03-21 10:17:05 +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
Katie Smith
31a1c1ca51 Pass service domain to api when adding a new service
We need to pass the domain to api when adding a service so that api can
link the domain of the service with a letter brand.
2019-02-12 14:59:29 +00:00
Pea Tyczynska
db5378bac2 Edit template postage from a separate view 2019-02-04 14:45:33 +00:00
Chris Hill-Scott
21cec873d0 Stop calling fake_uuid fixture directly
Pytest is deprecating the direct calling of fixtures. One fixture that
we call directly quite a lot is `fake_uuid`. Since it just returns the
value of `sample_uuid()` we can either call that instead (where we need
a fixed value) or generate a new UUID each time (where a fixed value is
not needed).
2018-09-27 14:14:10 +01:00
Alexey Bezhan
28b03fe748 Add limit_days argument to statistics API client method
Allows getting notification counts for a given number of days to
support services with custom data retention periods (admin
dashboard page should still display counts for the last 7 days,
while the notifications page displays all stored notifications).
2018-08-13 17:04:40 +01:00
Leo Hemsted
78a6f86043 use service statistics endpoint instead of detailed service
we're not actually looking at the detailed service aspects - just
the stats. We're doing this in three places:

* dashboard
* notification activity page
* when checking jobs to see if we're over the daily limit

change these places to use a new api endpoint (service/id/statistics),
which hopefully be a little more performant, and will definitely be a
little more organised - moving away from generic endpoints with loads
of optional parameters.

We still need the detailed endpoints for the platform admin page tho.

Depends on https://github.com/alphagov/notifications-api/pull/1865
2018-05-09 14:00:24 +01:00
Katie Smith
0e370d511e Update service_api_client to use new endpoints
API now has separate endpoints to archive email reply-to addresses and
SMS senders, so we no longer need to use the endpoints for updating.
2018-05-01 08:38:54 +01:00
Leo Hemsted
2ceea61bb1 Merge pull request #2034 from alphagov/zendesk
send zendesk rather than deskpro tickets
2018-04-27 14:33:31 +01:00
Leo Hemsted
be038e345d define isort first party (app and tests)
we were seeing isort produce different outputs locally and in docker -
this was due to it having different opinions about whether the tests
module (ie all our unit tests) is a first party (local) or third party
(pip installed) import. It's a first party import, so by defining this
in the setup.cfg isort settings, we can force it to be consistent
between environments.

Note: I don't know why it was different in the first place though
2018-04-25 14:12:58 +01:00
Chris Hill-Scott
589dbea971 Make Redis hold onto cached API responses longer
Redis is giving us a big performance boost (it’s roughly halved the
median request time on the admin app).

Once we’re confident that it’s working properly[1] we can eke out a bit
more performance from it by keeping the caches alive for longer. As
far as I can tell we’re still using Redis in a very low-volume way[2],
so increasing the number of things we’re storing shouldn’t start taxing
our Redis server at all. But reducing the number of times we have to
hit the API to refresh the cache _should_ result in some performance
increase.

---

1. ie we’re not seeing instances of stale caches not being invalidated

2. We have 2.5G of available space in Redis. Here is our current usage:
```
used_memory:7728960
used_memory_human:7.37M
used_memory_rss:7728960
used_memory_peak:16563776
used_memory_peak_human:15.79M
used_memory_lua:37888
```
2018-04-23 17:07:41 +01:00
Chris Hill-Scott
222a67959a Add tests for all templates and template versions 2018-04-20 17:32:01 +01:00
Chris Hill-Scott
06de94f1c5 Rewrite cache decorator to use format string
This is easier to read than having to understand the arguments 1…n of
the cache decorator are ‘magic’, and gives us more flexibility about
how the cache keys are formatted, eg being able to add words in the
middle of them.

Also changes the key format for all templates to be
`service-{service_id}-templates` instead of `templates-{service_id}`
because then it’s clearer what the ID represents.
2018-04-20 16:32:02 +01:00