From 524fdf60492ae6c3045d5694795cb4dfee6784e1 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 7 Mar 2024 17:58:41 -0800 Subject: [PATCH] app: Add ability to hide configuration form when app is disabled - Some apps store their configuration in database. The database server may not be running when app is disabled. Configuration changes may then not be possible for such apps. Provide the ability to disable configuration for apps that don't support configuration changes when disabled. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/app.py | 6 ++++++ plinth/tests/test_app.py | 3 +++ plinth/views.py | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/plinth/app.py b/plinth/app.py index 6969720f1..c093ceb32 100644 --- a/plinth/app.py +++ b/plinth/app.py @@ -42,6 +42,10 @@ class App: the app. This flag is currently set during backup and restore operations but UI changes are currently not implemented. + 'configure_when_disabled' is a boolean indicating whether the app can + configured while it is disabled. Some apps such those whose configuration + is stored in a database can't be configured while they are disabled because + the database server may not be running when the app is disabled. """ app_id: str | None = None @@ -51,6 +55,8 @@ class App: locked: bool = False # Whether user interaction with the app is allowed. # XXX: Lockdown the application UI by implementing a middleware + configure_when_disabled: bool = True + _all_apps: ClassVar[collections.OrderedDict[ str, 'App']] = collections.OrderedDict() diff --git a/plinth/tests/test_app.py b/plinth/tests/test_app.py index 86bcfec65..1ea6fc523 100644 --- a/plinth/tests/test_app.py +++ b/plinth/tests/test_app.py @@ -67,6 +67,9 @@ def test_app_instantiation(): assert app.app_id == 'test-app' assert app._all_apps['test-app'] == app assert len(app._all_apps) == 1 + assert app.can_be_disabled + assert not app.locked + assert app.configure_when_disabled def test_app_get(): diff --git a/plinth/views.py b/plinth/views.py index da37eeaea..e79c3fb5e 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -215,6 +215,11 @@ class AppView(FormView): if not self.form_class: return None + if not self.app.configure_when_disabled: + status = self.get_common_status() + if not status['is_enabled']: + return None + return super().get_form(*args, **kwargs) def _get_common_status(self):