From 1f177283211ddf36ab2c465c3e54fd31aba49528 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 1 Oct 2024 19:01:01 -0700 Subject: [PATCH] networks: Disable DNS-over-TLS option if resolved is not installed Tests: - Ensure that systemd-resolved package is not installed. DNS-over-TLS field is disabled. - Submitting the form works with and without changes. - Value of global DNS-over-TLS setting shows as 'unknown'. - Current value of DNS-over-TLS for this connection is show in the form. - Ensure that systemd-resolved package is installed. DNS-over-TLS field is enabled. - Submitting the form works with and without changes. - Value of the global DNS-over-TLS setting shows the current value set in names app. - Current value of DNS-over-TLS for this connection is show in the form. - Introduce an exception in get_resolved_configuration privileged action and notice that value shows up as 'unknown' in the form. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- plinth/modules/networks/forms.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plinth/modules/networks/forms.py b/plinth/modules/networks/forms.py index d16059e51..0067dc023 100644 --- a/plinth/modules/networks/forms.py +++ b/plinth/modules/networks/forms.py @@ -7,6 +7,7 @@ from django.utils.functional import lazy from django.utils.translation import gettext_lazy as _ from plinth import cfg, network +from plinth.modules import names from plinth.utils import format_lazy, import_from_gi nm = import_from_gi('NM', '1.0') @@ -14,11 +15,14 @@ nm = import_from_gi('NM', '1.0') def _get_dns_over_tls(): """Return the value of DNS over TLS.""" + if not names.is_resolved_installed(): + return str(_('unknown')) + try: from plinth.modules.names import privileged dns_over_tls = privileged.get_resolved_configuration()['dns_over_tls'] except Exception: - return _('unknown') + return str(_('unknown')) value_map = { 'yes': _('yes'), @@ -160,6 +164,13 @@ class ConnectionForm(forms.Form): 'provided by a DHCP server will be ignored.'), validators=[validators.validate_ipv6_address], required=False) + def __init__(self, *args, **kwargs): + """Disable DNS fallback field if necessary.""" + from plinth.modules import names + super().__init__(*args, **kwargs) + self.fields['dns_over_tls'].disabled = ( + not names.is_resolved_installed()) + @staticmethod def _get_interface_choices(device_type): """Return a list of choices for a given device type."""