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

Fix incorrect detection of cosign being required blocking the registration #4889

Merged
merged 2 commits into from
Dec 10, 2024
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
17 changes: 17 additions & 0 deletions src/openforms/submissions/cosigning.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,30 @@ def _find_component(self) -> Component | None:
"""
Discover the Formio cosign component in the submission/form.
"""
from .form_logic import check_submission_logic
from .logic.datastructures import DataContainer

check_submission_logic(self.submission)

# use the complete view on the Formio component tree(s)
configuration_wrapper = self.submission.total_configuration_wrapper

# there should only be one cosign component, so we check our flatmap to find the
# component.
for component in configuration_wrapper.component_map.values():
if component["type"] == "cosign":
# we can't just blindly return the component, as it may be conditionally
# displayed, which is equivalent to "cosign not relevant". See
# https://github.com/open-formulieren/open-forms/issues/3901
container = DataContainer(
self.submission.load_submission_value_variables_state()
)
visible = configuration_wrapper.is_visible_in_frontend(
component["key"],
values=container.data,
)
if not visible:
return None
return component
return None

Expand Down
86 changes: 84 additions & 2 deletions src/openforms/submissions/tests/test_post_submission_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from openforms.authentication.service import AuthAttribute
from openforms.config.models import GlobalConfiguration
from openforms.emails.tests.factories import ConfirmationEmailTemplateFactory
from openforms.forms.tests.factories import FormDefinitionFactory
from openforms.forms.constants import LogicActionTypes, PropertyTypes
from openforms.forms.tests.factories import FormDefinitionFactory, FormLogicFactory
from openforms.payments.constants import PaymentStatus
from openforms.payments.tests.factories import SubmissionPaymentFactory
from openforms.registrations.base import PreRegistrationResult
Expand All @@ -24,7 +25,7 @@
)
from openforms.utils.tests.logging import ensure_logger_level

from ..constants import PostSubmissionEvents
from ..constants import PostSubmissionEvents, RegistrationStatuses
from ..models import SubmissionReport
from ..tasks import on_post_submission_event
from .factories import SubmissionFactory
Expand Down Expand Up @@ -996,6 +997,87 @@ def test_cosign_not_required_but_filled_in_does_not_proceed_with_registration(se
self.assertTrue(submission.confirmation_email_sent)
self.assertEqual(submission.auth_info.value, "111222333")

@tag("gh-3901", "hlmr-86")
def test_cosign_required_but_hidden_proceeds_with_registration(self):
"""
A conditionally hidden cosign component may not block registration.
"""
submission = SubmissionFactory.from_components(
components_list=[
{
"key": "cosign",
"type": "cosign",
"label": "Cosign component",
"validate": {"required": True},
"hidden": True,
},
],
submitted_data={"cosign": ""},
completed=True,
cosign_complete=False,
form__registration_backend="email",
form__registration_backend_options={"to_emails": ["[email protected]"]},
auth_info__attribute=AuthAttribute.bsn,
auth_info__value="111222333",
language_code="en",
)
assert submission.registration_status == RegistrationStatuses.pending

on_post_submission_event(submission.pk, PostSubmissionEvents.on_completion)

submission.refresh_from_db()
self.assertEqual(submission.registration_status, RegistrationStatuses.success)

@tag("gh-3901", "hlmr-86")
def test_cosign_required_and_visible_via_logic_does_not_proceed_with_registration(
self,
):
"""
A conditionally displayed cosign component must block registration.
"""
submission = SubmissionFactory.from_components(
components_list=[
{
"key": "cosign",
"type": "cosign",
"label": "Cosign component",
"validate": {"required": True},
"hidden": True,
},
],
submitted_data={"cosign": ""},
completed=True,
cosign_complete=False,
form__registration_backend="email",
form__registration_backend_options={"to_emails": ["[email protected]"]},
auth_info__attribute=AuthAttribute.bsn,
auth_info__value="111222333",
language_code="en",
)
FormLogicFactory.create(
form=submission.form,
json_logic_trigger=True,
actions=[
{
"action": {
"type": LogicActionTypes.property,
"property": {
"type": PropertyTypes.bool,
"value": "hidden",
},
"state": False,
},
"component": "cosign",
}
],
)
assert submission.registration_status == RegistrationStatuses.pending

on_post_submission_event(submission.pk, PostSubmissionEvents.on_completion)

submission.refresh_from_db()
self.assertEqual(submission.registration_status, RegistrationStatuses.pending)

@tag("gh-3924")
def test_payment_complete_does_not_set_retry_flag(self):
submission = SubmissionFactory.create(
Expand Down
Loading