config: Consolidate get_domainname() implementation into config

- Use the function get_domainname() in config module everywhere
- Delete duplicate implementations in ejabberd and jsxc

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati 2019-02-08 11:18:00 +05:30 committed by Sunil Mohan Adapa
parent 753881b80f
commit 1dc1278a88
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
4 changed files with 16 additions and 27 deletions

View File

@ -19,7 +19,6 @@ FreedomBox app to configure ejabberd server.
""" """
import logging import logging
import socket
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -27,6 +26,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import action_utils, actions, cfg, frontpage from plinth import action_utils, actions, cfg, frontpage
from plinth import service as service_module from plinth import service as service_module
from plinth.menu import main_menu from plinth.menu import main_menu
from plinth.modules import config
from plinth.signals import (domainname_change, post_hostname_change, from plinth.signals import (domainname_change, post_hostname_change,
pre_hostname_change) pre_hostname_change)
from plinth.utils import format_lazy from plinth.utils import format_lazy
@ -75,10 +75,11 @@ def init():
global service global service
setup_helper = globals()['setup_helper'] setup_helper = globals()['setup_helper']
if setup_helper.get_state() != 'needs-setup': if setup_helper.get_state() != 'needs-setup':
service = service_module.Service('ejabberd', name, ports=[ service = service_module.Service(
'xmpp-client', 'xmpp-server', 'xmpp-bosh' 'ejabberd', name,
], is_external=True, is_enabled=is_enabled, enable=enable, ports=['xmpp-client', 'xmpp-server',
disable=disable) 'xmpp-bosh'], is_external=True, is_enabled=is_enabled,
enable=enable, disable=disable)
if is_enabled(): if is_enabled():
add_shortcut() add_shortcut()
pre_hostname_change.connect(on_pre_hostname_change) pre_hostname_change.connect(on_pre_hostname_change)
@ -88,7 +89,7 @@ def init():
def setup(helper, old_version=None): def setup(helper, old_version=None):
"""Install and configure the module.""" """Install and configure the module."""
domainname = get_domainname() domainname = config.get_domainname()
logger.info('ejabberd service domainname - %s', domainname) logger.info('ejabberd service domainname - %s', domainname)
helper.call('pre', actions.superuser_run, 'ejabberd', helper.call('pre', actions.superuser_run, 'ejabberd',
@ -97,10 +98,11 @@ def setup(helper, old_version=None):
helper.call('post', actions.superuser_run, 'ejabberd', ['setup']) helper.call('post', actions.superuser_run, 'ejabberd', ['setup'])
global service global service
if service is None: if service is None:
service = service_module.Service('ejabberd', name, ports=[ service = service_module.Service(
'xmpp-client', 'xmpp-server', 'xmpp-bosh' 'ejabberd', name,
], is_external=True, is_enabled=is_enabled, enable=enable, ports=['xmpp-client', 'xmpp-server',
disable=disable) 'xmpp-bosh'], is_external=True, is_enabled=is_enabled,
enable=enable, disable=disable)
helper.call('post', service.notify_enabled, None, True) helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut) helper.call('post', add_shortcut)
@ -117,12 +119,6 @@ def is_enabled():
return action_utils.service_is_enabled('ejabberd') return action_utils.service_is_enabled('ejabberd')
def get_domainname():
"""Return the domainname"""
fqdn = socket.getfqdn()
return '.'.join(fqdn.split('.')[1:])
def enable(): def enable():
"""Enable the module.""" """Enable the module."""
actions.superuser_run('ejabberd', ['enable']) actions.superuser_run('ejabberd', ['enable'])

View File

@ -22,7 +22,7 @@ from django.contrib import messages
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from plinth import actions from plinth import actions
from plinth.modules import ejabberd from plinth.modules import config, ejabberd
from plinth.views import ServiceView from plinth.views import ServiceView
from .forms import EjabberdForm from .forms import EjabberdForm
@ -45,7 +45,7 @@ class EjabberdServiceView(ServiceView):
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
"""Add service to the context data.""" """Add service to the context data."""
context = super().get_context_data(*args, **kwargs) context = super().get_context_data(*args, **kwargs)
context['domainname'] = ejabberd.get_domainname() context['domainname'] = config.get_domainname()
context['clients'] = ejabberd.clients context['clients'] = ejabberd.clients
return context return context

View File

@ -19,7 +19,6 @@ FreedomBox app to configure XMPP web client/jsxc.
""" """
import logging import logging
import socket
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -90,12 +89,6 @@ def is_enabled():
return setup_helper.get_state() != 'needs-setup' return setup_helper.get_state() != 'needs-setup'
def get_domainname():
"""Return the domainname"""
fqdn = socket.getfqdn()
return '.'.join(fqdn.split('.')[1:])
def enable(): def enable():
add_shortcut() add_shortcut()

View File

@ -22,7 +22,7 @@ from django.views.generic import TemplateView
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from stronghold.decorators import public from stronghold.decorators import public
from plinth.modules import jsxc from plinth.modules import config, jsxc
from plinth.views import ServiceView from plinth.views import ServiceView
@ -47,5 +47,5 @@ class JsxcView(TemplateView):
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
"""Add domain information to view context.""" """Add domain information to view context."""
context = super().get_context_data(*args, **kwargs) context = super().get_context_data(*args, **kwargs)
context['domainname'] = jsxc.get_domainname() context['domainname'] = config.get_domainname()
return context return context