mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-18 05:30:21 -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:
@@ -373,35 +373,20 @@ def view_broadcast(service_id, broadcast_message_id):
|
||||
if broadcast_message.status == 'draft':
|
||||
abort(404)
|
||||
|
||||
if (
|
||||
broadcast_message.status in {'completed', 'cancelled'}
|
||||
and request.endpoint != 'main.view_previous_broadcast'
|
||||
for statuses, endpoint in (
|
||||
({'completed', 'cancelled'}, 'main.view_previous_broadcast'),
|
||||
({'broadcasting', 'pending-approval'}, 'main.view_current_broadcast'),
|
||||
({'rejected'}, 'main.view_rejected_broadcast'),
|
||||
):
|
||||
return redirect(url_for(
|
||||
'.view_previous_broadcast',
|
||||
service_id=current_service.id,
|
||||
broadcast_message_id=broadcast_message.id,
|
||||
))
|
||||
|
||||
if (
|
||||
broadcast_message.status in {'broadcasting', 'pending-approval'}
|
||||
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,
|
||||
))
|
||||
if (
|
||||
broadcast_message.status in statuses
|
||||
and request.endpoint != endpoint
|
||||
):
|
||||
return redirect(url_for(
|
||||
endpoint,
|
||||
service_id=current_service.id,
|
||||
broadcast_message_id=broadcast_message.id,
|
||||
))
|
||||
|
||||
back_link_endpoint = {
|
||||
'main.view_current_broadcast': '.broadcast_dashboard',
|
||||
|
||||
Reference in New Issue
Block a user