aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authorisation/privileges.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-01-28 03:16:45 +0300
committerFrederick Muriuki Muriithi2023-01-28 03:20:01 +0300
commit76c464946d01073b8bcb757345d0d42b9a8207e4 (patch)
tree7d5cd20018c65207b809842277e7533d7490de7b /gn3/auth/authorisation/privileges.py
parente6e173b74d381f590ff5a8e7957489ea4d50c06b (diff)
downloadgenenetwork3-76c464946d01073b8bcb757345d0d42b9a8207e4.tar.gz
auth: rework dictify
Define a Protocol type to use with the `dictify` function and implement the `dictify` methods for the various classes.
Diffstat (limited to 'gn3/auth/authorisation/privileges.py')
-rw-r--r--gn3/auth/authorisation/privileges.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/gn3/auth/authorisation/privileges.py b/gn3/auth/authorisation/privileges.py
index 6cfd1d8..ae4ed88 100644
--- a/gn3/auth/authorisation/privileges.py
+++ b/gn3/auth/authorisation/privileges.py
@@ -1,5 +1,5 @@
"""Handle privileges"""
-from typing import Iterable, NamedTuple
+from typing import Any, Iterable, NamedTuple
from gn3.auth import db
from gn3.auth.authentication.users import User
@@ -9,6 +9,13 @@ class Privilege(NamedTuple):
privilege_id: str
privilege_description: str
+ def dictify(self) -> dict[str, Any]:
+ """Return a dict representation of `Privilege` objects."""
+ return {
+ "privilege_id": self.privilege_id,
+ "privilege_description": self.privilege_description
+ }
+
def user_privileges(conn: db.DbConnection, user: User) -> Iterable[Privilege]:
"""Fetch the user's privileges from the database."""
with db.cursor(conn) as cursor: