diff options
author | Munyoki Kilyungi | 2024-03-25 20:45:51 +0300 |
---|---|---|
committer | Munyoki Kilyungi | 2024-03-25 20:45:51 +0300 |
commit | 79df53abade6c2d2cbc91da9f5078cc527fb8c0f (patch) | |
tree | 604dc3421e60c3478f0374e6ced3f1131f678e56 /gn_auth | |
parent | 9f236d1257cf64c630d2fe0c59d580e32568fc2f (diff) | |
download | gn-auth-79df53abade6c2d2cbc91da9f5078cc527fb8c0f.tar.gz |
Flatten roles list in "get_user_roles_on_resource."
* gn_auth/auth/authorisation/resources/views.py: Import operator.
(get_user_roles_on_resource): Flatten roles list.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn_auth')
-rw-r--r-- | gn_auth/auth/authorisation/resources/views.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/gn_auth/auth/authorisation/resources/views.py b/gn_auth/auth/authorisation/resources/views.py index 8034110..e256b3e 100644 --- a/gn_auth/auth/authorisation/resources/views.py +++ b/gn_auth/auth/authorisation/resources/views.py @@ -1,6 +1,7 @@ """The views/routes for the resources package""" import uuid import json +import operator import sqlite3 from dataclasses import asdict @@ -381,16 +382,25 @@ def get_user_roles_on_resource(name) -> Response: resid = with_db_connection( lambda conn: get_resource_id(conn, name) ) + + def _extract_privilege_id(privileges): + return tuple( + p_.privilege_id for p_ in privileges + ) + with require_oauth.acquire("profile resource") as _token: _resources = with_db_connection( lambda conn: user_roles_on_resources( conn, _token.user, (resid,) ) ) + _roles = tuple( + _extract_privilege_id(role.privileges) + for role in + _resources.get( + uuid.UUID(resid), {} + ).get("roles", tuple())) return jsonify({ - name: { - "roles": tuple( - asdict(rol) for rol in - _resources.get(resid, {}).get("roles", tuple())) - } - }) + # Flatten this list + "roles": reduce(operator.iconcat, _roles, []) + }) |