Skip to content

Commit

Permalink
♻️ Rename existing logic rule check
Browse files Browse the repository at this point in the history
DMN action checks are also logic rule checks, so the collector function
and context variables are renamed to better cover what they actually
detect.
  • Loading branch information
sergei-maertens committed Jun 18, 2024
1 parent 2a17891 commit b946c10
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/openforms/emails/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def admin_link(self) -> str:


@dataclass
class InvalidLogicRule:
class InvalidLogicVariable:
variable: str
form_name: str
form_id: int
Expand Down Expand Up @@ -366,7 +366,7 @@ def collect_invalid_registration_backends() -> list[InvalidRegistrationBackend]:
return invalid_registration_backends


def collect_invalid_logic_rules() -> list[InvalidLogicRule]:
def collect_invalid_logic_variables() -> list[InvalidLogicVariable]:
forms = Form.objects.live().iterator()
static_variables = {
var.key: {"source": var.source, "type": var.data_type}
Expand Down Expand Up @@ -409,7 +409,7 @@ def collect_invalid_logic_rules() -> list[InvalidLogicRule]:

def _report():
invalid_logic_rules.append(
InvalidLogicRule(
InvalidLogicVariable(
variable=var.key,
form_name=form.admin_name,
form_id=form.id,
Expand Down
6 changes: 3 additions & 3 deletions src/openforms/emails/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
collect_failed_prefill_plugins,
collect_failed_registrations,
collect_invalid_certificates,
collect_invalid_logic_rules,
collect_invalid_logic_variables,
collect_invalid_registration_backends,
)
from .utils import send_mail_html
Expand All @@ -32,7 +32,7 @@ def get_context_data(self) -> dict[str, Any]:
broken_configurations = collect_broken_configurations()
invalid_certificates = collect_invalid_certificates()
invalid_registration_backends = collect_invalid_registration_backends()
invalid_logic_rules = collect_invalid_logic_rules()
invalid_logic_variables = collect_invalid_logic_variables()

return {
"failed_emails": failed_emails,
Expand All @@ -41,7 +41,7 @@ def get_context_data(self) -> dict[str, Any]:
"broken_configurations": broken_configurations,
"invalid_certificates": invalid_certificates,
"invalid_registration_backends": invalid_registration_backends,
"invalid_logic_rules": invalid_logic_rules,
"invalid_logic_variables": invalid_logic_variables,
}

def render(self) -> str:
Expand Down
10 changes: 4 additions & 6 deletions src/openforms/emails/templates/emails/admin_digest.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ <h5>{% trans "Found invalid certificates" %}</h5>
{% if invalid_registration_backends %}
<h5>{% trans "Registration backends problems" %}</h5>
<ul>
<ul>
{% for failed_backend in invalid_registration_backends %}
<li>
<p>
Expand All @@ -130,18 +129,17 @@ <h5>{% trans "Registration backends problems" %}</h5>
</ul>
{% endif %}

{% if invalid_logic_rules %}
{% if invalid_logic_variables %}
<h5>{% trans "Logic rules problems" %}</h5>
<ul>
<ul>
{% for logic_rule in invalid_logic_rules %}
{% for problem in invalid_logic_variables %}
<li>
<p>
{% blocktranslate with var=logic_rule.variable form_name=logic_rule.form_name trimmed %}
{% blocktranslate with var=problem.variable form_name=problem.form_name trimmed %}
Logic rule for variable '{{ var }}' is invalid in form '{{ form_name }}'.<br>
{% endblocktranslate %}
</p>
<p><a href="{{ logic_rule.admin_link }}">{% trans "View form" %}</a></p>
<p><a href="{{ problem.admin_link }}">{% trans "View form" %}</a></p>
</li>
{% endfor %}
</ul>
Expand Down
28 changes: 15 additions & 13 deletions src/openforms/emails/tests/test_digest_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
from stuf.stuf_bg.client import NoServiceConfigured

from ..digest import (
InvalidLogicRule,
InvalidLogicVariable,
collect_broken_configurations,
collect_failed_emails,
collect_failed_prefill_plugins,
collect_failed_registrations,
collect_invalid_certificates,
collect_invalid_logic_rules,
collect_invalid_logic_variables,
collect_invalid_registration_backends,
)
from ..tasks import Digest
Expand Down Expand Up @@ -678,7 +678,7 @@ def test_valid_logic_rules_are_not_collected_and_not_logged(self):
json_logic_trigger={"==": [{"var": "foo"}, "apple"]},
)

invalid_logic_rules = collect_invalid_logic_rules()
invalid_logic_rules = collect_invalid_logic_variables()

logs_exist = TimelineLogProxy.objects.exists()

Expand Down Expand Up @@ -714,7 +714,7 @@ def test_invalid_logic_rules_with_nested_key_are_only_logged(self):
)

with self.assertLogs() as logs:
collect_invalid_logic_rules()
collect_invalid_logic_variables()

logs_messages = [log.getMessage() for log in logs.records]

Expand Down Expand Up @@ -773,51 +773,53 @@ def test_invalid_logic_rules_are_collected_and_not_logged(self):
)

with self.assertNoLogs():
invalid_logic_rules = collect_invalid_logic_rules()
invalid_logic_rules = collect_invalid_logic_variables()

self.assertEqual(len(invalid_logic_rules), 8)
self.assertIn(
InvalidLogicRule(
InvalidLogicVariable(
variable="temp", form_name=form.admin_name, form_id=form.id
),
invalid_logic_rules,
)
self.assertIn(
InvalidLogicRule(
InvalidLogicVariable(
variable="fooStr.nested", form_name=form.admin_name, form_id=form.id
),
invalid_logic_rules,
)
self.assertIn(
InvalidLogicRule(
InvalidLogicVariable(
variable="fooArray.bar", form_name=form.admin_name, form_id=form.id
),
invalid_logic_rules,
)
self.assertIn(
InvalidLogicRule(
InvalidLogicVariable(
variable="foo.wrong", form_name=form.admin_name, form_id=form.id
),
invalid_logic_rules,
)
self.assertIn(
InvalidLogicRule(
InvalidLogicVariable(
variable="temp.0.other", form_name=form.admin_name, form_id=form.id
),
invalid_logic_rules,
)
self.assertIn(
InvalidLogicRule(
InvalidLogicVariable(
variable="another", form_name=form.admin_name, form_id=form.id
),
invalid_logic_rules,
)
self.assertIn(
InvalidLogicRule(variable="", form_name=form.admin_name, form_id=form.id),
InvalidLogicVariable(
variable="", form_name=form.admin_name, form_id=form.id
),
invalid_logic_rules,
)
self.assertIn(
InvalidLogicRule(
InvalidLogicVariable(
variable="pie.filling", form_name=form.admin_name, form_id=form.id
),
invalid_logic_rules,
Expand Down

0 comments on commit b946c10

Please sign in to comment.