mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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:
parent
753881b80f
commit
1dc1278a88
@ -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'])
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user