Allow old broadcasts to be overridden

This is a temporary feature to make it easy to migrate the format
of the "areas" column and backfill extra data for it.

It's not possible to use this feature to update the status of an
old broadcast message, so the risk from this override is minimal.
This commit is contained in:
Ben Thorner
2021-08-26 12:39:16 +01:00
parent 6edc6c70aa
commit 44b388dc69
2 changed files with 13 additions and 3 deletions

View File

@@ -157,11 +157,14 @@ def create_broadcast_message(service_id):
def update_broadcast_message(service_id, broadcast_message_id):
data = request.get_json()
# TEMPORARY: while we migrate and backfill "areas"
force_override = data.pop("force_override", False)
validate(data, update_broadcast_message_schema)
broadcast_message = dao_get_broadcast_message_by_id_and_service_id(broadcast_message_id, service_id)
if broadcast_message.status not in BroadcastStatusType.PRE_BROADCAST_STATUSES:
if not force_override and broadcast_message.status not in BroadcastStatusType.PRE_BROADCAST_STATUSES:
raise InvalidRequest(
f'Cannot update broadcast_message {broadcast_message.id} while it has status {broadcast_message.status}',
status_code=400