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 <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2024-10-01 19:01:01 -07:00 committed by Veiko Aasa
parent 71ed5f16c2
commit 1f17728321
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -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."""