From bfd8cefaa3e68f77c84eaf577b206377bf7fc4d5 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 29 Jul 2025 12:17:40 -0500 Subject: Add function to delete a resource. --- gn_auth/auth/authorisation/resources/models.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'gn_auth/auth/authorisation/resources/models.py') diff --git a/gn_auth/auth/authorisation/resources/models.py b/gn_auth/auth/authorisation/resources/models.py index b4adfc0..5feb916 100644 --- a/gn_auth/auth/authorisation/resources/models.py +++ b/gn_auth/auth/authorisation/resources/models.py @@ -72,6 +72,21 @@ def create_resource(# pylint: disable=[too-many-arguments, too-many-positional-a return resource + +def delete_resource(conn: db.DbConnection, resource_id: UUID): + with db.cursor(conn) as cursor: + cursor.execute("DELETE FROM user_roles WHERE resource_id=?", + (str(resource_id),)) + cursor.execute("DELETE FROM resource_roles WHERE resource_id=?", + (str(resource_id),)) + cursor.execute("DELETE FROM group_resources WHERE resource_id=?", + (str(resource_id),)) + cursor.execute("DELETE FROM resource_ownership WHERE resource_id=?", + (str(resource_id),)) + cursor.execute("DELETE FROM resources WHERE resource_id=?", + (str(resource_id),)) + + def resource_category_by_id( conn: db.DbConnection, category_id: UUID) -> ResourceCategory: """Retrieve a resource category by its ID.""" -- cgit 1.4.1