Skip to content

Commit

Permalink
[#3725] PR feedback-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed Apr 17, 2024
1 parent 7727b35 commit c22d0d9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 47 deletions.
40 changes: 0 additions & 40 deletions src/openforms/config/service.py

This file was deleted.

16 changes: 16 additions & 0 deletions src/openforms/contrib/brk/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from openforms.forms.models.form import Form
from openforms.plugins.exceptions import InvalidPluginConfiguration

from .checks import BRKValidatorCheck


def check_brk_config_for_addressNL() -> str:
live_forms = Form.objects.live()

if any(form.has_component("addressNL") for form in live_forms):
try:
BRKValidatorCheck.check_config()
except InvalidPluginConfiguration as e:
return e.args[0]

return ""
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from django_yubin.models import Message
from furl import furl

from openforms.contrib.brk.service import check_brk_config_for_addressNL
from openforms.logging.models import TimelineLogProxy
from openforms.submissions.models.submission import Submission
from openforms.submissions.utils import get_filtered_submission_admin_url
from openforms.typing import StrOrPromise


@dataclass
Expand Down Expand Up @@ -60,6 +63,12 @@ def failed_submissions_counter(self) -> int:
return len(self.submission_ids)


@dataclass
class BrokenConfiguration:
config_name: StrOrPromise
exception_message: str


def collect_failed_emails(since: datetime) -> Iterable[FailedEmail]:
logs = TimelineLogProxy.objects.filter(
timestamp__gt=since,
Expand Down Expand Up @@ -156,3 +165,17 @@ def collect_failed_prefill_plugins(since: datetime) -> list[FailedPrefill]:
)

return failed_prefill_plugins


def collect_broken_configurations() -> list[BrokenConfiguration]:
check_brk_configuration = check_brk_config_for_addressNL()

broken_configurations = []
if check_brk_configuration:
broken_configurations.append(
BrokenConfiguration(
config_name=_("BRK Client"), exception_message=check_brk_configuration
)
)

return broken_configurations
6 changes: 3 additions & 3 deletions src/openforms/emails/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

from openforms.celery import app
from openforms.config.models import GlobalConfiguration
from openforms.config.service import collect_broken_configurations
from openforms.logging.service import (

from .digest import (
collect_broken_configurations,
collect_failed_emails,
collect_failed_prefill_plugins,
collect_failed_registrations,
)

from .utils import send_mail_html


Expand Down
4 changes: 2 additions & 2 deletions src/openforms/emails/templates/emails/admin_digest.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ <h5>{% trans "Prefill plugins" %}</h5>
{% endif %}

{% if broken_configurations %}
<h5>{% trans "Broken configuration" %}</h5>
<h5>{% trans "Configuration problems" %}</h5>
<ul>
{% for config in broken_configurations %}
<li>
{% blocktranslate with name=config.config_name message=config.exception_message trimmed %}
Configuration for '{{ name }}' is broken (<i>{{ message }}</i>).<br/>
The configuration for '{{ name }}' is invalid (<i>{{ message }}</i>).<br/>
Components or plugins which make use of this will not work properly.
{% endblocktranslate %}
</li>
Expand Down
8 changes: 6 additions & 2 deletions src/openforms/emails/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ def test_broken_brk_configuration_for_addressNL_is_sent(self):
self.assertEqual(sent_email.recipients(), ["[email protected]"])
self.assertIn(
_(
"Configuration for 'BRK Client' is broken (KVK endpoint is not configured)."
"The configuration for 'BRK Client' is invalid (KVK endpoint is not configured)."
),
sent_email.body,
)

def test_no_email_sent_when_brk_congiguration_is_valid_for_other_component(self):
def test_no_email_sent_when_brk_congiguration_is_invalid_but_unused(self):
form = FormFactory.create()
form_definition = FormDefinitionFactory.create(
configuration={
Expand All @@ -390,6 +390,10 @@ def test_no_email_sent_when_brk_congiguration_is_valid_for_other_component(self)
recipients_email_digest=["[email protected]"]
),
),
patch(
"openforms.contrib.brk.client.BRKConfig.get_solo",
return_value=BRKConfig(service=None),
),
):

send_email_digest()
Expand Down

0 comments on commit c22d0d9

Please sign in to comment.