Merge pull request #3459 from alphagov/delete-cache-on-archive

Delete cached users and templates when archiving a service
This commit is contained in:
David McDonald
2020-05-27 10:19:48 +01:00
committed by GitHub
4 changed files with 27 additions and 3 deletions

View File

@@ -302,7 +302,11 @@ def archive_service(service_id):
):
abort(403)
if request.method == 'POST':
service_api_client.archive_service(service_id)
# We need to purge the cache for the services users as otherwise, although they will have had their permissions
# removed in the DB, they would still have permissions in the cache to view/edit/manage this service
cached_service_user_ids = [user.id for user in current_service.active_users]
service_api_client.archive_service(service_id, cached_service_user_ids)
flash(
'{} was deleted'.format(current_service.name),
'default_with_tick',

View File

@@ -129,7 +129,10 @@ class ServiceAPIClient(NotifyAdminAPIClient):
return self.update_service(service_id, **properties)
@cache.delete('service-{service_id}')
def archive_service(self, service_id):
@cache.delete('service-{service_id}-templates')
def archive_service(self, service_id, cached_service_user_ids):
if cached_service_user_ids:
cache.delete(*map('user-{}'.format, cached_service_user_ids))
return self.post('/service/{}/archive'.format(service_id), data=None)
@cache.delete('service-{service_id}')