aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authorisation/groups
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-02-06 14:20:24 +0300
committerFrederick Muriuki Muriithi2023-02-06 14:20:24 +0300
commit30da2f48eb35360bb339d54da2ab83d96a1cf85b (patch)
treee30f2e0c3e884df0be52c7c3ffe65d1636aaa2c1 /gn3/auth/authorisation/groups
parent6c76667857d5bbc8db962a551cece3f068074055 (diff)
downloadgenenetwork3-30da2f48eb35360bb339d54da2ab83d96a1cf85b.tar.gz
auth: resource: Enable viewing the details of a resource.
Diffstat (limited to 'gn3/auth/authorisation/groups')
-rw-r--r--gn3/auth/authorisation/groups/models.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/gn3/auth/authorisation/groups/models.py b/gn3/auth/authorisation/groups/models.py
index c5c9370..49b5066 100644
--- a/gn3/auth/authorisation/groups/models.py
+++ b/gn3/auth/authorisation/groups/models.py
@@ -12,7 +12,7 @@ from gn3.auth.authentication.users import User
from ..checks import authorised_p
from ..privileges import Privilege
-from ..errors import AuthorisationError
+from ..errors import NotFoundError, AuthorisationError
from ..roles.models import (
Role, create_role, revoke_user_role_by_name, assign_user_role_by_name)
@@ -224,3 +224,21 @@ def group_users(conn: db.DbConnection, group_id: UUID) -> Iterable[User]:
return (User(UUID(row["user_id"]), row["email"], row["name"])
for row in results)
+
+@authorised_p(
+ privileges = ("system:group:view-group",),
+ error_description = (
+ "You do not have the appropriate privileges to access the group."))
+def group_by_id(conn: db.DbConnection, group_id: UUID) -> Group:
+ """Retrieve a group by its ID"""
+ with db.cursor(conn) as cursor:
+ cursor.execute("SELECT * FROM groups WHERE group_id=:group_id",
+ {"group_id": str(group_id)})
+ row = cursor.fetchone()
+ if row:
+ return Group(
+ UUID(row["group_id"]),
+ row["group_name"],
+ json.loads(row["group_metadata"]))
+
+ raise NotFoundError(f"Could not find group with ID '{group_id}'.")