mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Change permissions endpoint to accept data in new format
The data posted to the `set_permissions` endpoint is currently sent as a
list of permissions:
`[{'permission': MANAGE_SETTINGS}, {'permission': MANAGE_TEMPLATES}]`.
This endpoint is going to also be used for folder permissions, so the
data now needs to be nested:
`{'permissions': [{'permission': MANAGE_SETTINGS}, {'permission': MANAGE_TEMPLATES}]}`
This changes the set_permissions endpoint to accept data in either
format. Once admin is sending data in the new format, the code can be
simplified.
This commit is contained in:
@@ -338,7 +338,14 @@ def set_permissions(user_id, service_id):
|
||||
# who is making this request has permission to make the request.
|
||||
user = get_user_by_id(user_id=user_id)
|
||||
service = dao_fetch_service_by_id(service_id=service_id)
|
||||
permissions, errors = permission_schema.load(request.get_json(), many=True)
|
||||
|
||||
data = request.get_json()
|
||||
if 'permissions' in data:
|
||||
user_permissions = data['permissions']
|
||||
else:
|
||||
user_permissions = data
|
||||
|
||||
permissions, errors = permission_schema.load(user_permissions, many=True)
|
||||
|
||||
for p in permissions:
|
||||
p.user = user
|
||||
|
||||
Reference in New Issue
Block a user