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 <contact@nbenedek.me>
[sunil: Update docstrings, make uninstall fail-safe]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
nbenedek 2023-04-07 02:48:03 +02:00 committed by Sunil Mohan Adapa
parent f11074ab9d
commit 17e062e829
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
3 changed files with 24 additions and 9 deletions

View File

@ -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()

View File

@ -14,4 +14,8 @@ clients = [{
}]
}]
backup = {}
backup = {
'data': {
'files': ['/etc/rss-bridge/is_public']
}
}

View File

@ -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)