Skip to content

Commit

Permalink
[#4298] Made admin links absolute, fixed missing labels in certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed May 22, 2024
1 parent c38add7 commit 71dec0e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 33 deletions.
18 changes: 9 additions & 9 deletions src/openforms/conf/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sergei+local@maykinmedia.nl>\n"
"Language-Team: Dutch <support@maykinmedia.nl>\n"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
30 changes: 19 additions & 11 deletions src/openforms/emails/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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]:
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 23 additions & 11 deletions src/openforms/emails/tests/test_tasks_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
),
Expand All @@ -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(
Expand All @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions src/openforms/submissions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 71dec0e

Please sign in to comment.