mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-25 08:43:55 -04:00
Merge pull request #3313 from alphagov/force-override-broadcast-178986763
Allow old broadcasts to be overridden
This commit is contained in:
@@ -157,11 +157,14 @@ def create_broadcast_message(service_id):
|
|||||||
def update_broadcast_message(service_id, broadcast_message_id):
|
def update_broadcast_message(service_id, broadcast_message_id):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
|
||||||
|
# TEMPORARY: while we migrate and backfill "areas"
|
||||||
|
force_override = data.pop("force_override", False)
|
||||||
|
|
||||||
validate(data, update_broadcast_message_schema)
|
validate(data, update_broadcast_message_schema)
|
||||||
|
|
||||||
broadcast_message = dao_get_broadcast_message_by_id_and_service_id(broadcast_message_id, service_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:
|
if not force_override and broadcast_message.status not in BroadcastStatusType.PRE_BROADCAST_STATUSES:
|
||||||
raise InvalidRequest(
|
raise InvalidRequest(
|
||||||
f'Cannot update broadcast_message {broadcast_message.id} while it has status {broadcast_message.status}',
|
f'Cannot update broadcast_message {broadcast_message.id} while it has status {broadcast_message.status}',
|
||||||
status_code=400
|
status_code=400
|
||||||
|
|||||||
@@ -385,6 +385,10 @@ def test_update_broadcast_message_allows_edit_while_not_yet_live(admin_request,
|
|||||||
assert response['updated_at'] is not None
|
assert response['updated_at'] is not None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('force_override', [
|
||||||
|
False,
|
||||||
|
pytest.param(True, marks=pytest.mark.xfail)
|
||||||
|
])
|
||||||
@pytest.mark.parametrize('status', [
|
@pytest.mark.parametrize('status', [
|
||||||
BroadcastStatusType.BROADCASTING,
|
BroadcastStatusType.BROADCASTING,
|
||||||
BroadcastStatusType.CANCELLED,
|
BroadcastStatusType.CANCELLED,
|
||||||
@@ -392,14 +396,17 @@ def test_update_broadcast_message_allows_edit_while_not_yet_live(admin_request,
|
|||||||
BroadcastStatusType.TECHNICAL_FAILURE,
|
BroadcastStatusType.TECHNICAL_FAILURE,
|
||||||
])
|
])
|
||||||
def test_update_broadcast_message_doesnt_allow_edits_after_broadcast_goes_live(
|
def test_update_broadcast_message_doesnt_allow_edits_after_broadcast_goes_live(
|
||||||
admin_request, sample_broadcast_service, status
|
admin_request,
|
||||||
|
force_override,
|
||||||
|
sample_broadcast_service,
|
||||||
|
status
|
||||||
):
|
):
|
||||||
t = create_template(sample_broadcast_service, BROADCAST_TYPE)
|
t = create_template(sample_broadcast_service, BROADCAST_TYPE)
|
||||||
bm = create_broadcast_message(t, areas=['manchester'], status=status)
|
bm = create_broadcast_message(t, areas=['manchester'], status=status)
|
||||||
|
|
||||||
response = admin_request.post(
|
response = admin_request.post(
|
||||||
'broadcast_message.update_broadcast_message',
|
'broadcast_message.update_broadcast_message',
|
||||||
_data={'areas': ['london', 'glasgow']},
|
_data={'areas': ['london', 'glasgow'], 'force_override': force_override},
|
||||||
service_id=t.service_id,
|
service_id=t.service_id,
|
||||||
broadcast_message_id=bm.id,
|
broadcast_message_id=bm.id,
|
||||||
_expected_status=400
|
_expected_status=400
|
||||||
|
|||||||
Reference in New Issue
Block a user