mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 22:40:31 -04:00
Allow broadcasts to be cancelled
Currently this is a `get` request from the dashboard. Once we have a page for viewing an individual broadcast it should probably show there instead and be a `get`/confirm/`post` loop like for deleting a template.
This commit is contained in:
@@ -124,3 +124,17 @@ def preview_broadcast_message(service_id, broadcast_message_id):
|
|||||||
'views/broadcast/preview-message.html',
|
'views/broadcast/preview-message.html',
|
||||||
broadcast_message=broadcast_message,
|
broadcast_message=broadcast_message,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@main.route('/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/cancel')
|
||||||
|
@user_has_permissions('send_messages')
|
||||||
|
@service_has_permission('broadcast')
|
||||||
|
def cancel_broadcast_message(service_id, broadcast_message_id):
|
||||||
|
BroadcastMessage.from_id(
|
||||||
|
broadcast_message_id,
|
||||||
|
service_id=current_service.id,
|
||||||
|
).cancel_broadcast()
|
||||||
|
return redirect(url_for(
|
||||||
|
'.broadcast_dashboard',
|
||||||
|
service_id=current_service.id,
|
||||||
|
))
|
||||||
|
|||||||
@@ -125,6 +125,13 @@ class BroadcastMessage(JSONModel):
|
|||||||
service_id=self.service_id,
|
service_id=self.service_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def cancel_broadcast(self):
|
||||||
|
broadcast_message_api_client.update_broadcast_message_status(
|
||||||
|
'cancelled',
|
||||||
|
broadcast_message_id=self.id,
|
||||||
|
service_id=self.service_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BroadcastMessages(ModelList):
|
class BroadcastMessages(ModelList):
|
||||||
|
|
||||||
|
|||||||
@@ -358,6 +358,7 @@ class HeaderNavigation(Navigation):
|
|||||||
'choose_broadcast_area',
|
'choose_broadcast_area',
|
||||||
'remove_broadcast_area',
|
'remove_broadcast_area',
|
||||||
'preview_broadcast_message',
|
'preview_broadcast_message',
|
||||||
|
'cancel_broadcast_message',
|
||||||
}
|
}
|
||||||
|
|
||||||
# header HTML now comes from GOVUK Frontend so requires a boolean, not an attribute
|
# header HTML now comes from GOVUK Frontend so requires a boolean, not an attribute
|
||||||
@@ -413,6 +414,7 @@ class MainNavigation(Navigation):
|
|||||||
'choose_broadcast_area',
|
'choose_broadcast_area',
|
||||||
'remove_broadcast_area',
|
'remove_broadcast_area',
|
||||||
'preview_broadcast_message',
|
'preview_broadcast_message',
|
||||||
|
'cancel_broadcast_message',
|
||||||
},
|
},
|
||||||
'uploads': {
|
'uploads': {
|
||||||
'upload_contact_list',
|
'upload_contact_list',
|
||||||
@@ -1001,6 +1003,7 @@ class CaseworkNavigation(Navigation):
|
|||||||
'choose_broadcast_area',
|
'choose_broadcast_area',
|
||||||
'remove_broadcast_area',
|
'remove_broadcast_area',
|
||||||
'preview_broadcast_message',
|
'preview_broadcast_message',
|
||||||
|
'cancel_broadcast_message',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1318,4 +1321,5 @@ class OrgNavigation(Navigation):
|
|||||||
'choose_broadcast_area',
|
'choose_broadcast_area',
|
||||||
'remove_broadcast_area',
|
'remove_broadcast_area',
|
||||||
'preview_broadcast_message',
|
'preview_broadcast_message',
|
||||||
|
'cancel_broadcast_message',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,15 +24,20 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call field(align='right') %}
|
{% call field(align='right') %}
|
||||||
<p class="govuk-body govuk-!-margin-top-6 govuk-!-margin-bottom-0">
|
{% if item.status == 'broadcasting' %}
|
||||||
{% if item.status == 'broadcasting' %}
|
<p class="govuk-body letter-recipient-summary">
|
||||||
Live until {{ item.finishes_at|format_datetime_relative }}
|
Live until {{ item.finishes_at|format_datetime_relative }}
|
||||||
{% elif item.status == 'cancelled' %}
|
<a href="{{ url_for('.cancel_broadcast_message', service_id=current_service.id, broadcast_message_id=item.id) }}" class="destructive-link destructive-link--no-visited-state">Stop broadcasting</a>
|
||||||
|
</p>
|
||||||
|
{% elif item.status == 'cancelled' %}
|
||||||
|
<p class="govuk-body govuk-!-margin-top-6 govuk-!-margin-bottom-0">
|
||||||
Stopped {{ item.cancelled_at|format_datetime_relative }}
|
Stopped {{ item.cancelled_at|format_datetime_relative }}
|
||||||
{% else %}
|
</p>
|
||||||
|
{% else %}
|
||||||
|
<p class="govuk-body govuk-!-margin-top-6 govuk-!-margin-bottom-0">
|
||||||
Finished {{ item.finishes_at|format_datetime_relative }}
|
Finished {{ item.finishes_at|format_datetime_relative }}
|
||||||
{% endif %}
|
</p>
|
||||||
</p>
|
{% endif %}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ def test_broadcast_dashboard(
|
|||||||
assert [
|
assert [
|
||||||
normalize_spaces(row.text) for row in page.select('table')[0].select('tbody tr')
|
normalize_spaces(row.text) for row in page.select('table')[0].select('tbody tr')
|
||||||
] == [
|
] == [
|
||||||
'Example template To England and Scotland Live until tomorrow at 2:20am',
|
'Example template To England and Scotland Live until tomorrow at 2:20am Stop broadcasting',
|
||||||
]
|
]
|
||||||
assert [
|
assert [
|
||||||
normalize_spaces(row.text) for row in page.select('table')[1].select('tbody tr')
|
normalize_spaces(row.text) for row in page.select('table')[1].select('tbody tr')
|
||||||
@@ -275,3 +275,28 @@ def test_start_broadcasting(
|
|||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
broadcast_message_id=fake_uuid,
|
broadcast_message_id=fake_uuid,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_cancel_broadcast(
|
||||||
|
client_request,
|
||||||
|
service_one,
|
||||||
|
mock_get_draft_broadcast_message,
|
||||||
|
mock_update_broadcast_message_status,
|
||||||
|
fake_uuid,
|
||||||
|
):
|
||||||
|
service_one['permissions'] += ['broadcast']
|
||||||
|
client_request.get(
|
||||||
|
'.cancel_broadcast_message',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
broadcast_message_id=fake_uuid,
|
||||||
|
_expected_redirect=url_for(
|
||||||
|
'.broadcast_dashboard',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
_external=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
mock_update_broadcast_message_status.assert_called_once_with(
|
||||||
|
'cancelled',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
broadcast_message_id=fake_uuid,
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user