Clear service cache for when updating org branding

Updating an organisation’s branding might now also update the branding
of services associated to that organisation. This is similar to how
updating an organisation’s type can update the organisation type for its
services.

In the latter case we already make sure to clear the cached version of
these services which is held in Redis.

This commit does the same clearing of the caches when updating an
organisation’s branding (and does a bit of refactoring to do so without
duplication of code.)
This commit is contained in:
Chris Hill-Scott
2019-10-03 11:57:24 +01:00
parent 8b9cc5f4dc
commit 78e57dbff9
5 changed files with 36 additions and 15 deletions

View File

@@ -135,6 +135,10 @@ class Organisation(JSONModel):
def services(self):
return organisations_client.get_organisation_services(self.id)
@cached_property
def service_ids(self):
return [s['id'] for s in self.services]
@property
def live_services(self):
return [s for s in self.services if s['active'] and not s['restricted']]
@@ -180,8 +184,12 @@ class Organisation(JSONModel):
self.letter_branding_id
)
def update(self, **kwargs):
response = organisations_client.update_organisation(self.id, **kwargs)
def update(self, delete_services_cache=False, **kwargs):
response = organisations_client.update_organisation(
self.id,
cached_service_ids=self.service_ids if delete_services_cache else None,
**kwargs
)
self.__init__(response)
def associate_service(self, service_id):