mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 02:23:19 -04:00
Refactor to reduce duplication
> Rule of three ("Three strikes and you refactor") is a code refactoring
> rule of thumb to decide when similar pieces of code should be
> refactored to avoid duplication. It states that two instances of
> similar code don't require refactoring, but when similar code is used
> three times, it should be extracted into a new procedure
– https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming)
This commit is contained in:
+13
-28
@@ -373,35 +373,20 @@ def view_broadcast(service_id, broadcast_message_id):
|
|||||||
if broadcast_message.status == 'draft':
|
if broadcast_message.status == 'draft':
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
if (
|
for statuses, endpoint in (
|
||||||
broadcast_message.status in {'completed', 'cancelled'}
|
({'completed', 'cancelled'}, 'main.view_previous_broadcast'),
|
||||||
and request.endpoint != 'main.view_previous_broadcast'
|
({'broadcasting', 'pending-approval'}, 'main.view_current_broadcast'),
|
||||||
|
({'rejected'}, 'main.view_rejected_broadcast'),
|
||||||
):
|
):
|
||||||
return redirect(url_for(
|
if (
|
||||||
'.view_previous_broadcast',
|
broadcast_message.status in statuses
|
||||||
service_id=current_service.id,
|
and request.endpoint != endpoint
|
||||||
broadcast_message_id=broadcast_message.id,
|
):
|
||||||
))
|
return redirect(url_for(
|
||||||
|
endpoint,
|
||||||
if (
|
service_id=current_service.id,
|
||||||
broadcast_message.status in {'broadcasting', 'pending-approval'}
|
broadcast_message_id=broadcast_message.id,
|
||||||
and request.endpoint != 'main.view_current_broadcast'
|
))
|
||||||
):
|
|
||||||
return redirect(url_for(
|
|
||||||
'.view_current_broadcast',
|
|
||||||
service_id=current_service.id,
|
|
||||||
broadcast_message_id=broadcast_message.id,
|
|
||||||
))
|
|
||||||
|
|
||||||
if (
|
|
||||||
broadcast_message.status in {'rejected'}
|
|
||||||
and request.endpoint != 'main.view_rejected_broadcast'
|
|
||||||
):
|
|
||||||
return redirect(url_for(
|
|
||||||
'.view_rejected_broadcast',
|
|
||||||
service_id=current_service.id,
|
|
||||||
broadcast_message_id=broadcast_message.id,
|
|
||||||
))
|
|
||||||
|
|
||||||
back_link_endpoint = {
|
back_link_endpoint = {
|
||||||
'main.view_current_broadcast': '.broadcast_dashboard',
|
'main.view_current_broadcast': '.broadcast_dashboard',
|
||||||
|
|||||||
Reference in New Issue
Block a user