From 82478e50062d3df4776b5bd8c2717cee42213b65 Mon Sep 17 00:00:00 2001
From: Maarten de Waard <maarten@greenhost.nl>
Date: Wed, 28 Sep 2022 14:46:49 +0200
Subject: [PATCH] fix a few bugs with app del uninstall and deletion

---
 .pylintrc            |  5 +++++
 areas/apps/models.py |  4 +++-
 cliapp/cliapp/cli.py | 15 ++++++++++-----
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/.pylintrc b/.pylintrc
index 4051d643..cacf5a9a 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -3,3 +3,8 @@
 # List of plugins (as comma separated values of python module names) to load,
 # usually to register additional checkers.
 load-plugins=pylint_flask,pylint_flask_sqlalchemy
+
+# List of class names for which member attributes should not be checked (useful
+# for classes with dynamically set attributes). This supports the use of
+# qualified names.
+ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace,scoped_session
diff --git a/areas/apps/models.py b/areas/apps/models.py
index a3098ab3..abc3448c 100644
--- a/areas/apps/models.py
+++ b/areas/apps/models.py
@@ -51,7 +51,8 @@ class App(db.Model):
         """
         # Delete all roles first
         for role in self.roles:
-            role.delete()
+            db.session.delete(role)
+        db.session.commit()
 
         db.session.delete(self)
         return db.session.commit()
@@ -166,6 +167,7 @@ class AppStatus():  # pylint: disable=too-few-public-methods
             self.installed = False
             self.ready = False
             self.message = "Not installed"
+            return
 
         for helmrelease in helmreleases:
             hr_status = helmrelease['status']
diff --git a/cliapp/cliapp/cli.py b/cliapp/cliapp/cli.py
index 6ac5cba6..25ba8611 100644
--- a/cliapp/cliapp/cli.py
+++ b/cliapp/cliapp/cli.py
@@ -98,9 +98,14 @@ def delete_app(slug):
         current_app.logger.info("Not found")
         return
 
-    deleted = app_obj.delete()
-    current_app.logger.info(f"Success: {deleted}")
-    return
+    app_status = app_obj.get_status()
+    if not app_status.installed:
+        deleted = app_obj.delete()
+        current_app.logger.info(f"Success.")
+    else:
+        current_app.logger.info("Can not delete installed application, run"
+            " 'uninstall' first")
+
 
 @app_cli.command(
     "uninstall",
@@ -110,7 +115,7 @@ def uninstall_app(slug):
     """Uninstalls the app from the cluster
     :param slug: str Slug of app to remove
     """
-    current_app.logger.info(f"Trying to delete app: {slug}")
+    current_app.logger.info(f"Trying to uninstall app: {slug}")
     app_obj = App.query.filter_by(slug=slug).first()
 
     if not app_obj:
@@ -152,7 +157,7 @@ def install_app(slug):
         return
 
     current_status = app.get_status()
-    if current_status.installed == False:
+    if not current_status.installed:
         app.install()
         current_app.logger.info(
             f"App {slug} installing... use `status` to see status")
-- 
GitLab