mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 13:39:41 -04:00
map roles and db permissions
in the db, we have several rows for single permissions - we separate `send_messages` into `send_texts`, `send_emails` and `send_letters`, and also `manage_service` into `manage_users` and `manage_settings`. But on the front end we don't do anything with this distinction. It's unhelpful for us to have to think about permissions as groups of things when we can never split them up at all. So we should combine them. This commit makes sure: * when user models are read (from JSON direct from the API), we should transform them from db permissions into roles. * when permissions are persisted (editing permissions, and creating invites), we should send db permissions to the API. All other interaction with permissions (should just be the endpoint decorator and checks in html templates generally) should use admin roles.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from notifications_python_client.errors import HTTPError
|
||||
|
||||
from app.notify_client import NotifyAdminAPIClient
|
||||
from app.notify_client.models import User
|
||||
from app.notify_client.models import (
|
||||
User,
|
||||
translate_permissions_from_admin_roles_to_db,
|
||||
)
|
||||
|
||||
ALLOWED_ATTRIBUTES = {
|
||||
'name',
|
||||
@@ -142,8 +145,9 @@ class UserApiClient(NotifyAdminAPIClient):
|
||||
return [User(data) for data in resp['data']]
|
||||
|
||||
def add_user_to_service(self, service_id, user_id, permissions):
|
||||
# permissions passed in are the combined admin roles, not db permissions
|
||||
endpoint = '/service/{}/users/{}'.format(service_id, user_id)
|
||||
data = [{'permission': x} for x in permissions]
|
||||
data = [{'permission': x} for x in translate_permissions_from_admin_roles_to_db(permissions)]
|
||||
resp = self.post(endpoint, data=data)
|
||||
return User(resp['data'], max_failed_login_count=self.max_failed_login_count)
|
||||
|
||||
@@ -152,7 +156,8 @@ class UserApiClient(NotifyAdminAPIClient):
|
||||
return User(resp['data'], max_failed_login_count=self.max_failed_login_count)
|
||||
|
||||
def set_user_permissions(self, user_id, service_id, permissions):
|
||||
data = [{'permission': x} for x in permissions]
|
||||
# permissions passed in are the combined admin roles, not db permissions
|
||||
data = [{'permission': x} for x in translate_permissions_from_admin_roles_to_db(permissions)]
|
||||
endpoint = '/user/{}/service/{}/permission'.format(user_id, service_id)
|
||||
self.post(endpoint, data=data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user