mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
xmpp: Use common view for configuration
This commit is contained in:
parent
fb19fed6f5
commit
40a9507aae
@ -79,6 +79,13 @@ def setup(helper, old_version=None):
|
||||
helper.call('post', service.notify_enabled, None, True)
|
||||
|
||||
|
||||
def get_status():
|
||||
"""Get the current settings."""
|
||||
return {'enabled': is_enabled(),
|
||||
'is_running': is_running(),
|
||||
'domainname': get_domainname()}
|
||||
|
||||
|
||||
def is_enabled():
|
||||
"""Return whether the module is enabled."""
|
||||
return (action_utils.service_is_enabled('ejabberd') and
|
||||
@ -96,6 +103,13 @@ def get_domainname():
|
||||
return '.'.join(fqdn.split('.')[1:])
|
||||
|
||||
|
||||
def enable(should_enable):
|
||||
"""Enable/disable the module."""
|
||||
sub_command = 'enable' if should_enable else 'disable'
|
||||
actions.superuser_run('xmpp', [sub_command])
|
||||
service.notify_enabled(None, should_enable)
|
||||
|
||||
|
||||
def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs):
|
||||
"""
|
||||
Backup ejabberd database before hostname is changed.
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Forms for configuring XMPP service.
|
||||
"""
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class XmppForm(forms.Form): # pylint: disable=W0232
|
||||
"""XMPP configuration form."""
|
||||
enabled = forms.BooleanField(
|
||||
label=_('Enable XMPP'),
|
||||
required=False)
|
||||
@ -21,8 +21,10 @@ URLs for the XMPP module
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
from plinth.views import ConfigurationView
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^apps/xmpp/$', views.index, name='index'),
|
||||
url(r'^apps/xmpp/$', ConfigurationView.as_view(module_name='xmpp'),
|
||||
name='index'),
|
||||
]
|
||||
|
||||
@ -1,79 +0,0 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Plinth module to configure XMPP server
|
||||
"""
|
||||
|
||||
from django.contrib import messages
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.translation import ugettext as _
|
||||
import logging
|
||||
|
||||
from .forms import XmppForm
|
||||
from plinth import actions
|
||||
from plinth.modules import xmpp
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def index(request):
|
||||
"""Serve configuration page"""
|
||||
status = get_status()
|
||||
|
||||
form = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = XmppForm(request.POST, prefix='xmpp')
|
||||
if form.is_valid():
|
||||
_apply_changes(request, status, form.cleaned_data)
|
||||
status = get_status()
|
||||
form = XmppForm(initial=status, prefix='xmpp')
|
||||
else:
|
||||
form = XmppForm(initial=status, prefix='xmpp')
|
||||
|
||||
return TemplateResponse(request, 'xmpp.html',
|
||||
{'title': xmpp.title,
|
||||
'description': xmpp.description,
|
||||
'status': status,
|
||||
'form': form})
|
||||
|
||||
|
||||
def get_status():
|
||||
"""Get the current settings."""
|
||||
status = {'enabled': xmpp.is_enabled(),
|
||||
'is_running': xmpp.is_running(),
|
||||
'domainname': xmpp.get_domainname()}
|
||||
|
||||
return status
|
||||
|
||||
|
||||
def _apply_changes(request, old_status, new_status):
|
||||
"""Apply the changes."""
|
||||
modified = False
|
||||
|
||||
if old_status['enabled'] != new_status['enabled']:
|
||||
sub_command = 'enable' if new_status['enabled'] else 'disable'
|
||||
actions.superuser_run('xmpp', [sub_command])
|
||||
xmpp.service.notify_enabled(None, new_status['enabled'])
|
||||
modified = True
|
||||
|
||||
if modified:
|
||||
messages.success(request, _('Configuration updated'))
|
||||
else:
|
||||
messages.info(request, _('Setting unchanged'))
|
||||
Loading…
x
Reference in New Issue
Block a user