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/users/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gn_auth/auth/authorisation/users') diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py index ae3c45e..f9353eb 100644 --- a/gn_auth/auth/authorisation/users/views.py +++ b/gn_auth/auth/authorisation/users/views.py @@ -57,7 +57,7 @@ def user_roles() -> Response: with require_oauth.acquire("role") as token: with db.connection(current_app.config["AUTH_DB"]) as conn: return jsonify(tuple( - {**role, "roles": tuple(dictify(rol) for rol in role["roles"])} + {**role, "roles": tuple(asdict(rol) for rol in role["roles"])} for role in _user_roles(conn, token.user))) def validate_password(password, confirm_password) -> str: -- cgit v1.2.3