about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-07-29 12:17:40 -0500
committerFrederick Muriuki Muriithi2025-07-29 12:17:40 -0500
commitbfd8cefaa3e68f77c84eaf577b206377bf7fc4d5 (patch)
tree40591e8a232e174756f1c17afa36536e6c03b186
parentd4fb5c646d112e3fc8d66f7f6e795946b7465919 (diff)
downloadgn-auth-bfd8cefaa3e68f77c84eaf577b206377bf7fc4d5.tar.gz
Add function to delete a resource.
-rw-r--r--gn_auth/auth/authorisation/resources/models.py15
1 files changed, 15 insertions, 0 deletions
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."""