diff --git a/plinth/modules/avahi/__init__.py b/plinth/modules/avahi/__init__.py index 886d227bf..f710c9c81 100644 --- a/plinth/modules/avahi/__init__.py +++ b/plinth/modules/avahi/__init__.py @@ -61,7 +61,7 @@ class AvahiApp(app_module.App): domain_type = DomainType('domain-type-local', _('Local Network Domain'), configuration_url='names:hostname', - can_have_certificate=False) + can_have_certificate=False, priority=10) self.add(domain_type) firewall = Firewall('firewall-avahi', info.name, ports=['mdns'], diff --git a/plinth/modules/dynamicdns/__init__.py b/plinth/modules/dynamicdns/__init__.py index 3fd109e26..ecc00053e 100644 --- a/plinth/modules/dynamicdns/__init__.py +++ b/plinth/modules/dynamicdns/__init__.py @@ -78,7 +78,7 @@ class DynamicDNSApp(app_module.App): edit_url='dynamicdns:domain-edit', delete_url='dynamicdns:domain-delete', add_url='dynamicdns:domain-add', - can_have_certificate=True) + can_have_certificate=True, priority=70) self.add(domain_type) users_and_groups = UsersAndGroups('users-and-groups-dynamicdns', diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index ab3848d99..8f0537d58 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -67,7 +67,7 @@ class NamesApp(app_module.App): domain_type = DomainType('domain-type-static', _('Domain (regular)'), delete_url='names:domain-delete', add_url='names:domain-add', - can_have_certificate=True) + can_have_certificate=True, priority=100) self.add(domain_type) daemon = ResolvedDaemon('daemon-names', 'systemd-resolved') diff --git a/plinth/modules/names/components.py b/plinth/modules/names/components.py index f3cd73a52..6b719089e 100644 --- a/plinth/modules/names/components.py +++ b/plinth/modules/names/components.py @@ -46,8 +46,8 @@ class DomainType(app.FollowerComponent): def __init__(self, component_id: str, display_name: str, configuration_url: str | None = None, edit_url: str | None = None, delete_url: str | None = None, - add_url: str | None = None, - can_have_certificate: bool = True): + add_url: str | None = None, can_have_certificate: bool = True, + priority: int = 50): """Initialize the domain type component. component_id should be a unique ID across all components of an app and @@ -73,6 +73,10 @@ class DomainType(app.FollowerComponent): can_have_certificate indicates if this type of domain can have a TLS certificate that can be validated by a typical browser. + + priority decides which domain will be used (by default) when an app can + only deal with a single domain. The domain with highest value will be + chosen by the app by default. """ super().__init__(component_id) @@ -82,6 +86,7 @@ class DomainType(app.FollowerComponent): self.delete_url = delete_url self.add_url = add_url self.can_have_certificate = can_have_certificate + self.priority = priority self._all[component_id] = self diff --git a/plinth/modules/names/tests/test_components.py b/plinth/modules/names/tests/test_components.py index 23784da8e..73ab4578f 100644 --- a/plinth/modules/names/tests/test_components.py +++ b/plinth/modules/names/tests/test_components.py @@ -26,13 +26,15 @@ def test_domain_type_init(): """Test initialization of domain type object.""" component = DomainType('test-component', 'x-display-name', configuration_url='config_url', edit_url='edit_url', - delete_url='delete_url', add_url='add_url') + delete_url='delete_url', add_url='add_url', + priority=80) assert component.component_id == 'test-component' assert component.display_name == 'x-display-name' assert component.configuration_url == 'config_url' assert component.edit_url == 'edit_url' assert component.delete_url == 'delete_url' assert component.add_url == 'add_url' + assert component.priority == 80 assert component.can_have_certificate assert len(DomainType._all) assert DomainType._all['test-component'] == component @@ -43,6 +45,7 @@ def test_domain_type_init(): assert component.edit_url is None assert component.delete_url is None assert component.add_url is None + assert component.priority == 50 assert not component.can_have_certificate diff --git a/plinth/modules/pagekite/__init__.py b/plinth/modules/pagekite/__init__.py index e39152e03..e9b5aa867 100644 --- a/plinth/modules/pagekite/__init__.py +++ b/plinth/modules/pagekite/__init__.py @@ -71,7 +71,7 @@ class PagekiteApp(app_module.App): domain_type = DomainType('domain-type-pagekite', _('PageKite Domain'), configuration_url='pagekite:index', - can_have_certificate=True) + can_have_certificate=True, priority=40) self.add(domain_type) daemon = Daemon('daemon-pagekite', self.DAEMON) diff --git a/plinth/modules/tor/__init__.py b/plinth/modules/tor/__init__.py index bd266fabe..980488f51 100644 --- a/plinth/modules/tor/__init__.py +++ b/plinth/modules/tor/__init__.py @@ -76,7 +76,7 @@ class TorApp(app_module.App): domain_type = DomainType('domain-type-tor', _('Tor Onion Service'), configuration_url='tor:index', - can_have_certificate=False) + can_have_certificate=False, priority=30) self.add(domain_type) firewall = Firewall('firewall-tor-relay', _('Tor Bridge Relay'),