From f8136e8c8fa2db489b771a224174026447d5d006 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 11 Aug 2022 16:44:24 -0700 Subject: [PATCH] sharing: Add installing and enable/disable like other apps - With the new setup mechanism automatic setup of app is no longer possible. - Enabling/disabling is desirable by the user. - During initial setup, ensure that Apache configuration file exists. Upgrade for existing users to create the file. - Enabling/disabling the app enables/disables the web server configuration file. - Diagnostics are not available, disable them explicitly as auto-detect does not work. - Use the regular app base template instead of custom one. - Use framework base classes for view and functional tests. Tests: - Run functional tests. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/sharing/__init__.py | 13 ++- plinth/modules/sharing/privileged.py | 16 ++++ plinth/modules/sharing/templates/sharing.html | 7 +- .../modules/sharing/tests/test_functional.py | 92 +++++++++---------- plinth/modules/sharing/urls.py | 4 +- plinth/modules/sharing/views.py | 12 +-- 6 files changed, 82 insertions(+), 62 deletions(-) create mode 100644 plinth/modules/sharing/privileged.py diff --git a/plinth/modules/sharing/__init__.py b/plinth/modules/sharing/__init__.py index c716b13b5..1ce644648 100644 --- a/plinth/modules/sharing/__init__.py +++ b/plinth/modules/sharing/__init__.py @@ -10,10 +10,11 @@ from django.utils.translation import gettext_lazy as _ from plinth import actions from plinth import app as app_module from plinth import cfg, menu +from plinth.modules.apache.components import Webserver from plinth.modules.backups.components import BackupRestore from plinth.utils import format_lazy -from . import manifest +from . import manifest, privileged _description = [ format_lazy( @@ -28,7 +29,7 @@ class SharingApp(app_module.App): app_id = 'sharing' - _version = 1 + _version = 2 def __init__(self): """Create components for the app.""" @@ -43,13 +44,21 @@ class SharingApp(app_module.App): parent_url_name='apps') self.add(menu_item) + webserver = Webserver('webserver-sharing', 'sharing-freedombox') + self.add(webserver) + backup_restore = BackupRestore('backup-restore-sharing', **manifest.backup) self.add(backup_restore) + def has_diagnostics(self): + """Disable diagnostics button despite having webserver component.""" + return False + def setup(self, old_version): """Install and configure the app.""" super().setup(old_version) + privileged.setup() self.enable() diff --git a/plinth/modules/sharing/privileged.py b/plinth/modules/sharing/privileged.py new file mode 100644 index 000000000..79c247f07 --- /dev/null +++ b/plinth/modules/sharing/privileged.py @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Configure sharing.""" + +import pathlib + +from plinth.actions import privileged + +APACHE_CONFIGURATION = '/etc/apache2/conf-available/sharing-freedombox.conf' + + +@privileged +def setup(): + """Create an empty apache configuration file.""" + path = pathlib.Path(APACHE_CONFIGURATION) + if not path.exists(): + path.touch() diff --git a/plinth/modules/sharing/templates/sharing.html b/plinth/modules/sharing/templates/sharing.html index e63f125d3..4eedd13c7 100644 --- a/plinth/modules/sharing/templates/sharing.html +++ b/plinth/modules/sharing/templates/sharing.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "app.html" %} {% comment %} # SPDX-License-Identifier: AGPL-3.0-or-later {% endcomment %} @@ -11,9 +11,8 @@ href="{% static 'sharing/sharing.css' %}"/> {% endblock %} -{% block content %} - - {% include "app-header.html" with icon_filename=icon_filename name=title description=description %} +{% block configuration %} + {{ block.super }}