Hide mediawiki frontpage shortcut when private mode is enabled

Signed-off-by: Hemanth Kumar Veeranki <hemanthveeranki@gmail.com>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
Hemanth Kumar Veeranki 2018-06-05 21:33:49 +05:30 committed by Joseph Nuthalapati
parent f83e22ba75
commit a9fa28d3de
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35
3 changed files with 16 additions and 16 deletions

View File

@ -98,7 +98,7 @@ def add_shortcut():
"""Helper method to add a shortcut to the frontpage."""
frontpage.add_shortcut('mediawiki', name,
short_description=short_description,
url='/mediawiki', login_required=False)
url='/mediawiki', login_required=is_private_mode_enabled())
def is_enabled():
@ -125,18 +125,17 @@ def diagnose():
results.extend(
action_utils.diagnose_url_on_all('https://{host}/mediawiki',
check_certificate=False))
return results
def get_public_registration_status():
def is_public_registration_enabled():
"""Return whether public registration is enabled."""
output = actions.superuser_run('mediawiki',
['public-registrations', 'status'])
return output.strip() == 'enabled'
def get_private_mode_status():
def is_private_mode_enabled():
""" Return wheter private mode is enabled or disabled"""
output = actions.superuser_run('mediawiki',
['private-mode', 'status'])

View File

@ -33,12 +33,12 @@ class MediaWikiForm(ServiceForm): # pylint: disable=W0232
required=False, widget=forms.PasswordInput)
enable_public_registrations = forms.BooleanField(
label=_('Enable public registrations'), required=False, help_text=_(
'If enabled, anyone on the internet will be able to '
'create an account on your MediaWiki instance.'))
label=_('Enable public registrations'), required=False,
help_text=_('If enabled, anyone on the internet will be able to '
'create an account on your MediaWiki instance.'))
enable_private_mode = forms.BooleanField(
label=_('Enable private mode'), required=False, help_text=_(
'If enabled, Access will be restricted. Only people '
'who have accounts can read/write to the wiki. '
'Public registrations will also be disabled.'))
label=_('Enable private mode'), required=False,
help_text=_('If enabled, access will be restricted. Only people '
'who have accounts can read/write to the wiki. '
'Public registrations will also be disabled.'))

View File

@ -23,10 +23,10 @@ import logging
from django.contrib import messages
from django.utils.translation import ugettext as _
from plinth import actions, views
from plinth import actions, views, frontpage
from plinth.modules import mediawiki
from . import get_public_registration_status, get_private_mode_status
from . import is_public_registration_enabled, is_private_mode_enabled, is_enabled, add_shortcut
from .forms import MediaWikiForm
logger = logging.getLogger(__name__)
@ -46,8 +46,8 @@ class MediaWikiServiceView(views.ServiceView):
"""Return the values to fill in the form."""
initial = super().get_initial()
initial.update({
'enable_public_registrations': get_public_registration_status(),
'enable_private_mode': get_private_mode_status()
'enable_public_registrations': is_public_registration_enabled(),
'enable_private_mode': is_private_mode_enabled()
})
return initial
@ -107,5 +107,6 @@ class MediaWikiServiceView(views.ServiceView):
['private-mode', 'disable'])
messages.success(self.request,
_('Private mode disabled'))
if is_enabled():
add_shortcut()
return super().form_valid(form)