diff options
author | Frederick Muriuki Muriithi | 2025-07-30 10:54:01 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-07-30 12:54:52 -0500 |
commit | 1b0bda74dbd87decc0ebb8392188cfaebd0eea08 (patch) | |
tree | 2a4ac00718e7a571e5e81ee42aa0535b4cacdb4f | |
parent | 29d097ffcbe9b0993bfab794c91f96d473ce0207 (diff) | |
download | gn-auth-1b0bda74dbd87decc0ebb8392188cfaebd0eea08.tar.gz |
Remove a user from a group as a member.
-rw-r--r-- | gn_auth/auth/authorisation/resources/groups/models.py | 13 |
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=( |