Skip to content

Commit

Permalink
🩺 [#4284] Add DMN plugin config check to digest email
Browse files Browse the repository at this point in the history
Detect which DMN plugins are enabled and used in (live) forms, and
run the config check for them. If problems are detected, they will
be reported in the digest email.
  • Loading branch information
sergei-maertens committed Jun 18, 2024
1 parent 43a32dc commit 76d5fd9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/openforms/emails/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

from openforms.contrib.brk.service import check_brk_config_for_addressNL
from openforms.contrib.kadaster.service import check_bag_config_for_address_fields
from openforms.dmn.registry import register as dmn_register
from openforms.forms.constants import LogicActionTypes
from openforms.forms.models import Form
from openforms.forms.models.form import FormQuerySet
from openforms.forms.models.form_registration_backend import FormRegistrationBackend
from openforms.forms.models.logic import FormLogic
from openforms.logging.models import TimelineLogProxy
Expand Down Expand Up @@ -255,6 +257,22 @@ def collect_broken_configurations() -> list[BrokenConfiguration]:
)
)

# check DMN usage for each plugin and if used, validate the plugin config
for plugin in dmn_register.iter_enabled_plugins():
has_forms = _get_forms_with_dmn_action(plugin.identifier).exists()
if not has_forms:
continue

try:
plugin.check_config()
except InvalidPluginConfiguration as exc:
broken_configurations.append(
BrokenConfiguration(
config_name=_("{plugin} (DMN)").format(plugin=plugin.verbose_name),
exception_message=exc.message,
)
)

return broken_configurations


Expand Down Expand Up @@ -456,3 +474,21 @@ def _report():
)

return invalid_logic_rules


def _get_forms_with_dmn_action(plugin_id: str) -> FormQuerySet:
# actions is a JSONField - the top-level is an array of actions. Each action is
# an object with the shape openforms.submissions.logic.actions.ActionDict. The
# JSONField query does not fully specify all properties because it performs
# structural matching (and we only process the rest of the config after establishing
# that it is indeed the expected action type).
lookup_value = [
{
"action": {
"type": LogicActionTypes.evaluate_dmn,
"config": {"plugin_id": plugin_id},
}
}
]
base_qs = Form.objects.live().distinct()
return base_qs.filter(formlogic__actions__contains=lookup_value)

0 comments on commit 76d5fd9

Please sign in to comment.