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

View File

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

View File

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

View File

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