diff options
author | Munyoki Kilyungi | 2024-03-11 23:58:35 +0300 |
---|---|---|
committer | Munyoki Kilyungi | 2024-03-13 10:25:27 +0300 |
commit | 7e11ddbbdd6ddfa28367c02d0a3a7f3932c369ae (patch) | |
tree | a3f50b605411594ddf970752ffcb24a73f1d306b /gn_auth/auth/authorisation/resources/groups/models.py | |
parent | a295d21a42a6ae9c463f7661b32df7de11095835 (diff) | |
download | gn-auth-7e11ddbbdd6ddfa28367c02d0a3a7f3932c369ae.tar.gz |
Define Group using a frozen dataclass.
* gn_auth/auth/authorisation/data/genotypes.py: Import
dataclasses.asdict.
(link_genotype_data): Replace dictify with asdict.
* gn_auth/auth/authorisation/data/mrna.py: Import dataclasses.asdict.
(link_mrna_data): Replace dictify with asdict.
* gn_auth/auth/authorisation/data/phenotypes.py: Import
dataclasses.asdict.
(link_phenotype_data): Replace dictify with asdict.
* gn_auth/auth/authorisation/resources/groups/models.py: Import
dataclass.
(Group): Use frozen dataclass.
(Group.dictify): Delete.
(GroupRole.dictify): Replace dictify with asdict.
* gn_auth/auth/authorisation/resources/groups/views.py: Import
dataclasses.asdict. Remove dictify import.
(list_groups): Replace dictify with asdict.
(create_group): Ditto.
* gn_auth/auth/authorisation/resources/views.py:
(resource_users): Replace dictify with asdict.
* gn_auth/auth/authorisation/users/views.py: Import
dataclasses.asdict. Remove dictify import.
(user_details): Replace dictify with asdict.
(user_group): Ditto.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn_auth/auth/authorisation/resources/groups/models.py')
-rw-r--r-- | gn_auth/auth/authorisation/resources/groups/models.py | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/gn_auth/auth/authorisation/resources/groups/models.py b/gn_auth/auth/authorisation/resources/groups/models.py index 959389c..9a60df9 100644 --- a/gn_auth/auth/authorisation/resources/groups/models.py +++ b/gn_auth/auth/authorisation/resources/groups/models.py @@ -2,6 +2,7 @@ import json from uuid import UUID, uuid4 from functools import reduce +from dataclasses import dataclass from typing import Any, Sequence, Iterable, Optional, NamedTuple from flask import g @@ -21,18 +22,14 @@ from gn_auth.auth.authorisation.roles.models import ( Role, create_role, check_user_editable, revoke_user_role_by_name, assign_user_role_by_name) -class Group(NamedTuple): + +@dataclass(frozen=True) +class Group: """Class representing a group.""" group_id: UUID group_name: str group_metadata: dict[str, Any] - 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 - } DUMMY_GROUP = Group( group_id=UUID("77cee65b-fe29-4383-ae41-3cb3b480cc70"), @@ -50,8 +47,8 @@ class GroupRole(NamedTuple): 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) + "group_role_id": self.group_role_id, "group": asdict(self.group), } class GroupCreationError(AuthorisationError): |