aboutsummaryrefslogtreecommitdiff
path: root/gn_auth
diff options
context:
space:
mode:
Diffstat (limited to 'gn_auth')
-rw-r--r--gn_auth/auth/authorisation/resources/groups/models.py13
-rw-r--r--gn_auth/auth/authorisation/resources/groups/views.py4
2 files changed, 6 insertions, 11 deletions
diff --git a/gn_auth/auth/authorisation/resources/groups/models.py b/gn_auth/auth/authorisation/resources/groups/models.py
index 9a60df9..3afa7bf 100644
--- a/gn_auth/auth/authorisation/resources/groups/models.py
+++ b/gn_auth/auth/authorisation/resources/groups/models.py
@@ -2,14 +2,13 @@
import json
from uuid import UUID, uuid4
from functools import reduce
-from dataclasses import dataclass
+from dataclasses import dataclass, asdict
from typing import Any, Sequence, Iterable, Optional, NamedTuple
from flask import g
from pymonad.maybe import Just, Maybe, Nothing
from gn_auth.auth.db import sqlite3 as db
-from gn_auth.auth.dictify import dictify
from gn_auth.auth.authentication.users import User, user_by_id
from gn_auth.auth.authorisation.checks import authorised_p
@@ -38,18 +37,14 @@ DUMMY_GROUP = Group(
"group-description": "This is a dummy group to use as a placeholder"
})
-class GroupRole(NamedTuple):
+
+@dataclass(frozen=True)
+class GroupRole:
"""Class representing a role tied/belonging to a group."""
group_role_id: UUID
group: Group
role: Role
- def dictify(self) -> dict[str, Any]:
- """Return a dict representation of `GroupRole` objects."""
- return {
- "role": dictify(self.role)
- "group_role_id": self.group_role_id, "group": asdict(self.group),
- }
class GroupCreationError(AuthorisationError):
"""Raised whenever a group creation fails"""
diff --git a/gn_auth/auth/authorisation/resources/groups/views.py b/gn_auth/auth/authorisation/resources/groups/views.py
index b655a0f..8b471ff 100644
--- a/gn_auth/auth/authorisation/resources/groups/views.py
+++ b/gn_auth/auth/authorisation/resources/groups/views.py
@@ -308,7 +308,7 @@ def group_roles():
tuple()))
for row in cursor.fetchall())
return jsonify(tuple(
- dictify(role) for role in with_db_connection(__list_roles__)))
+ asdict(role) for role in with_db_connection(__list_roles__)))
@groups.route("/privileges", methods=["GET"])
@require_oauth("profile group")
@@ -384,7 +384,7 @@ def view_group_role(group_role_id: uuid.UUID):
raise AuthorisationError(
"A user without a group cannot view group roles.")
return group_role_by_id(conn, group, group_role_id)
- return jsonify(dictify(with_db_connection(__group_role__)))
+ return jsonify(asdict(with_db_connection(__group_role__)))
def __add_remove_priv_to_from_role__(conn: db.DbConnection,
group_role_id: uuid.UUID,