Files
notifications-admin/app/navigation.py
T

368 lines
11 KiB
Python
Raw Normal View History

2018-04-24 12:48:05 +01:00
from itertools import chain
from flask import request
2018-04-25 10:24:32 +01:00
class Navigation:
2018-04-24 12:48:05 +01:00
2018-04-25 10:24:32 +01:00
mapping = {}
2019-12-11 20:33:57 +00:00
selected_class = "selected"
2018-04-24 12:48:05 +01:00
2018-04-25 10:24:32 +01:00
def __init__(self):
self.mapping = {
navigation: {
# if not specified, assume endpoints are all in the `main` blueprint.
self.get_endpoint_with_blueprint(endpoint) for endpoint in endpoints
2018-04-25 10:24:32 +01:00
} for navigation, endpoints in self.mapping.items()
}
2018-04-24 12:48:05 +01:00
2018-04-25 10:24:32 +01:00
@property
def endpoints_with_navigation(self):
return tuple(chain.from_iterable((
endpoints
for navigation_item, endpoints in self.mapping.items()
)))
def is_selected(self, navigation_item):
if request.endpoint in self.mapping[navigation_item]:
2019-12-11 20:33:57 +00:00
return " " + self.selected_class
2018-04-25 10:24:32 +01:00
return ''
2018-04-24 12:48:05 +01:00
@staticmethod
def get_endpoint_with_blueprint(endpoint):
return endpoint if '.' in endpoint else 'main.{}'.format(endpoint)
2018-04-24 12:48:05 +01:00
class HeaderNavigation(Navigation):
mapping = {
'support': {
'bat_phone',
'feedback',
'support',
'support_public',
'thanks',
'triage',
},
'features': {
'features',
2019-04-11 11:47:09 +01:00
'features_email',
'features_letters',
'features_sms',
'message_status',
'roadmap',
'security',
'terms',
'trial_mode_new',
'using_notify',
},
'pricing': {
'pricing',
2019-06-04 10:43:15 +01:00
'how_to_pay',
2021-08-27 11:44:19 +01:00
'billing_details',
},
'documentation': {
'documentation',
'integration_testing',
},
'user-profile': {
'user_profile',
2022-03-18 13:08:09 +00:00
'user_profile_confirm_delete_mobile_number',
'user_profile_email',
'user_profile_email_authenticate',
'user_profile_email_confirm',
'user_profile_mobile_number',
'user_profile_mobile_number_authenticate',
'user_profile_mobile_number_confirm',
2022-03-18 13:08:09 +00:00
'user_profile_mobile_number_delete',
'user_profile_name',
'user_profile_password',
'user_profile_disable_platform_admin_view',
},
'platform-admin': {
2019-05-22 11:38:47 +01:00
'archive_user',
'change_user_auth',
2019-02-15 10:27:38 +00:00
'clear_cache',
'create_email_branding',
2019-01-31 16:56:35 +00:00
'create_letter_branding',
'edit_sms_provider_ratio',
'email_branding',
2019-08-13 16:25:26 +01:00
'find_services_by_name',
'find_users_by_email',
'letter_branding',
'live_services',
2019-04-24 16:23:12 +01:00
'live_services_csv',
'notifications_sent_by_service',
2021-03-15 18:04:01 +00:00
'get_billing_report',
'get_daily_volumes',
2022-04-08 16:05:43 +01:00
'get_daily_sms_provider_volumes',
'get_volumes_by_service',
2020-04-23 11:08:43 +01:00
'organisations',
'platform_admin',
'platform_admin_list_complaints',
'platform_admin_reports',
'platform_admin_returned_letters',
'platform_admin_splash_page',
'suspend_service',
'trial_services',
'update_email_branding',
2019-02-11 15:31:12 +00:00
'update_letter_branding',
'user_information',
'view_provider',
'view_providers',
},
'sign-in': {
'revalidate_email_sent',
'sign_in',
2021-05-14 19:15:12 +01:00
'two_factor_sms',
'two_factor_email',
'two_factor_email_sent',
'two_factor_email_interstitial',
2021-05-14 11:20:56 +01:00
'two_factor_webauthn',
'verify',
'verify_email',
},
}
2019-10-09 16:00:45 +01:00
# header HTML now comes from GOVUK Frontend so requires a boolean, not an attribute
def is_selected(self, navigation_item):
2019-10-30 10:17:32 +00:00
return request.endpoint in self.mapping[navigation_item]
2019-10-09 16:00:45 +01:00
2018-04-25 10:24:32 +01:00
class MainNavigation(Navigation):
mapping = {
'dashboard': {
'broadcast_tour',
2018-04-25 10:24:32 +01:00
'conversation',
'inbox',
'monthly',
'returned_letter_summary',
'returned_letters',
2018-04-25 10:24:32 +01:00
'service_dashboard',
'template_usage',
'view_notification',
'view_notifications',
},
'current-broadcasts': {
'broadcast_dashboard',
'broadcast_dashboard_updates',
'view_current_broadcast',
'new_broadcast',
'write_new_broadcast',
},
'previous-broadcasts': {
2020-10-13 11:40:20 +01:00
'broadcast_dashboard_previous',
'view_previous_broadcast',
2020-10-13 11:40:20 +01:00
},
2021-04-08 13:09:29 +01:00
'rejected-broadcasts': {
'broadcast_dashboard_rejected',
'view_rejected_broadcast',
},
2018-04-25 10:24:32 +01:00
'templates': {
'action_blocked',
'add_service_template',
'check_messages',
'check_notification',
2020-03-13 17:51:22 +00:00
'choose_from_contact_list',
2018-04-25 10:24:32 +01:00
'choose_template',
'choose_template_to_copy',
2018-04-25 10:24:32 +01:00
'confirm_redact_template',
'conversation_reply',
'copy_template',
2018-04-25 10:24:32 +01:00
'delete_service_template',
'edit_service_template',
2019-01-29 15:43:59 +00:00
'edit_template_postage',
'manage_template_folder',
2018-04-25 10:24:32 +01:00
'send_messages',
'send_one_off',
2020-03-10 15:12:19 +00:00
'send_one_off_letter_address',
2018-04-25 10:24:32 +01:00
'send_one_off_step',
'send_one_off_to_myself',
'no_cookie.send_test_preview',
2018-04-25 10:24:32 +01:00
'set_sender',
'set_template_sender',
'view_template',
'view_template_version',
'view_template_versions',
'broadcast',
'preview_broadcast_areas',
'choose_broadcast_library',
'choose_broadcast_area',
'choose_broadcast_sub_area',
'remove_broadcast_area',
'preview_broadcast_message',
2020-07-17 08:07:44 +01:00
'approve_broadcast_message',
2020-07-17 08:07:44 +01:00
'reject_broadcast_message',
2020-07-10 09:16:36 +01:00
'cancel_broadcast_message',
2018-04-25 10:24:32 +01:00
},
2019-08-09 08:44:11 +01:00
'uploads': {
'upload_contact_list',
'check_contact_list',
'save_contact_list',
'contact_list',
2020-03-18 13:37:39 +00:00
'delete_contact_list',
'upload_letter',
'uploaded_letter_preview',
2020-05-11 10:52:43 +01:00
'uploaded_letters',
2019-08-09 08:44:11 +01:00
'uploads',
2020-03-03 14:27:13 +00:00
'view_job',
'view_jobs',
2019-08-09 08:44:11 +01:00
},
2018-04-25 10:24:32 +01:00
'team-members': {
2019-02-20 11:50:34 +00:00
'confirm_edit_user_email',
'confirm_edit_user_mobile_number',
2019-02-20 11:50:34 +00:00
'edit_user_email',
'edit_user_mobile_number',
2018-04-25 10:24:32 +01:00
'edit_user_permissions',
'invite_user',
'manage_users',
'remove_user_from_service',
},
'usage': {
'usage',
},
'settings': {
'add_organisation_from_gp_service',
'add_organisation_from_nhs_local_service',
'email_branding_govuk',
'email_branding_govuk_and_org',
'email_branding_nhs',
'email_branding_organisation',
2022-01-19 15:39:05 +00:00
'email_branding_request',
'email_branding_something_else',
2019-02-15 11:03:19 +00:00
'estimate_usage',
2022-01-19 15:39:05 +00:00
'letter_branding_request',
2018-04-25 10:24:32 +01:00
'link_service_to_organisation',
'request_to_go_live',
'service_add_email_reply_to',
'service_add_letter_contact',
'service_add_sms_sender',
'service_agreement',
'service_accept_agreement',
'service_confirm_agreement',
'service_confirm_delete_email_reply_to',
2019-07-04 16:11:19 +01:00
'service_confirm_delete_letter_contact',
'service_confirm_delete_sms_sender',
2018-04-25 10:24:32 +01:00
'service_edit_email_reply_to',
'service_edit_letter_contact',
'service_edit_sms_sender',
'service_email_reply_to',
'service_letter_contact_details',
'service_make_blank_default_letter_contact',
2018-04-25 10:24:32 +01:00
'service_name_change',
2018-08-03 17:39:58 +01:00
'service_preview_email_branding',
'service_preview_letter_branding',
2018-04-25 10:24:32 +01:00
'service_set_auth_type',
'service_set_channel',
'send_files_by_email_contact_details',
'service_confirm_broadcast_account_type',
2021-05-11 11:07:30 +01:00
'service_set_broadcast_channel',
'service_set_broadcast_network',
2018-04-25 10:24:32 +01:00
'service_set_email_branding',
'service_set_inbound_number',
'service_set_inbound_sms',
'service_set_international_letters',
2018-04-25 10:24:32 +01:00
'service_set_international_sms',
'service_set_letters',
'service_set_reply_to_email',
'service_set_sms_prefix',
'service_verify_reply_to_address',
'service_verify_reply_to_address_updates',
2018-04-25 10:24:32 +01:00
'service_settings',
'service_sms_senders',
'set_free_sms_allowance',
'set_message_limit',
2020-10-21 14:30:35 +01:00
'set_rate_limit',
2019-02-05 16:33:36 +00:00
'service_set_letter_branding',
2018-04-25 10:24:32 +01:00
'submit_request_to_go_live',
},
'api-integration': {
'api_callbacks',
'api_documentation',
'api_integration',
'api_keys',
'create_api_key',
'delivery_status_callback',
'received_text_messages_callback',
'revoke_api_key',
'guest_list',
2020-06-12 09:07:29 +01:00
'old_guest_list',
2018-04-25 10:24:32 +01:00
},
}
2018-06-12 16:17:20 +01:00
class CaseworkNavigation(Navigation):
mapping = {
2020-07-08 11:34:16 +01:00
'dashboard': {
'broadcast_tour',
2020-07-08 11:34:16 +01:00
'broadcast_dashboard',
2020-10-13 11:40:20 +01:00
'broadcast_dashboard_previous',
'broadcast_dashboard_updates',
2020-07-08 11:34:16 +01:00
},
2018-06-12 16:17:20 +01:00
'send-one-off': {
2020-03-13 17:51:22 +00:00
'choose_from_contact_list',
2018-06-12 16:17:20 +01:00
'choose_template',
'send_one_off',
2020-03-10 15:12:19 +00:00
'send_one_off_letter_address',
2018-06-12 16:17:20 +01:00
'send_one_off_step',
'send_one_off_to_myself',
2018-06-13 14:16:10 +01:00
},
'sent-messages': {
'view_notifications',
2018-06-12 16:17:20 +01:00
'view_notification',
},
2019-10-09 10:58:15 +01:00
'uploads': {
2018-07-30 17:40:32 +01:00
'view_jobs',
'view_job',
'upload_contact_list',
'check_contact_list',
'save_contact_list',
'contact_list',
2020-03-18 13:37:39 +00:00
'delete_contact_list',
2019-10-09 10:58:15 +01:00
'upload_letter',
'uploaded_letter_preview',
2020-05-11 10:52:43 +01:00
'uploaded_letters',
2019-10-09 10:58:15 +01:00
'uploads',
2018-07-30 17:40:32 +01:00
},
2018-06-12 16:17:20 +01:00
}
class OrgNavigation(Navigation):
mapping = {
'dashboard': {
'organisation_dashboard',
},
'settings': {
'edit_organisation_agreement',
'edit_organisation_billing_details',
'edit_organisation_crown_status',
'edit_organisation_domains',
'edit_organisation_email_branding',
'edit_organisation_letter_branding',
'edit_organisation_domains',
2019-05-13 14:50:40 +01:00
'edit_organisation_go_live_notes',
'edit_organisation_name',
2021-02-04 18:00:41 +00:00
'edit_organisation_notes',
'edit_organisation_type',
'organisation_preview_email_branding',
'organisation_preview_letter_branding',
'organisation_settings',
},
'team-members': {
'edit_organisation_user',
'invite_org_user',
'manage_org_users',
'remove_user_from_organisation',
},
'trial-services': {
'organisation_trial_mode_services',
2021-12-07 13:42:44 +00:00
},
'billing': {
'organisation_billing',
}
}