From 1dc1278a88248bfda6074a1abe7b4a552f915abb Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Fri, 8 Feb 2019 11:18:00 +0530 Subject: [PATCH] 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 Reviewed-by: Sunil Mohan Adapa --- plinth/modules/ejabberd/__init__.py | 28 ++++++++++++---------------- plinth/modules/ejabberd/views.py | 4 ++-- plinth/modules/jsxc/__init__.py | 7 ------- plinth/modules/jsxc/views.py | 4 ++-- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/plinth/modules/ejabberd/__init__.py b/plinth/modules/ejabberd/__init__.py index 57270c933..c4bbd99c0 100644 --- a/plinth/modules/ejabberd/__init__.py +++ b/plinth/modules/ejabberd/__init__.py @@ -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']) diff --git a/plinth/modules/ejabberd/views.py b/plinth/modules/ejabberd/views.py index 4da02bbd1..c80d1b8d1 100644 --- a/plinth/modules/ejabberd/views.py +++ b/plinth/modules/ejabberd/views.py @@ -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 diff --git a/plinth/modules/jsxc/__init__.py b/plinth/modules/jsxc/__init__.py index 155836754..967a9ad15 100644 --- a/plinth/modules/jsxc/__init__.py +++ b/plinth/modules/jsxc/__init__.py @@ -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() diff --git a/plinth/modules/jsxc/views.py b/plinth/modules/jsxc/views.py index 3eed5bfe8..bc006410f 100644 --- a/plinth/modules/jsxc/views.py +++ b/plinth/modules/jsxc/views.py @@ -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