From 8ccf7409f6c89c3c5079a73c73dc2f6bfae086a7 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Tue, 12 Mar 2024 00:29:30 +0300 Subject: Define Privilege/Role using frozen dataclass. * gn_auth/auth/authorisation/privileges.py: Import dataclass. Remove NamedTuple import. (Privilege): Use frozen dataclass. (Privelege.dictify): Delete. * gn_auth/auth/authorisation/resources/groups/views.py: Import dataclasses.asdict. (group_privileges): Replace dictify with asdict. (add_priv_to_role): Ditto. (delete_priv_from_role): Ditto. * gn_auth/auth/authorisation/resources/models.py: (assign_resource_user): Replace dictify with asdict. (unassign_resource_user): Ditto. * gn_auth/auth/authorisation/resources/system/views.py: Import dataclasses.asdict. Remove dictify import. (system_roles): Replace dictify with asdict. * gn_auth/auth/authorisation/resources/views.py: (resource_users): Replace dictify with asdict. (resources_authorisation): Ditto. * gn_auth/auth/authorisation/roles/models.py: Remove dictify and NameTuple import. (Role): Use frozen dataclass. (Role.dictify): Replace dictify(priv) with asdict(priv). * gn_auth/auth/authorisation/roles/views.py: Import dataclasses.asdict. Remove dictify import. (view_role): Replace dictify with asdict. * gn_auth/auth/authorisation/users/views.py: (user_roles): Replace dictify with asdict. Signed-off-by: Munyoki Kilyungi --- gn_auth/auth/authorisation/resources/groups/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gn_auth/auth/authorisation/resources/groups') diff --git a/gn_auth/auth/authorisation/resources/groups/views.py b/gn_auth/auth/authorisation/resources/groups/views.py index 8b471ff..303368c 100644 --- a/gn_auth/auth/authorisation/resources/groups/views.py +++ b/gn_auth/auth/authorisation/resources/groups/views.py @@ -5,8 +5,8 @@ import uuid import datetime from typing import Iterable from functools import partial - from dataclasses import asdict + from MySQLdb.cursors import DictCursor from flask import request, jsonify, Response, Blueprint, current_app @@ -331,7 +331,7 @@ def group_privileges(): privilege for arole in this_user_roles for privilege in arole.privileges) + group_level_roles #type: ignore[attr-defined] return jsonify(tuple( - dictify(priv) for priv in with_db_connection(__list_privileges__))) + asdict(priv) for priv in with_db_connection(__list_privileges__))) @@ -420,7 +420,7 @@ def add_priv_to_role(group_role_id: uuid.UUID) -> Response: """Add privilege to group role.""" with require_oauth.acquire("profile group role") as the_token: return jsonify({ - **dictify(with_db_connection(partial( + **asdict(with_db_connection(partial( __add_remove_priv_to_from_role__, group_role_id=group_role_id, direction="ADD", user=the_token.user))), "description": "Privilege added successfully" @@ -432,7 +432,7 @@ def delete_priv_from_role(group_role_id: uuid.UUID) -> Response: """Delete privilege from group role.""" with require_oauth.acquire("profile group role") as the_token: return jsonify({ - **dictify(with_db_connection(partial( + **asdict(with_db_connection(partial( __add_remove_priv_to_from_role__, group_role_id=group_role_id, direction="DELETE", user=the_token.user))), "description": "Privilege deleted successfully" -- cgit v1.2.3