From 1659b456d160ce1e15d7b0acb38c22ab082d1f08 Mon Sep 17 00:00:00 2001 From: nbenedek Date: Fri, 7 Apr 2023 02:18:02 +0200 Subject: [PATCH] matrixsynapse: Completely uninstall app Remove database, mediafiles and freedombox configs. Removal of certs are not neccessary since the next setup will overwrite them Test: 1. Install the app and set a domain 2. Reinstall the app and confirm the domain can be set like it's the first time Signed-off-by: nbenedek [sunil: Update docstrings, make uninstall fail-safe] [sunil: Fix uninstall functional test] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/matrixsynapse/__init__.py | 5 +++++ plinth/modules/matrixsynapse/privileged.py | 7 +++++++ plinth/modules/matrixsynapse/tests/test_functional.py | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/plinth/modules/matrixsynapse/__init__.py b/plinth/modules/matrixsynapse/__init__.py index 606f6f47d..46ed62539 100644 --- a/plinth/modules/matrixsynapse/__init__.py +++ b/plinth/modules/matrixsynapse/__init__.py @@ -126,6 +126,11 @@ class MatrixSynapseApp(app_module.App): config = self.get_component('turn-matrixsynapse').get_configuration() update_turn_configuration(config, force=True) + def uninstall(self): + """De-configure and uninstall the app.""" + super().uninstall() + privileged.uninstall() + class MatrixSynapseTurnConsumer(TurnConsumer): """Component to manage Coturn configuration for Matrix Synapse.""" diff --git a/plinth/modules/matrixsynapse/privileged.py b/plinth/modules/matrixsynapse/privileged.py index 8aa6fa2a7..f5b48459d 100644 --- a/plinth/modules/matrixsynapse/privileged.py +++ b/plinth/modules/matrixsynapse/privileged.py @@ -339,3 +339,10 @@ def _generate_mac(shared_secret: str, nonce: str, user: str, password: str, mac.update(user_type.encode('utf8')) return mac.hexdigest() + + +@privileged +def uninstall(): + """Delete configuration and data directories.""" + for item in ['/etc/matrix-synapse/conf.d', '/var/lib/matrix-synapse']: + shutil.rmtree(item, ignore_errors=True) diff --git a/plinth/modules/matrixsynapse/tests/test_functional.py b/plinth/modules/matrixsynapse/tests/test_functional.py index 4d844fefd..9a57103fd 100644 --- a/plinth/modules/matrixsynapse/tests/test_functional.py +++ b/plinth/modules/matrixsynapse/tests/test_functional.py @@ -24,3 +24,9 @@ class TestMatrixSynapseApp(functional.BaseAppTests): functional.install(session_browser, self.app_name) functional.app_select_domain_name(session_browser, self.app_name, 'mydomain.example') + + def test_uninstall(self, session_browser): + """After uninstall test, after installing select the domain again.""" + super().test_uninstall(session_browser) + functional.app_select_domain_name(session_browser, self.app_name, + 'mydomain.example')