From b743305e069ab3f0c948fc3a1cd5acdd8f84edfa Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 9 Jul 2019 11:38:07 -0700 Subject: [PATCH] names: Don't enumerate services for domains supporting all Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/config/__init__.py | 20 +++----------------- plinth/modules/config/views.py | 13 ++----------- plinth/modules/dynamicdns/__init__.py | 20 ++------------------ plinth/modules/dynamicdns/views.py | 4 +--- plinth/modules/names/__init__.py | 4 +++- 5 files changed, 11 insertions(+), 50 deletions(-) diff --git a/plinth/modules/config/__init__.py b/plinth/modules/config/__init__.py index 12aaaadbe..71e202944 100644 --- a/plinth/modules/config/__init__.py +++ b/plinth/modules/config/__init__.py @@ -27,8 +27,6 @@ from django.utils.translation import ugettext_lazy from plinth import actions from plinth import app as app_module from plinth import frontpage, menu -from plinth.modules import firewall -from plinth.modules.names import SERVICES from plinth.signals import domain_added version = 2 @@ -152,21 +150,9 @@ def init(): # Register domain with Name Services module. domainname = get_domainname() if domainname: - try: - domainname_services = firewall.get_enabled_services( - zone='external') - except actions.ActionError: - # This happens when firewalld is not installed. - # TODO: Are these services actually enabled? - domainname_services = [service[0] for service in SERVICES] - else: - domainname_services = None - - if domainname: - domain_added.send_robust(sender='config', domain_type='domainname', - name=domainname, - description=ugettext_lazy('Domain Name'), - services=domainname_services) + domain_added.send_robust( + sender='config', domain_type='domainname', name=domainname, + description=ugettext_lazy('Domain Name'), services='__all__') def setup(helper, old_version=None): diff --git a/plinth/modules/config/views.py b/plinth/modules/config/views.py index 4c81a42e5..f50814e61 100644 --- a/plinth/modules/config/views.py +++ b/plinth/modules/config/views.py @@ -25,8 +25,7 @@ from django.template.response import TemplateResponse from django.utils.translation import ugettext as _ from plinth import actions -from plinth.modules import config, firewall -from plinth.modules.names import SERVICES +from plinth.modules import config from plinth.signals import (domain_added, domain_removed, domainname_change, post_hostname_change, pre_hostname_change) @@ -159,14 +158,6 @@ def set_domainname(domainname): # Update domain registered with Name Services module. domain_removed.send_robust(sender='config', domain_type='domainname') if domainname: - try: - domainname_services = firewall.get_enabled_services( - zone='external') - except actions.ActionError: - # This happens when firewalld is not installed. - # TODO: Are these services actually enabled? - domainname_services = [service[0] for service in SERVICES] - domain_added.send_robust(sender='config', domain_type='domainname', name=domainname, description=_('Domain Name'), - services=domainname_services) + services='__all__') diff --git a/plinth/modules/dynamicdns/__init__.py b/plinth/modules/dynamicdns/__init__.py index fb35a5cd5..639589333 100644 --- a/plinth/modules/dynamicdns/__init__.py +++ b/plinth/modules/dynamicdns/__init__.py @@ -23,12 +23,10 @@ from django.utils.translation import ugettext_lazy as _ from plinth import actions from plinth import app as app_module from plinth import cfg, menu -from plinth.modules import firewall -from plinth.modules.names import SERVICES from plinth.signals import domain_added from plinth.utils import format_lazy -from .manifest import backup # noqa, pylint: disable=unused-import +from .manifest import backup # noqa, pylint: disable=unused-import version = 1 @@ -82,11 +80,10 @@ def init(): app = DynamicDNSApp() current_status = get_status() if current_status['enabled']: - services = get_enabled_services(current_status['dynamicdns_domain']) domain_added.send_robust( sender='dynamicdns', domain_type='dynamicdnsservice', name=current_status['dynamicdns_domain'], - description=_('Dynamic DNS Service'), services=services) + description=_('Dynamic DNS Service'), services='__all__') app.set_enabled(True) @@ -95,19 +92,6 @@ def setup(helper, old_version=None): helper.install(managed_packages) -def get_enabled_services(domain_name): - """Get enabled services for the domain name.""" - if domain_name is not None and domain_name != '': - try: - domainname_services = firewall.get_enabled_services( - zone='external') - except actions.ActionError: - domainname_services = [service[0] for service in SERVICES] - else: - domainname_services = None - return domainname_services - - def get_status(): """Return the current status.""" # TODO: use key/value instead of hard coded value list diff --git a/plinth/modules/dynamicdns/views.py b/plinth/modules/dynamicdns/views.py index 625db4884..14729e741 100644 --- a/plinth/modules/dynamicdns/views.py +++ b/plinth/modules/dynamicdns/views.py @@ -161,12 +161,10 @@ def _apply_changes(request, old_status, new_status): _run(['stop']) if new_status['enabled']: - services = dynamicdns.get_enabled_services( - new_status['dynamicdns_domain']) domain_added.send_robust( sender='dynamicdns', domain_type='dynamicdnsservice', name=new_status['dynamicdns_domain'], - description=_('Dynamic DNS Service'), services=services) + description=_('Dynamic DNS Service'), services='__all__') _run(['start']) messages.success(request, _('Configuration updated')) diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index 89e47d92f..747e962da 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -153,4 +153,6 @@ def get_enabled_services(domain_type, domain): def get_services_status(domain_type, domain): """Get list of whether each service is enabled for a domain.""" enabled = get_enabled_services(domain_type, domain) - return [service[0] in enabled for service in SERVICES] + return [ + enabled == '__all__' or service[0] in enabled for service in SERVICES + ]