Alice Kile 0b5b384651
app: Separate app enable/disable form from config form
- Introduce new API to mark an app that it can't be disabled.

- Mark jsxc, storage, config, upgrade and firewall apps as can't be disabled.

- Fixed functional tests

- Replaced AppForm with forms.Form in all modules' forms.py.

- Remove app.template.js.

- Remove unused styles.

- Remove app status checks in form_valid of Deluge, Diaspora, Matrix, Ejabberd,
MediaWiki, Storage, Transmission, Quassel

- Purge unused is_enabled context variables (Ikiwiki)

- ejabberd: Minor cleanup in template

- jsxc: Cleanup unneeded overrides

- tahoe: Cleanup unnecessary overrides

Tests performed:

- For all apps affected, test enable/disable button works and submitting
configuration form works: with changes updates message and without changes
'settings unchanged' message.
  - avahi
  - bind
  - cockpit
  - SKIP: coquelicot
  - datetime
  - deluge
  - SKIP: diaspora
  - ejabberd
  - gitweb
  - i2p
  - infinoted
  - ikiwiki
  - matrixsynapse
  - mediawiki
  - minetest
  - minidlna
  - mldonkey
  - mumble
  - pagekite
  - privoxy
  - quassel
  - radicale
  - roundcube
  - SKIP: samba
  - searx
  - SKIP: shaarli
  - shadowsocks
  - ssh
  - tahoe
  - transmission
  - FAIL: tt-rss (not installable)
  - wireguard
- Deluge test that configuration changes when app is disabled work
- Quassel test that setting the domain works when app is diabled
- Transmission test that setting the domain works when app is diabled
- Ikiwiki create form works properly
- Enable/disable button appears as expected when enabled and when disabled
- Enable/disable button works without Javascript
- Functional tests work for affected apps, Tor and OpenVPN
- AppForm is removed from developer documentation
  - Forms reference
  - Customizing tutorial
- Test all apps using directory select form
  - Transmission
  - Deluge
- Visit each template that overrides block configuration and ensure that it is
loaded properly and the display is as expected.
- All apps that use AppView that are not tested above should not have an
enable/disable button. That is JSXC, update, config, firewall, storage, users.

Signed-off-by: Alice Kile <buoyantair@protonmail.com>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-03-29 09:42:31 +03:00

94 lines
3.4 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Views for the Matrix Synapse module.
"""
from django.contrib import messages
from django.shortcuts import redirect
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.views.generic import FormView
from plinth import actions
from plinth.forms import DomainSelectionForm
from plinth.modules import matrixsynapse, names
from plinth.views import AppView
from . import get_public_registration_status
from .forms import MatrixSynapseForm
class SetupView(FormView):
"""Show matrix-synapse setup page."""
template_name = 'matrix-synapse-pre-setup.html'
form_class = DomainSelectionForm
success_url = reverse_lazy('matrixsynapse:index')
def form_valid(self, form):
"""Handle valid form submission."""
matrixsynapse.setup_domain(form.cleaned_data['domain_name'])
return super().form_valid(form)
def get_context_data(self, *args, **kwargs):
"""Provide context data to the template."""
context = super().get_context_data(**kwargs)
context['title'] = matrixsynapse.app.info.name
context['app_info'] = matrixsynapse.app.info
context['domain_names'] = names.components.DomainName.list_names(
'matrix-synapse-plinth')
return context
class MatrixSynapseAppView(AppView):
"""Show matrix-synapse service page."""
app_id = 'matrixsynapse'
template_name = 'matrix-synapse.html'
form_class = MatrixSynapseForm
port_forwarding_info = matrixsynapse.port_forwarding_info
def dispatch(self, request, *args, **kwargs):
"""Redirect to setup page if setup is not done yet."""
if not matrixsynapse.is_setup():
return redirect('matrixsynapse:setup')
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, *args, **kwargs):
"""Add additional context data for template."""
context = super().get_context_data(*args, **kwargs)
context['domain_name'] = matrixsynapse.get_configured_domain_name()
context['certificate_status'] = matrixsynapse.get_certificate_status()
return context
def get_initial(self):
"""Return the values to fill in the form."""
initial = super().get_initial()
initial.update({
'enable_public_registration': get_public_registration_status(),
})
return initial
def form_valid(self, form):
"""Handle valid form submission."""
old_config = self.get_initial()
new_config = form.cleaned_data
pubreg_same = old_config['enable_public_registration'] == \
new_config['enable_public_registration']
if not pubreg_same:
# note action public-registration restarts, if running now
if new_config['enable_public_registration']:
actions.superuser_run('matrixsynapse',
['public-registration', 'enable'])
messages.success(self.request,
_('Public registration enabled'))
else:
actions.superuser_run('matrixsynapse',
['public-registration', 'disable'])
messages.success(self.request,
_('Public registration disabled'))
return super().form_valid(form)