From c3201d9593d15f13189f8f7ee35f00eacae37aca Mon Sep 17 00:00:00 2001
From: Mart van Santen <mart@greenhost.nl>
Date: Thu, 16 Mar 2023 22:31:59 +0800
Subject: [PATCH] Allow the deletion of apps

---
 backend/areas/apps/models.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/backend/areas/apps/models.py b/backend/areas/apps/models.py
index 069c7375..972d7dd3 100644
--- a/backend/areas/apps/models.py
+++ b/backend/areas/apps/models.py
@@ -113,6 +113,10 @@ class App(db.Model):
         # Delete all roles first
         for role in self.roles:
             db.session.delete(role)
+
+        # Delete all related oathclient entries
+        for auth in self.oauthclients:
+            db.session.delete(auth)
         db.session.commit()
 
         db.session.delete(self)
@@ -173,6 +177,15 @@ class App(db.Model):
             app_id=self.id
         ).all()
 
+    @property
+    def oauthclients(self):
+        """
+        All oauth clients related to this app
+        """
+        return OAuthClientApp.query.filter_by(
+            app_id=self.id
+        ).all()
+
     @property
     def kustomization(self):
         """Returns the kustomization object for this app"""
-- 
GitLab