mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
add broadcast message status transition map
be explicit about which transitions we allow. this is not necessarily an exhaustive list of everything we'll allow
This commit is contained in:
@@ -41,16 +41,21 @@ def _update_broadcast_message(broadcast_message, new_status, updating_user):
|
||||
if updating_user not in broadcast_message.service.users:
|
||||
abort(
|
||||
400,
|
||||
f'User {updating_user.id} cannot approve broadcast {broadcast_message.id} from other service'
|
||||
f'User {updating_user.id} cannot approve broadcast_message {broadcast_message.id} from other service'
|
||||
)
|
||||
|
||||
if new_status not in BroadcastStatusType.ALLOWED_STATUS_TRANSITIONS[broadcast_message.status]:
|
||||
abort(
|
||||
400,
|
||||
f'Cannot move broadcast_message {broadcast_message.id} from {broadcast_message.status} to {new_status}'
|
||||
)
|
||||
|
||||
# TODO: Restrict status transitions
|
||||
if new_status == BroadcastStatusType.BROADCASTING:
|
||||
# TODO: Remove this platform admin shortcut when the feature goes live
|
||||
if updating_user == broadcast_message.created_by and not updating_user.platform_admin:
|
||||
abort(
|
||||
400,
|
||||
f'User {updating_user.id} cannot approve their own broadcast {broadcast_message.id}'
|
||||
f'User {updating_user.id} cannot approve their own broadcast_message {broadcast_message.id}'
|
||||
)
|
||||
else:
|
||||
broadcast_message.approved_at = datetime.utcnow()
|
||||
|
||||
Reference in New Issue
Block a user