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

89 lines
3.5 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app for configuring MediaWiki.
"""
import logging
from django.contrib import messages
from django.utils.translation import ugettext as _
from plinth import actions, views
from plinth.modules import mediawiki
from . import (get_default_skin, is_private_mode_enabled,
is_public_registration_enabled)
from .forms import MediaWikiForm
logger = logging.getLogger(__name__)
class MediaWikiAppView(views.AppView):
"""App configuration page."""
app_id = 'mediawiki'
form_class = MediaWikiForm
template_name = 'mediawiki.html'
def get_initial(self):
"""Return the values to fill in the form."""
initial = super().get_initial()
initial.update({
'enable_public_registrations': is_public_registration_enabled(),
'enable_private_mode': is_private_mode_enabled(),
'default_skin': get_default_skin()
})
return initial
def form_valid(self, form):
"""Apply the changes submitted in the form."""
old_config = self.get_initial()
new_config = form.cleaned_data
def is_unchanged(key):
return old_config[key] == new_config[key]
if new_config['password']:
actions.superuser_run('mediawiki', ['change-password'],
input=new_config['password'].encode())
messages.success(self.request, _('Password updated'))
if not is_unchanged('enable_public_registrations'):
# note action public-registration restarts, if running now
if new_config['enable_public_registrations']:
if not new_config['enable_private_mode']:
actions.superuser_run('mediawiki',
['public-registrations', 'enable'])
messages.success(self.request,
_('Public registrations enabled'))
else:
messages.warning(
self.request, 'Public registrations ' +
'cannot be enabled when private mode is enabled')
else:
actions.superuser_run('mediawiki',
['public-registrations', 'disable'])
messages.success(self.request,
_('Public registrations disabled'))
if not is_unchanged('enable_private_mode'):
if new_config['enable_private_mode']:
actions.superuser_run('mediawiki', ['private-mode', 'enable'])
messages.success(self.request, _('Private mode enabled'))
if new_config['enable_public_registrations']:
# If public registrations are enabled, then disable it
actions.superuser_run('mediawiki',
['public-registrations', 'disable'])
else:
actions.superuser_run('mediawiki', ['private-mode', 'disable'])
messages.success(self.request, _('Private mode disabled'))
shortcut = mediawiki.app.get_component('shortcut-mediawiki')
shortcut.login_required = new_config['enable_private_mode']
if not is_unchanged('default_skin'):
actions.superuser_run(
'mediawiki', ['set-default-skin', new_config['default_skin']])
messages.success(self.request, _('Default skin changed'))
return super().form_valid(form)