mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
diagnostics: Translate descriptions only in view
Tests: - Enable all apps, and run diagnostics. Diagnostic descriptions are formatted as expected. - Change the language to Spanish, and view the diagnostic results. Diagnostic descriptions are translated as expected. Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
1 parent
a5820bc36d
commit
3fcd6b9e58
18 files changed
+101
-89
No files matched your search
@@ -4,8 +4,7 @@
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import action_utils, app
|
||||
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
|
||||
@@ -149,16 +148,13 @@ def diagnose_url(url, kind=None, env=None, check_certificate=True,
|
||||
except FileNotFoundError:
|
||||
result = Result.ERROR
|
||||
|
||||
parameters = {'url': url}
|
||||
parameters = {'url': url, 'kind': kind}
|
||||
if kind:
|
||||
parameters['kind'] = kind
|
||||
check_id = f'apache-url-kind-{url}-{kind}'
|
||||
template = gettext_lazy('Access URL {url} on tcp{kind}')
|
||||
description = format_lazy(template, url=url, kind=kind)
|
||||
description = gettext_noop('Access URL {url} on tcp{kind}')
|
||||
else:
|
||||
check_id = f'apache-url-{url}'
|
||||
template = gettext_lazy('Access URL {url}')
|
||||
description = format_lazy(template, url=url)
|
||||
description = gettext_noop('Access URL {url}')
|
||||
|
||||
return DiagnosticCheck(check_id, description, result, parameters)
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ from plinth import app
|
||||
from plinth.modules.apache.components import (Uwsgi, Webserver, check_url,
|
||||
diagnose_url,
|
||||
diagnose_url_on_all)
|
||||
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
|
||||
from plinth.modules.diagnostics.check import (DiagnosticCheck, Result,
|
||||
translate, translate_checks)
|
||||
|
||||
|
||||
def test_webserver_init():
|
||||
@@ -248,13 +249,13 @@ def test_diagnose_url(get_addresses, check):
|
||||
}
|
||||
parameters = {key: args[key] for key in ['url', 'kind']}
|
||||
check.return_value = True
|
||||
result = diagnose_url(**args)
|
||||
result = translate(diagnose_url(**args))
|
||||
assert result == DiagnosticCheck(
|
||||
'apache-url-kind-https://localhost/test-4',
|
||||
'Access URL https://localhost/test on tcp4', Result.PASSED, parameters)
|
||||
|
||||
check.return_value = False
|
||||
result = diagnose_url(**args)
|
||||
result = translate(diagnose_url(**args))
|
||||
assert result == DiagnosticCheck(
|
||||
'apache-url-kind-https://localhost/test-4',
|
||||
'Access URL https://localhost/test on tcp4', Result.FAILED, parameters)
|
||||
@@ -283,7 +284,7 @@ def test_diagnose_url(get_addresses, check):
|
||||
'kind': '6'
|
||||
},
|
||||
]
|
||||
results = diagnose_url_on_all(**args)
|
||||
results = translate_checks(diagnose_url_on_all(**args))
|
||||
assert results == [
|
||||
DiagnosticCheck('apache-url-kind-https://test-host-1/test-4',
|
||||
'Access URL https://test-host-1/test on tcp4',
|
||||
|
||||
@@ -6,6 +6,7 @@ FreedomBox app to configure system date and time.
|
||||
import subprocess
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import app as app_module
|
||||
from plinth import menu
|
||||
@@ -118,4 +119,5 @@ def _diagnose_time_synchronized():
|
||||
pass
|
||||
|
||||
return DiagnosticCheck('datetime-ntp-sync',
|
||||
_('Time synchronized to NTP server'), result)
|
||||
gettext_noop('Time synchronized to NTP server'),
|
||||
result)
|
||||
@@ -3,6 +3,7 @@
|
||||
FreedomBox app for running diagnostics.
|
||||
"""
|
||||
|
||||
from copy import deepcopy
|
||||
import logging
|
||||
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
@@ -17,7 +18,7 @@ from plinth.app import App
|
||||
from plinth.modules import diagnostics
|
||||
from plinth.views import AppView
|
||||
|
||||
from .check import Result
|
||||
from .check import Result, translate_checks
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -62,7 +63,14 @@ class DiagnosticsFullView(TemplateView):
|
||||
is_task_running = False
|
||||
|
||||
with diagnostics.results_lock:
|
||||
results = diagnostics.current_results
|
||||
results = deepcopy(diagnostics.current_results)
|
||||
|
||||
# Translate and format diagnostic check descriptions for each app
|
||||
for app_id in results['results']:
|
||||
if 'diagnosis' in results['results'][app_id]:
|
||||
diagnosis = results['results'][app_id]['diagnosis']
|
||||
results['results'][app_id]['diagnosis'] = translate_checks(
|
||||
diagnosis)
|
||||
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['is_task_running'] = is_task_running
|
||||
@@ -89,6 +97,8 @@ def diagnose_app(request, app_id):
|
||||
exception)
|
||||
diagnosis_exception = str(exception)
|
||||
|
||||
# Translate and format diagnostic check descriptions
|
||||
diagnosis = translate_checks(diagnosis)
|
||||
show_rerun_setup = False
|
||||
for check in diagnosis:
|
||||
if check.result in [Result.FAILED, Result.WARNING]:
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
import contextlib
|
||||
import logging
|
||||
|
||||
from django.utils.translation import gettext
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import app as app_module
|
||||
from plinth import cfg, menu
|
||||
@@ -268,7 +268,7 @@ def remove_passthrough(ipv, *args):
|
||||
def _diagnose_default_zone(config):
|
||||
"""Diagnose whether the default zone is external."""
|
||||
check_id = 'firewall-default-zone'
|
||||
description = gettext('Default zone is external')
|
||||
description = gettext_noop('Default zone is external')
|
||||
result = Result.PASSED if config[
|
||||
'default_zone'] == 'external' else Result.FAILED
|
||||
return DiagnosticCheck(check_id, description, result)
|
||||
@@ -277,7 +277,7 @@ def _diagnose_default_zone(config):
|
||||
def _diagnose_firewall_backend(config):
|
||||
"""Diagnose whether the firewall backend is nftables."""
|
||||
check_id = 'firewall-backend'
|
||||
description = gettext('Firewall backend is nftables')
|
||||
description = gettext_noop('Firewall backend is nftables')
|
||||
result = Result.PASSED if config['backend'] == 'nftables' \
|
||||
else Result.FAILED
|
||||
return DiagnosticCheck(check_id, description, result)
|
||||
@@ -290,7 +290,7 @@ def _diagnose_direct_passthroughs(config):
|
||||
which are the number that are added by firewall's setup.
|
||||
"""
|
||||
check_id = 'firewall-direct-passthroughs'
|
||||
description = gettext('Direct passthrough rules exist')
|
||||
description = gettext_noop('Direct passthrough rules exist')
|
||||
result = Result.PASSED if len(
|
||||
config['passthroughs']) >= 12 else Result.FAILED
|
||||
return DiagnosticCheck(check_id, description, result)
|
||||
@@ -7,8 +7,7 @@ import logging
|
||||
import re
|
||||
from typing import ClassVar
|
||||
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import app
|
||||
from plinth.modules import firewall
|
||||
@@ -133,9 +132,8 @@ class Firewall(app.FollowerComponent):
|
||||
# Internal zone
|
||||
check_id = f'firewall-port-internal-{port}'
|
||||
result = Result.PASSED if port in internal_ports else Result.FAILED
|
||||
template = _(
|
||||
description = gettext_noop(
|
||||
'Port {name} ({details}) available for internal networks')
|
||||
description = format_lazy(template, name=port, details=details)
|
||||
parameters = {'name': port, 'details': details}
|
||||
results.append(
|
||||
DiagnosticCheck(check_id, description, result, parameters))
|
||||
@@ -145,17 +143,15 @@ class Firewall(app.FollowerComponent):
|
||||
check_id = f'firewall-port-external-available-{port}'
|
||||
result = Result.PASSED \
|
||||
if port in external_ports else Result.FAILED
|
||||
template = _(
|
||||
description = gettext_noop(
|
||||
'Port {name} ({details}) available for external networks')
|
||||
description = format_lazy(template, name=port, details=details)
|
||||
else:
|
||||
check_id = f'firewall-port-external-unavailable-{port}'
|
||||
result = Result.PASSED \
|
||||
if port not in external_ports else Result.FAILED
|
||||
template = _(
|
||||
description = gettext_noop(
|
||||
'Port {name} ({details}) unavailable for external networks'
|
||||
)
|
||||
description = format_lazy(template, name=port, details=details)
|
||||
|
||||
parameters = {'name': port, 'details': details}
|
||||
results.append(
|
||||
|
||||
@@ -8,7 +8,8 @@ from unittest.mock import call, patch
|
||||
import pytest
|
||||
|
||||
from plinth.app import App
|
||||
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
|
||||
from plinth.modules.diagnostics.check import (DiagnosticCheck, Result,
|
||||
translate_checks)
|
||||
from plinth.modules.firewall.components import (Firewall,
|
||||
FirewallLocalProtection)
|
||||
|
||||
@@ -153,7 +154,7 @@ def test_diagnose(get_enabled_services, get_port_details):
|
||||
get_port_details.side_effect = get_port_details_side_effect
|
||||
firewall = Firewall('test-firewall-1', ports=['test-port1', 'test-port2'],
|
||||
is_external=False)
|
||||
results = firewall.diagnose()
|
||||
results = translate_checks(firewall.diagnose())
|
||||
assert results == [
|
||||
DiagnosticCheck(
|
||||
'firewall-port-internal-test-port1',
|
||||
@@ -187,7 +188,7 @@ def test_diagnose(get_enabled_services, get_port_details):
|
||||
|
||||
firewall = Firewall('test-firewall-1', ports=['test-port3', 'test-port4'],
|
||||
is_external=True)
|
||||
results = firewall.diagnose()
|
||||
results = translate_checks(firewall.diagnose())
|
||||
assert results == [
|
||||
DiagnosticCheck(
|
||||
'firewall-port-internal-test-port3',
|
||||
|
||||
@@ -6,6 +6,7 @@ import logging
|
||||
import pathlib
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import app as app_module
|
||||
from plinth import cfg, menu
|
||||
@@ -13,6 +14,7 @@ from plinth.config import DropinConfigs
|
||||
from plinth.modules import names
|
||||
from plinth.modules.apache.components import diagnose_url
|
||||
from plinth.modules.backups.components import BackupRestore
|
||||
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
|
||||
from plinth.modules.names.components import DomainType
|
||||
from plinth.package import Packages
|
||||
from plinth.signals import domain_added, domain_removed, post_app_loading
|
||||
@@ -97,7 +99,10 @@ class LetsEncryptApp(app_module.App):
|
||||
|
||||
if not results:
|
||||
results.append(
|
||||
(_('Cannot test: No domains are configured.'), 'warning'))
|
||||
DiagnosticCheck(
|
||||
'letsencrypt-cannot-test',
|
||||
gettext_noop('Cannot test: No domains are configured.'),
|
||||
Result.WARNING))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ FreedomBox app to configure Privoxy.
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth import app as app_module
|
||||
@@ -112,9 +113,9 @@ def diagnose_url_with_proxy():
|
||||
|
||||
result = diagnose_url(url, kind=address['kind'], env=env)
|
||||
result.check_id = f'privoxy-url-proxy-kind-{url}-{address["kind"]}'
|
||||
result.description = _(
|
||||
'Access {url} with proxy {proxy} on tcp{kind}') \
|
||||
.format(url=url, proxy=proxy, kind=address['kind'])
|
||||
result.description = gettext_noop(
|
||||
'Access {url} with proxy {proxy} on tcp{kind}')
|
||||
result.parameters['proxy'] = proxy
|
||||
results.append(result)
|
||||
|
||||
return results
|
||||
@@ -5,6 +5,7 @@ import json
|
||||
import logging
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth import app as app_module
|
||||
@@ -134,7 +135,7 @@ class TorApp(app_module.App):
|
||||
if status['relay_enabled']:
|
||||
results.append(
|
||||
DiagnosticCheck(
|
||||
'tor-port-relay', _('Tor relay port available'),
|
||||
'tor-port-relay', gettext_noop('Tor relay port available'),
|
||||
Result.PASSED if 'orport' in ports else Result.FAILED))
|
||||
if 'orport' in ports:
|
||||
results.append(
|
||||
@@ -145,7 +146,8 @@ class TorApp(app_module.App):
|
||||
if status['bridge_relay_enabled']:
|
||||
results.append(
|
||||
DiagnosticCheck(
|
||||
'tor-port-obfs3', _('Obfs3 transport registered'),
|
||||
'tor-port-obfs3',
|
||||
gettext_noop('Obfs3 transport registered'),
|
||||
Result.PASSED if 'obfs3' in ports else Result.FAILED))
|
||||
if 'obfs3' in ports:
|
||||
results.append(
|
||||
@@ -155,7 +157,8 @@ class TorApp(app_module.App):
|
||||
|
||||
results.append(
|
||||
DiagnosticCheck(
|
||||
'tor-port-obfs4', _('Obfs4 transport registered'),
|
||||
'tor-port-obfs4',
|
||||
gettext_noop('Obfs4 transport registered'),
|
||||
Result.PASSED if 'obfs4' in ports else Result.FAILED))
|
||||
if 'obfs4' in ports:
|
||||
results.append(
|
||||
@@ -167,8 +170,8 @@ class TorApp(app_module.App):
|
||||
hs_hostname = status['hs_hostname'].split('.onion')[0]
|
||||
results.append(
|
||||
DiagnosticCheck(
|
||||
'tor-onion-version', _('Onion service is version 3'),
|
||||
Result.PASSED
|
||||
'tor-onion-version',
|
||||
gettext_noop('Onion service is version 3'), Result.PASSED
|
||||
if len(hs_hostname) == 56 else Result.FAILED))
|
||||
|
||||
return results
|
||||
|
||||
@@ -6,6 +6,7 @@ import logging
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import app as app_module
|
||||
from plinth import cfg, frontpage, kvstore, menu
|
||||
@@ -136,8 +137,7 @@ def _diagnose_url_via_tor(url, kind=None):
|
||||
"""Diagnose whether a URL is reachable via Tor."""
|
||||
result = diagnose_url(url, kind=kind, wrapper='torsocks')
|
||||
result.check_id = 'torproxy-url'
|
||||
result.description = _('Access URL {url} on tcp{kind} via Tor') \
|
||||
.format(url=url, kind=kind)
|
||||
result.description = gettext_noop('Access URL {url} on tcp{kind} via Tor')
|
||||
|
||||
return result
|
||||
|
||||
@@ -148,7 +148,7 @@ def _diagnose_tor_use(url, kind=None):
|
||||
result = diagnose_url(url, kind=kind, wrapper='torsocks',
|
||||
expected_output=expected_output)
|
||||
result.check_id = 'torproxy-using-tor'
|
||||
result.description = _('Confirm Tor usage at {url} on tcp{kind}') \
|
||||
.format(url=url, kind=kind)
|
||||
result.description = gettext_noop(
|
||||
'Confirm Tor usage at {url} on tcp{kind}')
|
||||
|
||||
return result
|
||||
@@ -7,6 +7,7 @@ import subprocess
|
||||
import augeas
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import app as app_module
|
||||
from plinth import cfg, menu
|
||||
@@ -123,8 +124,7 @@ def _diagnose_ldap_entry(search_item):
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
template = _('Check LDAP entry "{search_item}"')
|
||||
description = format_lazy(template, search_item=search_item)
|
||||
description = gettext_noop('Check LDAP entry "{search_item}"')
|
||||
parameters = {'search_item': search_item}
|
||||
|
||||
return DiagnosticCheck(check_id, description, result, parameters)
|
||||
@@ -138,8 +138,7 @@ def _diagnose_nslcd_config(config, key, value):
|
||||
except KeyError:
|
||||
result = Result.FAILED
|
||||
|
||||
template = _('Check nslcd config "{key} {value}"')
|
||||
description = format_lazy(template, key=key, value=value)
|
||||
description = gettext_noop('Check nslcd config "{key} {value}"')
|
||||
parameters = {'key': key, 'value': value}
|
||||
|
||||
return DiagnosticCheck(check_id, description, result, parameters)
|
||||
@@ -169,8 +168,7 @@ def _diagnose_nsswitch_config():
|
||||
|
||||
break
|
||||
|
||||
template = _('Check nsswitch config "{database}"')
|
||||
description = format_lazy(template, database=database)
|
||||
description = gettext_noop('Check nsswitch config "{database}"')
|
||||
parameters = {'database': database}
|
||||
|
||||
results.append(
|
||||
|
||||
Reference in new issue
Block a user