about summary refs log tree commit diff
path: root/gn_auth/auth/authorisation/resources
diff options
context:
space:
mode:
Diffstat (limited to 'gn_auth/auth/authorisation/resources')
-rw-r--r--gn_auth/auth/authorisation/resources/groups/models.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/resources/groups/models.py b/gn_auth/auth/authorisation/resources/groups/models.py
index 9daadf4..f5f0195 100644
--- a/gn_auth/auth/authorisation/resources/groups/models.py
+++ b/gn_auth/auth/authorisation/resources/groups/models.py
@@ -335,6 +335,19 @@ def resource_from_group(conn: db.DbConnection, the_group: Group) -> Resource:
         return results[0]
 
 
+def remove_user_from_group(conn: db.DbConnection, the_group: Group, user: User):
+    """Add `user` to `the_group` as a member."""
+    with db.cursor(conn) as cursor:
+        cursor.execute(
+            ("INSERT INTO group_users VALUES (:group_id, :user_id) "
+             "ON CONFLICT (group_id, user_id) DO NOTHING"),
+            {"group_id": str(the_group.group_id), "user_id": str(user.user_id)})
+        assign_user_role_by_name(conn,
+                                 user,
+                                 resource_from_group(the_group).group_id,
+                                 "group-creator")
+
+
 @authorised_p(
     privileges=("system:group:view-group",),
     error_description=(