diff options
author | Frederick Muriuki Muriithi | 2024-06-10 12:38:45 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-06-10 12:38:45 -0500 |
commit | 52bc7f5037acb4a0c7d55022a7f818a742706790 (patch) | |
tree | abdca2f2b4eb0e1f1c1a1e255c6f70bb2fa54147 | |
parent | f9e58648801f173e935485c87de5bf33b0dfc356 (diff) | |
download | gn-auth-52bc7f5037acb4a0c7d55022a7f818a742706790.tar.gz |
Share reusable function
-rw-r--r-- | gn_auth/auth/authorisation/resources/views.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/gn_auth/auth/authorisation/resources/views.py b/gn_auth/auth/authorisation/resources/views.py index 3a61704..24b2416 100644 --- a/gn_auth/auth/authorisation/resources/views.py +++ b/gn_auth/auth/authorisation/resources/views.py @@ -341,26 +341,29 @@ def toggle_public(resource_id: uuid.UUID) -> Response: else "Made resource private")}) +def __resultset_to_roles__(roles, row): + """Convert SQLite3 resultset into `Role` objects""" + _role = roles.get(row["role_id"]) + return { + **roles, + row["role_id"]: Role( + role_id=uuid.UUID(row["role_id"]), + role_name=row["role_name"], + user_editable=bool(row["user_editable"]), + privileges=( + (_role.privileges if bool(_role) else tuple()) + + (Privilege( + privilege_id=row["privilege_id"], + privilege_description=row[ + "privilege_description"]),))) + } + + @resources.route("<uuid:resource_id>/roles", methods=["GET"]) @require_oauth("profile group resource role") def resource_roles(resource_id: uuid.UUID) -> Response: """Return the roles the user has to act on a given resource.""" with require_oauth.acquire("profile group resource role") as _token: - def __resultset_to_roles__(roles, row): - _role = roles.get(row["role_id"]) - return { - **roles, - row["role_id"]: Role( - role_id=uuid.UUID(row["role_id"]), - role_name=row["role_name"], - user_editable=bool(row["user_editable"]), - privileges=( - (_role.privileges if bool(_role) else tuple()) + - (Privilege( - privilege_id=row["privilege_id"], - privilege_description=row[ - "privilege_description"]),))) - } def __roles__(conn: db.DbConnection) -> tuple[Role, ...]: |