aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authorisation/groups.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/groups.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/groups.py')
-rw-r--r--gn3/auth/authorisation/groups.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/gn3/auth/authorisation/groups.py b/gn3/auth/authorisation/groups.py
index 6d1b1a3..9dd5b71 100644
--- a/gn3/auth/authorisation/groups.py
+++ b/gn3/auth/authorisation/groups.py
@@ -7,8 +7,8 @@ from flask import g
from pymonad.maybe import Just, Maybe, Nothing
from gn3.auth import db
+from gn3.auth.dictify import dictify
from gn3.auth.authentication.users import User
-from gn3.auth.dictify import register_dictifier
from gn3.auth.authentication.checks import authenticated_p
from .checks import authorised_p
@@ -23,9 +23,12 @@ class Group(NamedTuple):
group_name: str
group_metadata: dict[str, Any]
-register_dictifier(Group, lambda grp: {
- "group_id": grp.group_id, "group_name": grp.group_name,
- "group_metadata": grp.group_metadata})
+ def dictify(self):
+ """Return a dict representation of `Group` objects."""
+ return {
+ "group_id": self.group_id, "group_name": self.group_name,
+ "group_metadata": self.group_metadata
+ }
class GroupRole(NamedTuple):
"""Class representing a role tied/belonging to a group."""
@@ -33,6 +36,13 @@ class GroupRole(NamedTuple):
group: Group
role: Role
+ def dictify(self) -> dict[str, Any]:
+ """Return a dict representation of `GroupRole` objects."""
+ return {
+ "group_role_id": self.group_role_id, "group": dictify(self.group),
+ "role": dictify(self.role)
+ }
+
class GroupCreationError(AuthorisationError):
"""Raised whenever a group creation fails"""