mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
mediawiki: Make private mode and public registrations mutually exclusive
- Added JavaScript code to make sure that only one of the checkboxes can be enabled at any time. - Handled the condition where a user disables JavaScript and tries to enable public registrations when private mode is active. The action will not proceed and a warning will be displayed in the response page. Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
2bd6d69e15
commit
62ccfdfebd
@ -53,3 +53,16 @@ Scenario: Disable private mode
|
|||||||
Given the mediawiki application is enabled
|
Given the mediawiki application is enabled
|
||||||
When I disable mediawiki private mode
|
When I disable mediawiki private mode
|
||||||
Then the mediawiki site should allow anonymous reads and writes
|
Then the mediawiki site should allow anonymous reads and writes
|
||||||
|
|
||||||
|
Scenario: Enabling private mode disables public registrations
|
||||||
|
Given the mediawiki application is enabled
|
||||||
|
When I enable mediawiki public registrations
|
||||||
|
And I enable mediawiki private mode
|
||||||
|
Then the mediawiki site should not allow creating accounts
|
||||||
|
|
||||||
|
# Requires JS
|
||||||
|
Scenario: Enabling public registrations disables private mode
|
||||||
|
Given the mediawiki application is enabled
|
||||||
|
When I enable mediawiki private mode
|
||||||
|
And I enable mediawiki public registrations
|
||||||
|
Then the mediawiki site should allow creating accounts
|
||||||
|
|||||||
41
plinth/modules/mediawiki/templates/mediawiki.html
Normal file
41
plinth/modules/mediawiki/templates/mediawiki.html
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{% extends "service.html" %}
|
||||||
|
{% comment %}
|
||||||
|
#
|
||||||
|
# This file is part of FreedomBox.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
{% endcomment %}
|
||||||
|
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block page_js %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function($) {
|
||||||
|
$('#id_enable_public_registrations').click(function () {
|
||||||
|
var checkedState = $(this).prop("checked");
|
||||||
|
if (checkedState) {
|
||||||
|
$('#id_enable_private_mode').prop('checked', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#id_enable_private_mode').click(function () {
|
||||||
|
var checkedState = $(this).prop("checked");
|
||||||
|
if (checkedState) {
|
||||||
|
$('#id_enable_public_registrations').prop('checked', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(jQuery);
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
@ -23,10 +23,11 @@ import logging
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from plinth import actions, views, frontpage
|
from plinth import actions, views
|
||||||
from plinth.modules import mediawiki
|
from plinth.modules import mediawiki
|
||||||
|
|
||||||
from . import is_public_registration_enabled, is_private_mode_enabled, is_enabled, add_shortcut
|
from . import (add_shortcut, is_enabled, is_private_mode_enabled,
|
||||||
|
is_public_registration_enabled)
|
||||||
from .forms import MediaWikiForm
|
from .forms import MediaWikiForm
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -41,6 +42,7 @@ class MediaWikiServiceView(views.ServiceView):
|
|||||||
form_class = MediaWikiForm
|
form_class = MediaWikiForm
|
||||||
manual_page = mediawiki.manual_page
|
manual_page = mediawiki.manual_page
|
||||||
show_status_block = False
|
show_status_block = False
|
||||||
|
template_name = 'mediawiki.html'
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
"""Return the values to fill in the form."""
|
"""Return the values to fill in the form."""
|
||||||
@ -82,10 +84,15 @@ class MediaWikiServiceView(views.ServiceView):
|
|||||||
if not pub_reg_same:
|
if not pub_reg_same:
|
||||||
# note action public-registration restarts, if running now
|
# note action public-registration restarts, if running now
|
||||||
if new_config['enable_public_registrations']:
|
if new_config['enable_public_registrations']:
|
||||||
actions.superuser_run('mediawiki',
|
if not new_config['enable_private_mode']:
|
||||||
['public-registrations', 'enable'])
|
actions.superuser_run('mediawiki',
|
||||||
messages.success(self.request,
|
['public-registrations', 'enable'])
|
||||||
_('Public registrations enabled'))
|
messages.success(self.request,
|
||||||
|
_('Public registrations enabled'))
|
||||||
|
else:
|
||||||
|
messages.warning(
|
||||||
|
self.request, 'Public registrations ' +
|
||||||
|
'cannot be enabled when private mode is enabled')
|
||||||
else:
|
else:
|
||||||
actions.superuser_run('mediawiki',
|
actions.superuser_run('mediawiki',
|
||||||
['public-registrations', 'disable'])
|
['public-registrations', 'disable'])
|
||||||
@ -94,19 +101,15 @@ class MediaWikiServiceView(views.ServiceView):
|
|||||||
|
|
||||||
if not private_mode_same:
|
if not private_mode_same:
|
||||||
if new_config['enable_private_mode']:
|
if new_config['enable_private_mode']:
|
||||||
actions.superuser_run('mediawiki',
|
actions.superuser_run('mediawiki', ['private-mode', 'enable'])
|
||||||
['private-mode', 'enable'])
|
|
||||||
if new_config['enable_public_registrations']:
|
if new_config['enable_public_registrations']:
|
||||||
# If public registrations are enabled, then disable it
|
# If public registrations are enabled, then disable it
|
||||||
actions.superuser_run('mediawiki',
|
actions.superuser_run('mediawiki',
|
||||||
['public-registrations', 'disable'])
|
['public-registrations', 'disable'])
|
||||||
messages.success(self.request,
|
messages.success(self.request, _('Private mode enabled'))
|
||||||
_('Private mode enabled'))
|
|
||||||
else:
|
else:
|
||||||
actions.superuser_run('mediawiki',
|
actions.superuser_run('mediawiki', ['private-mode', 'disable'])
|
||||||
['private-mode', 'disable'])
|
messages.success(self.request, _('Private mode disabled'))
|
||||||
messages.success(self.request,
|
|
||||||
_('Private mode disabled'))
|
|
||||||
if is_enabled():
|
if is_enabled():
|
||||||
add_shortcut()
|
add_shortcut()
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user