diff options
author | Frederick Muriuki Muriithi | 2025-07-31 12:21:24 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-07-31 12:59:05 -0500 |
commit | 24c731e707643395a0505e95e76a15c36baeee3f (patch) | |
tree | 7890c269cece462d2d9481a15f2e296f266d96d2 /gn_auth/auth/authorisation/resources/groups/models.py | |
parent | 471240cd5251b3f5d5bc9e45b2068eb4fe1036c6 (diff) | |
download | gn-auth-24c731e707643395a0505e95e76a15c36baeee3f.tar.gz |
Delete a group.
Diffstat (limited to 'gn_auth/auth/authorisation/resources/groups/models.py')
-rw-r--r-- | gn_auth/auth/authorisation/resources/groups/models.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/resources/groups/models.py b/gn_auth/auth/authorisation/resources/groups/models.py index 8b1df90..34f9b93 100644 --- a/gn_auth/auth/authorisation/resources/groups/models.py +++ b/gn_auth/auth/authorisation/resources/groups/models.py @@ -655,3 +655,27 @@ def group_leaders(conn: db.DbConnection, group_id: UUID) -> Iterable[User]: "AND roles.role_name='group-leader'", (str(group_id),)) yield from (User.from_sqlite3_row(row) for row in cursor.fetchall()) + + +def delete_group(conn: db.DbConnection, group_id: UUID): + """ + Delete the group with the given ID + + Parameters: + conn (db.DbConnection): an open connection to an SQLite3 database. + group_id (uuid.UUID): The identifier for the group to delete. + + Returns: + None: It does not return a value. + + Raises: + sqlite3.IntegrityError: if the group has members or linked resources, or + both. + """ + 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 groups WHERE group_id=?", + (str(group_id),)) |