aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-07-31 16:20:01 -0500
committerFrederick Muriuki Muriithi2025-07-31 16:20:01 -0500
commit33418d9f428c8ea5dc14f2accc15f4abbf275ab2 (patch)
tree1bb421df8cc09a07b5f56d2d98f98dc8122d131b
parent742f50cb5a6ee6e5c089c616d2c4b65f4a5ecb9b (diff)
downloadgn-auth-33418d9f428c8ea5dc14f2accc15f4abbf275ab2.tar.gz
Clean up data on group deletion.HEADmain
-rw-r--r--gn_auth/auth/authorisation/resources/groups/models.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/gn_auth/auth/authorisation/resources/groups/models.py b/gn_auth/auth/authorisation/resources/groups/models.py
index 597ac37..a1937ce 100644
--- a/gn_auth/auth/authorisation/resources/groups/models.py
+++ b/gn_auth/auth/authorisation/resources/groups/models.py
@@ -690,10 +690,16 @@ def delete_group(conn: db.DbConnection, group_id: UUID):
sqlite3.IntegrityError: if the group has members or linked resources, or
both.
"""
+ rsc = group_resource(conn, group_id)
with db.cursor(conn) as cursor:
cursor.execute("DELETE FROM group_join_requests WHERE group_id=?",
(str(group_id),))
- cursor.execute("DELETE FROM group_resources WHERE group_id=?",
- (str(group_id),))
+ cursor.execute("DELETE FROM user_roles WHERE resource_id=?",
+ (str(rsc.resource_id),))
+ cursor.execute(
+ "DELETE FROM group_resources WHERE group_id=? AND resource_id=?",
+ (str(group_id), str(rsc.resource_id)))
+ cursor.execute("DELETE FROM resources WHERE resource_id=?",
+ (str(rsc.resource_id),))
cursor.execute("DELETE FROM groups WHERE group_id=?",
(str(group_id),))