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/system/views.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'gn_auth/auth/authorisation/resources/system') diff --git a/gn_auth/auth/authorisation/resources/system/views.py b/gn_auth/auth/authorisation/resources/system/views.py index 70e28d6..b0d40c2 100644 --- a/gn_auth/auth/authorisation/resources/system/views.py +++ b/gn_auth/auth/authorisation/resources/system/views.py @@ -1,12 +1,11 @@ """Views relating to `System` resource(s).""" +from dataclasses import asdict from flask import jsonify, Blueprint from gn_auth.auth.db.sqlite3 import with_db_connection from gn_auth.auth.authentication.oauth2.resource_server import require_oauth -from gn_auth.auth.dictify import dictify - from .models import user_roles_on_system system = Blueprint("system", __name__) @@ -17,4 +16,4 @@ def system_roles(): with require_oauth.acquire("profile group") as the_token: roles = with_db_connection( lambda conn: user_roles_on_system(conn, the_token.user)) - return jsonify(tuple(dictify(role) for role in roles)) + return jsonify(tuple(asdict(role) for role in roles)) -- cgit v1.2.3