mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-03 23:51:22 -04:00
For services with the broadcast permission this hides: - the ‘View dashboard’ permission (and defaults it to _checked_) because all users of broadcast services will need to see the dashboard - the ‘Manage API keys’ permission (and defaults it to _not checked_) because we don’t offer an API integration for broadcast services yet – if we do we won’t want existing users to automatically get the permission It relabels: - the ‘Send’ permission to ‘Prepare and approve’ to match the current, slightly clunky language on the templates page - the ‘Manage settings’ label to not refer to ‘usage’ because broadcast services won’t incur cost
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from itertools import chain
|
|
|
|
roles = {
|
|
'send_messages': ['send_texts', 'send_emails', 'send_letters'],
|
|
'manage_templates': ['manage_templates'],
|
|
'manage_service': ['manage_users', 'manage_settings'],
|
|
'manage_api_keys': ['manage_api_keys'],
|
|
'view_activity': ['view_activity'],
|
|
}
|
|
|
|
# same dict as above, but flipped round
|
|
roles_by_permission = {
|
|
permission: next(
|
|
role for role, permissions in roles.items() if permission in permissions
|
|
) for permission in chain(*list(roles.values()))
|
|
}
|
|
|
|
all_permissions = set(roles_by_permission.values())
|
|
|
|
permissions = (
|
|
('view_activity', 'See dashboard'),
|
|
('send_messages', 'Send messages'),
|
|
('manage_templates', 'Add and edit templates'),
|
|
('manage_service', 'Manage settings, team and usage'),
|
|
('manage_api_keys', 'Manage API integration'),
|
|
)
|
|
|
|
broadcast_permissions = (
|
|
('send_messages', 'Prepare and approve broadcasts'),
|
|
('manage_templates', 'Add and edit templates'),
|
|
('manage_service', 'Manage settings and team'),
|
|
)
|
|
|
|
|
|
def translate_permissions_from_db_to_admin_roles(permissions):
|
|
"""
|
|
Given a list of database permissions, return a set of roles
|
|
|
|
look them up in roles_by_permission, falling back to just passing through from the api if they aren't in the dict
|
|
"""
|
|
return {roles_by_permission.get(permission, permission) for permission in permissions}
|
|
|
|
|
|
def translate_permissions_from_admin_roles_to_db(permissions):
|
|
"""
|
|
Given a list of admin roles (ie: checkboxes on a permissions edit page for example), return a set of db permissions
|
|
|
|
Looks them up in the roles dict, falling back to just passing through if they're not recognised.
|
|
"""
|
|
return set(chain.from_iterable(roles.get(permission, [permission]) for permission in permissions))
|