From 71dec0e5ea95d2f6f584d9cd4c3254284281e5f8 Mon Sep 17 00:00:00 2001 From: vasileios Date: Wed, 22 May 2024 12:23:42 +0200 Subject: [PATCH] [#4298] Made admin links absolute, fixed missing labels in certificates --- .../conf/locale/nl/LC_MESSAGES/django.po | 18 +++++----- src/openforms/emails/digest.py | 30 ++++++++++------ .../emails/tests/test_tasks_integration.py | 34 +++++++++++++------ src/openforms/submissions/utils.py | 9 +++-- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/src/openforms/conf/locale/nl/LC_MESSAGES/django.po b/src/openforms/conf/locale/nl/LC_MESSAGES/django.po index 38c5e2e40a..cb250f07a0 100644 --- a/src/openforms/conf/locale/nl/LC_MESSAGES/django.po +++ b/src/openforms/conf/locale/nl/LC_MESSAGES/django.po @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Open Forms\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-05-22 10:57+0200\n" +"POT-Creation-Date: 2024-05-22 12:23+0200\n" "PO-Revision-Date: 2024-05-17 15:22+0200\n" "Last-Translator: Sergei Maertens \n" "Language-Team: Dutch \n" @@ -3824,29 +3824,29 @@ msgstr "Bevestiging" msgid "Co-sign confirmation" msgstr "Mede-ondertekeningbevestiging" -#: openforms/emails/digest.py:239 +#: openforms/emails/digest.py:247 msgid "BRK Client" msgstr "BRK client" -#: openforms/emails/digest.py:246 +#: openforms/emails/digest.py:254 #, fuzzy #| msgid "BRK Client" msgid "BAG Client" msgstr "BRK client" -#: openforms/emails/digest.py:256 +#: openforms/emails/digest.py:264 msgid "will expire soon" msgstr "" -#: openforms/emails/digest.py:257 +#: openforms/emails/digest.py:265 msgid "has invalid keypair" msgstr "" -#: openforms/emails/digest.py:258 +#: openforms/emails/digest.py:266 msgid "invalid keypair, will expire soon" msgstr "" -#: openforms/emails/digest.py:351 +#: openforms/emails/digest.py:359 #, fuzzy #| msgid "Email registration configuration" msgid "Invalid registration backend configuration detected" @@ -8303,8 +8303,8 @@ msgid "" "The co-sign component requires the '{field_label}' ({config_verbose_name}) " "to be configured." msgstr "" -"Het mede-ondertekencomponent vereist de configuratie van '{field_label}' " -"({config_verbose_name})." +"Het mede-ondertekencomponent vereist de configuratie van " +"'{field_label}' ({config_verbose_name})." #: openforms/products/api/viewsets.py:15 msgid "Retrieve details of a single product" diff --git a/src/openforms/emails/digest.py b/src/openforms/emails/digest.py index 65100e2f9a..31f70cbeb0 100644 --- a/src/openforms/emails/digest.py +++ b/src/openforms/emails/digest.py @@ -30,6 +30,7 @@ from openforms.typing import StrOrPromise from openforms.utils.json_logic.datastructures import InputVar from openforms.utils.json_logic.introspection import introspect_json_logic +from openforms.utils.urls import build_absolute_uri from openforms.variables.constants import FormVariableDataTypes from openforms.variables.service import get_static_variables @@ -71,10 +72,12 @@ def admin_link(self) -> str: "object_id__in": ",".join(self.submission_ids), "extra_data__log_event__in": "prefill_retrieve_empty,prefill_retrieve_failure", } - submissions_admin_url = furl( + submissions_relative_admin_url = furl( reverse("admin:logging_timelinelogproxy_changelist") ) - return submissions_admin_url.add(query_params).url + submissions_relative_admin_url.add(query_params) + + return build_absolute_uri(submissions_relative_admin_url.url) @property def failed_submissions_counter(self) -> int: @@ -97,11 +100,13 @@ class InvalidCertificate: @property def admin_link(self) -> str: - form_admin_url = reverse( - "admin:simple_certmanager_certificate_change", - kwargs={"object_id": self.id}, + form_relative_admin_url = furl( + reverse( + "admin:simple_certmanager_certificate_change", + kwargs={"object_id": self.id}, + ) ) - return form_admin_url + return build_absolute_uri(form_relative_admin_url.url) @dataclass @@ -113,10 +118,10 @@ class InvalidRegistrationBackend: @property def admin_link(self) -> str: - form_admin_url = reverse( - "admin:forms_form_change", kwargs={"object_id": self.form_id} + form_relative_admin_url = furl( + reverse("admin:forms_form_change", kwargs={"object_id": self.form_id}) ) - return form_admin_url + return build_absolute_uri(form_relative_admin_url.url) @dataclass @@ -127,7 +132,10 @@ class InvalidLogicRule: @property def admin_link(self) -> str: - return reverse("admin:forms_form_change", kwargs={"object_id": self.form_id}) + form_relative_admin_url = furl( + reverse("admin:forms_form_change", kwargs={"object_id": self.form_id}) + ) + return build_absolute_uri(form_relative_admin_url.url) def collect_failed_emails(since: datetime) -> Iterable[FailedEmail]: @@ -289,7 +297,7 @@ def collect_invalid_certificates() -> list[InvalidCertificate]: invalid_certs.append( InvalidCertificate( id=cert.id, - label=cert.label, + label=cert.__str__(), error_message=error_message, is_valid_pair=is_valid_pair, expiry_date=cert.expiry_date, diff --git a/src/openforms/emails/tests/test_tasks_integration.py b/src/openforms/emails/tests/test_tasks_integration.py index 14b145e43b..b9b84186f3 100644 --- a/src/openforms/emails/tests/test_tasks_integration.py +++ b/src/openforms/emails/tests/test_tasks_integration.py @@ -29,6 +29,7 @@ from openforms.submissions.constants import RegistrationStatuses from openforms.submissions.models.submission import Submission from openforms.submissions.tests.factories import SubmissionFactory +from openforms.utils.urls import build_absolute_uri from ..tasks import send_email_digest @@ -187,7 +188,7 @@ def test_email_sent_when_there_are_failures(self, mock_global_config, brk_config open(TEST_FILES / "test.key", "r") as key_f, ): certificate = CertificateFactory.create( - label="Test certificate", + label="", public_certificate=File( client_certificate_f, name="test.certificate" ), @@ -207,35 +208,41 @@ def test_email_sent_when_there_are_failures(self, mock_global_config, brk_config ) with self.subTest("failed registration"): - admin_submissions_url = furl( + admin_relative_submissions_url = furl( reverse("admin:submissions_submission_changelist") ) - admin_submissions_url.args = { + admin_relative_submissions_url.args = { "form__id__exact": form.id, "needs_on_completion_retry__exact": 1, "registration_time": "24hAgo", } + admin_submissions_url = build_absolute_uri( + admin_relative_submissions_url.url + ) self.assertIn( f"Form '{form.admin_name}' failed 1 time(s) between 12:30 p.m. and 12:30 p.m..", sent_email.body, ) - self.assertIn(admin_submissions_url.url, sent_email.body) + self.assertIn(admin_submissions_url, sent_email.body) with self.subTest("failed prefill plugin"): content_type = ContentType.objects.get_for_model(Submission).id - admin_logs_url = furl(reverse("admin:logging_timelinelogproxy_changelist")) - admin_logs_url.args = { + admin_relative_logs_url = furl( + reverse("admin:logging_timelinelogproxy_changelist") + ) + admin_relative_logs_url.args = { "content_type": content_type, "object_id__in": submission.id, "extra_data__log_event__in": "prefill_retrieve_empty,prefill_retrieve_failure", } + admin_logs_url = build_absolute_uri(admin_relative_logs_url.url) self.assertIn( f"'{hc_plugin.verbose_name}' plugin has failed 1 time(s) between 12:30 p.m. and 12:30 p.m.", sent_email.body, ) - self.assertIn(admin_logs_url.url, sent_email.body) + self.assertIn(admin_logs_url, sent_email.body) with self.subTest("broken configuration"): self.assertIn( @@ -244,20 +251,25 @@ def test_email_sent_when_there_are_failures(self, mock_global_config, brk_config ) with self.subTest("invalid certificates"): - admin_certificate_url = furl( + admin_relative_certificate_url = furl( reverse( "admin:simple_certmanager_certificate_change", kwargs={"object_id": certificate.id}, ) ) + admin_certificate_url = build_absolute_uri( + admin_relative_certificate_url.url + ) - self.assertIn("Test certificate: has invalid keypair.", sent_email.body) - self.assertIn(admin_certificate_url.url, sent_email.body) + self.assertIn("(missing label): has invalid keypair.", sent_email.body) + self.assertIn(admin_certificate_url, sent_email.body) with self.subTest("invalid registration backends"): - admin_form_url = reverse( + admin_relative_form_url = reverse( "admin:forms_form_change", kwargs={"object_id": form.id} ) + admin_form_url = build_absolute_uri(admin_relative_form_url) + self.assertIn( f"The configuration for plugin '{InvalidBackend.verbose_name}' is invalid.", sent_email.body, diff --git a/src/openforms/submissions/utils.py b/src/openforms/submissions/utils.py index a6fc0b2004..7f177625f4 100644 --- a/src/openforms/submissions/utils.py +++ b/src/openforms/submissions/utils.py @@ -25,6 +25,7 @@ ) from openforms.forms.models import Form from openforms.logging import logevent +from openforms.utils.urls import build_absolute_uri from openforms.variables.constants import FormVariableSources from .constants import SUBMISSIONS_SESSION_KEY, UPLOADS_SESSION_KEY @@ -346,5 +347,9 @@ def get_filtered_submission_admin_url( "needs_on_completion_retry__exact": 1 if filter_retry else 0, "registration_time": registration_time, } - submissions_admin_url = furl(reverse("admin:submissions_submission_changelist")) - return submissions_admin_url.add(query_params).url + submissions_relative_admin_url = furl( + reverse("admin:submissions_submission_changelist") + ) + submissions_relative_admin_url.add(query_params) + + return build_absolute_uri(submissions_relative_admin_url.url)