mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
forbid editing after broadcast message goes live
only allow editing while in: * draft * pending-approval * rejected (not too sure if/how this'll be used, so easier to include it for now)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
|
||||
import iso8601
|
||||
from flask import Blueprint, jsonify, request, current_app
|
||||
from flask import Blueprint, jsonify, request, current_app, abort
|
||||
|
||||
from app.config import QueueNames
|
||||
from app.dao.templates_dao import dao_get_template_by_id_and_service_id
|
||||
@@ -85,6 +85,12 @@ def update_broadcast_message(service_id, broadcast_message_id):
|
||||
|
||||
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:
|
||||
abort(
|
||||
400,
|
||||
f'Cannot update broadcast_message {broadcast_message.id} while it has status {broadcast_message.status}'
|
||||
)
|
||||
|
||||
if 'personalisation' in data:
|
||||
broadcast_message.personalisation = data['personalisation']
|
||||
if 'starts_at' in data:
|
||||
|
||||
@@ -2172,6 +2172,10 @@ class BroadcastStatusType(db.Model):
|
||||
|
||||
STATUSES = [DRAFT, PENDING_APPROVAL, REJECTED, BROADCASTING, COMPLETED, CANCELLED, TECHNICAL_FAILURE]
|
||||
|
||||
# a broadcast message can be edited while in one of these states
|
||||
PRE_BROADCAST_STATUSES = [DRAFT, PENDING_APPROVAL, REJECTED]
|
||||
LIVE_STATUSES = [BROADCASTING, COMPLETED, CANCELLED]
|
||||
|
||||
name = db.Column(db.String, primary_key=True)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user