Ensure broadcast with no areas cannot be approved

This is already checked by admin app, but we want to have a
fallback safety measure as a precaution.
This commit is contained in:
Pea Tyczynska
2020-09-02 18:10:56 +01:00
parent bceb5d8fde
commit 2f6b96dafc
2 changed files with 55 additions and 5 deletions

View File

@@ -59,6 +59,11 @@ def _update_broadcast_message(broadcast_message, new_status, updating_user):
f'User {updating_user.id} cannot approve their own broadcast_message {broadcast_message.id}',
status_code=400
)
elif not broadcast_message.areas:
raise InvalidRequest(
f'broadcast_message {broadcast_message.id} has no selected areas and so cannot be broadcasted.',
status_code=400
)
else:
broadcast_message.approved_at = datetime.utcnow()
broadcast_message.approved_by = updating_user