aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-11-17 14:03:19 +0300
committerFrederick Muriuki Muriithi2022-11-17 14:03:19 +0300
commit8e0ed6fdb03d1a2c284a68a387105623c8947abd (patch)
tree2748c4dd713bce099565c02569463553f293beb9 /gn3
parentfb885e810f568a69e6703939062e532acf649a38 (diff)
downloadgenenetwork3-8e0ed6fdb03d1a2c284a68a387105623c8947abd.tar.gz
auth: Finish implementation of `create_group_role`
* gn3/auth/authorisation/groups.py: Add `GroupRole` type. Fix typing annotations. Fix bugs. * tests/unit/auth/conftest.py: Fix bugs. * tests/unit/auth/test_groups.py: Fix test to run.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/auth/authorisation/groups.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/gn3/auth/authorisation/groups.py b/gn3/auth/authorisation/groups.py
index 210c8de..6d7b885 100644
--- a/gn3/auth/authorisation/groups.py
+++ b/gn3/auth/authorisation/groups.py
@@ -12,6 +12,11 @@ class Group(NamedTuple):
group_id: UUID
group_name: str
+class GroupRole(NamedTuple):
+ """Class representing a role tied/belonging to a group."""
+ group_role_id: UUID
+ role: Role
+
@authorised_p(("create-group",), error_message="Failed to create group.")
def create_group(conn: db.DbConnection, group_name: str) -> Group:
"""Create a group"""
@@ -30,12 +35,14 @@ def create_group(conn: db.DbConnection, group_name: str) -> Group:
@authorised_p(("create-role",), error_message="Could not create the group role")
def create_group_role(
conn: db.DbConnection, group: Group, role_name: str,
- privileges: Iterable[Privilege]) -> Role:
+ privileges: Iterable[Privilege]) -> GroupRole:
"""Create a role attached to a group."""
with db.cursor(conn) as cursor:
+ group_role_id = uuid4()
role = create_role(cursor, role_name, privileges)
cursor.execute(
- "INSERT INTO group_roles(group_id, role_id) VALUES(?, ?)",
- (str(group.group_id), role.role_id))
+ ("INSERT INTO group_roles(group_role_id, group_id, role_id) "
+ "VALUES(?, ?, ?)"),
+ (str(group_role_id), str(group.group_id), str(role.role_id)))
- return role
+ return GroupRole(group_role_id, role)