mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-06 18:41:25 -04:00
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.
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
|
|
|
|
|
|
class BroadcastMessageAPIClient(NotifyAdminAPIClient):
|
|
|
|
def create_broadcast_message(
|
|
self,
|
|
*,
|
|
service_id,
|
|
template_id,
|
|
):
|
|
data = {
|
|
"service_id": service_id,
|
|
"template_id": template_id,
|
|
"personalisation": {},
|
|
}
|
|
|
|
data = _attach_current_user(data)
|
|
|
|
broadcast_message = self.post(
|
|
f'/service/{service_id}/broadcast-message',
|
|
data=data,
|
|
)
|
|
|
|
return broadcast_message
|
|
|
|
def get_broadcast_messages(self, service_id):
|
|
return self.get(f'/service/{service_id}/broadcast-message')['broadcast_messages']
|
|
|
|
@cache.set('broadcast-message-{broadcast_message_id}')
|
|
def get_broadcast_message(self, *, service_id, broadcast_message_id):
|
|
return self.get(f'/service/{service_id}/broadcast-message/{broadcast_message_id}')
|
|
|
|
@cache.delete('broadcast-message-{broadcast_message_id}')
|
|
@cache.delete('service-{service_id}-broadcast-message-{broadcast_message_id}')
|
|
def update_broadcast_message(self, *, service_id, broadcast_message_id, data):
|
|
self.post(
|
|
f'/service/{service_id}/broadcast-message/{broadcast_message_id}',
|
|
data=data,
|
|
)
|
|
|
|
@cache.delete('broadcast-message-{broadcast_message_id}')
|
|
@cache.delete('service-{service_id}-broadcast-message-{broadcast_message_id}')
|
|
def update_broadcast_message_status(self, status, *, service_id, broadcast_message_id):
|
|
data = _attach_current_user({
|
|
'status': status,
|
|
})
|
|
self.post(
|
|
f'/service/{service_id}/broadcast-message/{broadcast_message_id}/status',
|
|
data=data,
|
|
)
|
|
|
|
|
|
broadcast_message_api_client = BroadcastMessageAPIClient()
|