Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4298] Broken admin links and certificate label in email digest #4317

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 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 12:22+0200\n"
"POT-Creation-Date: 2024-05-23 10:18+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 @@ -2187,36 +2187,36 @@ msgstr "Lijst van beschikbare stijlen"
msgid "Retrieve theme details"
msgstr "Stijldetails weergeven"

#: openforms/config/checks.py:54
#: openforms/config/checks.py:56
msgid "Address lookup plugins"
msgstr "Adresopzoekplugins"

#: openforms/config/checks.py:67
#: openforms/config/checks.py:69
msgid "Validator plugins"
msgstr "Validatieplugins"

#: openforms/config/checks.py:78
#: openforms/config/checks.py:80
msgid "Appointment plugins"
msgstr "Afspraakplugins"

#: openforms/config/checks.py:79
#: openforms/config/checks.py:81
msgid "Registration plugins"
msgstr "Registratieplugins"

#: openforms/config/checks.py:80
#: openforms/config/checks.py:82
#: openforms/emails/templates/emails/admin_digest.html:46
msgid "Prefill plugins"
msgstr "Prefillplugins"

#: openforms/config/checks.py:81
#: openforms/config/checks.py:83
msgid "Payment plugins"
msgstr "Betaalproviderplugins"

#: openforms/config/checks.py:82
#: openforms/config/checks.py:84
msgid "DMN plugins"
msgstr "DMN plugins"

#: openforms/config/checks.py:126
#: openforms/config/checks.py:130
#, python-brace-format
msgid "Internal error: {exception}"
msgstr "Interne fout: {exception}"
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
24 changes: 16 additions & 8 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,12 @@ class InvalidCertificate:

@property
def admin_link(self) -> str:
form_admin_url = reverse(
form_relative_admin_url = reverse(
"admin:simple_certmanager_certificate_change",
kwargs={"object_id": self.id},
)
return form_admin_url

return build_absolute_uri(form_relative_admin_url)


@dataclass
Expand All @@ -113,10 +117,10 @@ class InvalidRegistrationBackend:

@property
def admin_link(self) -> str:
form_admin_url = reverse(
form_relative_admin_url = reverse(
"admin:forms_form_change", kwargs={"object_id": self.form_id}
)
return form_admin_url
return build_absolute_uri(form_relative_admin_url)


@dataclass
Expand All @@ -127,7 +131,11 @@ class InvalidLogicRule:

@property
def admin_link(self) -> str:
return reverse("admin:forms_form_change", kwargs={"object_id": self.form_id})
form_relative_admin_url = reverse(
"admin:forms_form_change", kwargs={"object_id": self.form_id}
)

return build_absolute_uri(form_relative_admin_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=str(cert),
error_message=error_message,
is_valid_pair=is_valid_pair,
expiry_date=cert.expiry_date,
Expand Down
38 changes: 23 additions & 15 deletions src/openforms/emails/tests/test_tasks_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test_no_email_sent_if_no_recipients(self, mock_global_config):
return_value=BRKConfig(service=None),
)
@freeze_time("2023-01-03T01:00:00+01:00")
@override_settings(BASE_URL="http://testserver")
def test_email_sent_when_there_are_failures(self, mock_global_config, brk_config):
"""Integration test for all the possible failures
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 = furl(
f"http://testserver{admin_relative_submissions_url.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 = furl(f"http://testserver{admin_relative_logs_url.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,21 @@ def test_email_sent_when_there_are_failures(self, mock_global_config, brk_config
)

with self.subTest("invalid certificates"):
admin_certificate_url = furl(
reverse(
"admin:simple_certmanager_certificate_change",
kwargs={"object_id": certificate.id},
)
admin_relative_certificate_url = reverse(
"admin:simple_certmanager_certificate_change",
kwargs={"object_id": certificate.id},
)
admin_certificate_url = f"http://testserver{admin_relative_certificate_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 = f"http://testserver{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)
Loading