Hardcode service broadcast channel that API shows

We are in a weird situation where at the moment, we have services with
the broadcast permission that do not have a row in the
service_broadcast_settings table and therefore do not have defined
whether they should send messages on the 'test' or 'severe' channel.

We currently get around this when we send broadcast messages out as
such:
https://github.com/alphagov/notifications-api/blob/master/app/celery/broadcast_message_tasks.py#L51

We need to something equivalent for the broadcast channel that the API
says the service is on. In time, when we have added a row in the
service_broadcast_settings table for every service with the broadcast
permission then we can remove both of these two hardcodings.

Note, one option would have been to move the default of `test` on to the
`Service` model rather than having it in both the
broadcast_message_tasks file and the `ServiceSchema` class. However, I
went for the quickest thing which was to add it here.
This commit is contained in:
David McDonald
2021-02-12 15:26:03 +00:00
parent d846ed79d2
commit 42163813fe
2 changed files with 41 additions and 2 deletions

View File

@@ -25,7 +25,7 @@ from notifications_utils.recipients import (
from app import ma
from app import models
from app.models import ServicePermission
from app.models import ServicePermission, BROADCAST_TYPE
from app.dao.permissions_dao import permission_dao
from app.utils import DATETIME_FORMAT_NO_TIMEZONE, get_template_instance
@@ -242,7 +242,14 @@ class ServiceSchema(BaseSchema, UUIDsAsStringsMixin):
return service.allowed_broadcast_provider
def _get_broadcast_channel(self, service):
return service.broadcast_channel
# TODO: Once we've migrated data so that all broadcast services have `service.broadcast_channel`
# set then we can remove this logic and related tests and instead just return
# `service.broadcast_channel`. For the moment though, as we have some services with the broadcast
# permission that do not have a row in the service_broadcast_settings table, we need to hardcode
# this in here to give them a default that the admin app can use
if BROADCAST_TYPE in self.service_permissions(service):
return service.broadcast_channel if service.broadcast_channel else "test"
return None
def get_letter_logo_filename(self, service):
return service.letter_branding and service.letter_branding.filename