From 17e062e8292c26aa9867d054cf2bd2c27ac213e4 Mon Sep 17 00:00:00 2001 From: nbenedek Date: Fri, 7 Apr 2023 02:48:03 +0200 Subject: [PATCH] rssbridge: Completely uninstall app * make ENABLE_LIST a constant and declare PUBLIC_ACCESS_FILE with pathlib.Path() * add PUBLIC_ACCESS_FILE to the backup manifest * Remove PUBLIC_ACCESS_FILE and ENABLE_LIST Tests: 1. Install the app and enable public access 2. Reinstall the app and confirm the public access is reset to default 3. Functional tests passed Signed-off-by: nbenedek [sunil: Update docstrings, make uninstall fail-safe] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/rssbridge/__init__.py | 5 +++++ plinth/modules/rssbridge/manifest.py | 6 +++++- plinth/modules/rssbridge/privileged.py | 22 ++++++++++++++-------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/plinth/modules/rssbridge/__init__.py b/plinth/modules/rssbridge/__init__.py index 460d833f8..7b84a8af8 100644 --- a/plinth/modules/rssbridge/__init__.py +++ b/plinth/modules/rssbridge/__init__.py @@ -88,3 +88,8 @@ class RSSBridgeApp(app_module.App): super().setup(old_version) privileged.setup() self.enable() + + def uninstall(self): + """De-configure and uninstall the app.""" + super().uninstall() + privileged.uninstall() diff --git a/plinth/modules/rssbridge/manifest.py b/plinth/modules/rssbridge/manifest.py index 289bc65d3..0048bcd43 100644 --- a/plinth/modules/rssbridge/manifest.py +++ b/plinth/modules/rssbridge/manifest.py @@ -14,4 +14,8 @@ clients = [{ }] }] -backup = {} +backup = { + 'data': { + 'files': ['/etc/rss-bridge/is_public'] + } +} diff --git a/plinth/modules/rssbridge/privileged.py b/plinth/modules/rssbridge/privileged.py index ad31fb541..741326ee9 100644 --- a/plinth/modules/rssbridge/privileged.py +++ b/plinth/modules/rssbridge/privileged.py @@ -2,32 +2,38 @@ """Configure RSS-Bridge.""" import pathlib -from plinth import action_utils +from plinth import action_utils from plinth.actions import privileged -PUBLIC_ACCESS_FILE = '/etc/rss-bridge/is_public' +PUBLIC_ACCESS_FILE = pathlib.Path('/etc/rss-bridge/is_public') +ENABLE_LIST = pathlib.Path('/etc/rss-bridge/whitelist.txt') @privileged def setup(): """Configure RSS-Bridge by enable all bridges.""" - enable_list = pathlib.Path('/etc/rss-bridge/whitelist.txt') - enable_list.write_text('*\n', encoding='utf-8') + ENABLE_LIST.write_text('*\n', encoding='utf-8') @privileged def set_public(enable: bool): """Allow/disallow public access.""" - public_access_file = pathlib.Path(PUBLIC_ACCESS_FILE) if enable: - public_access_file.touch() + PUBLIC_ACCESS_FILE.touch() else: - public_access_file.unlink(missing_ok=True) + PUBLIC_ACCESS_FILE.unlink(missing_ok=True) action_utils.service_reload('apache2') def is_public() -> bool: """Return whether public access is enabled.""" - return pathlib.Path(PUBLIC_ACCESS_FILE).exists() + return PUBLIC_ACCESS_FILE.exists() + + +@privileged +def uninstall(): + """Remove config files when app is uninstalled.""" + for path in PUBLIC_ACCESS_FILE, ENABLE_LIST: + path.unlink(missing_ok=True)