Update the broadcast roles

We've added new broadcast roles in the database (`create_broadcasts` and
`approve_broadcasts`).

Adding these has meant we've needed to do a bit of a rewrite of the roles and
permissions code since this had been based on the assumption that each
database permission only belongs to one admin role - this is no longer true.
This means that flipping the roles dict round to create a dict which
contains database permissions as the keys is no longer possible. We can't
necessarily tell which admin role someone has given a database permission.

To check if a user has an admin role given a list of database permissions,
the user must now have ALL the database permissions mapped to that role
(instead of just one). This works because no one has the `manage_users`
permission without also having the `manage_settings` (and similar for
the other admin roles which map to multiple database permissions).

Some test data was changed because it was using admin roles where
database permissions are actually used when the app is running. I've kept
the functionality of the `translate_permissions_from_db_to_admin_roles`
function passing through any unknown roles it is passed as an argument.
This is not necessary, so can be changed later if we decide it will not
ever be used. However, removing it would require updating a lot of
tests since the tests rely on this behaviour.
This commit is contained in:
Katie Smith
2021-06-18 15:09:11 +01:00
parent a66a31c944
commit a84705f834
5 changed files with 89 additions and 48 deletions

View File

@@ -1214,7 +1214,7 @@ def test_menu_send_messages(
notify_admin,
api_user_active,
service_one,
['view_activity', 'send_messages'])
['view_activity', 'send_texts', 'send_emails', 'send_letters'])
page = resp.get_data(as_text=True)
assert url_for(
'main.choose_template',
@@ -1248,7 +1248,7 @@ def test_menu_send_messages_when_service_does_not_have_upload_letters_permission
notify_admin,
api_user_active,
service_one,
['view_activity', 'send_messages'])
['view_activity', 'send_texts', 'send_emails', 'send_letters'])
page = BeautifulSoup(resp.data.decode('utf-8'), 'html.parser')
assert page.select_one('.navigation')
assert url_for('main.uploads', service_id=service_one['id']) not in page.select_one('.navigation')
@@ -1274,7 +1274,7 @@ def test_menu_manage_service(
notify_admin,
api_user_active,
service_one,
['view_activity', 'manage_templates', 'manage_service'])
['view_activity', 'manage_templates', 'manage_users', 'manage_settings'])
page = resp.get_data(as_text=True)
assert url_for(
'main.choose_template',