Skip to content

Commit

Permalink
Merge pull request #4977 from open-formulieren/issue/4650-fix-bugs
Browse files Browse the repository at this point in the history
Fix bugs in email registraton + objects API prefill combination
  • Loading branch information
sergei-maertens authored Dec 31, 2024
2 parents 2d36304 + 991e466 commit 4a72d18
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
{% extends 'ui/views/abstract/detail.html' %}
{% load i18n static %}

{% block extra_css %}
{{ block.super }}

{# Needed for the styling of the auth-mode class #}
<link href="{% static 'bundles/public-styles.css' %}" media="all" rel="stylesheet"/>
{% endblock %}

{% block card %}
<div class="openforms-card">
<header class="openforms-card__header">
Expand Down
8 changes: 8 additions & 0 deletions src/openforms/registrations/contrib/email/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class EmailRegistration(BasePlugin[Options]):
verbose_name = _("Email registration")
configuration_options = EmailOptionsSerializer

def verify_initial_data_ownership(
self, submission: Submission, options: Options
) -> None:
"""
Ownership checks for email registration are not meaningful, allow anything.
"""
pass

@staticmethod
def get_recipients(submission: Submission, options: Options) -> list[str]:
state = submission.load_submission_value_variables_state()
Expand Down
32 changes: 31 additions & 1 deletion src/openforms/registrations/contrib/email/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from openforms.payments.constants import PaymentStatus
from openforms.payments.tests.factories import SubmissionPaymentFactory
from openforms.submissions.attachments import attach_uploads_to_submission_step
from openforms.submissions.constants import PostSubmissionEvents
from openforms.submissions.exports import create_submission_export
from openforms.submissions.models import Submission
from openforms.submissions.tests.factories import (
Expand All @@ -34,7 +35,8 @@
from openforms.utils.tests.html_assert import HTMLAssertMixin
from openforms.variables.constants import FormVariableSources

from ..constants import AttachmentFormat
from ....tasks import pre_registration
from ..constants import PLUGIN_ID, AttachmentFormat
from ..models import EmailConfig
from ..plugin import EmailRegistration, Options

Expand Down Expand Up @@ -1281,3 +1283,31 @@ def test_with_deferred_registration(self):
# Verify that email was sent
emails = mail.outbox
self.assertEqual(len(emails), 2)

@tag("gh-4650")
def test_register_submission_with_initial_data_reference(self):
"""
Test that submissions with initial data references can be registered.
For email, no access control checks can be performed and there is no 'update
existing object' mechanic, so any submission with some initial data reference
(for prefill, for example) needs to be accepted.
"""
email_form_options: Options = {
"to_emails": ["recipient@example.com"],
"attach_files_to_email": None,
}
submission = SubmissionFactory.from_data(
{"whatever": "156/Silence"},
completed_not_preregistered=True,
initial_data_reference="some-reference",
form__registration_backend=PLUGIN_ID,
form__registration_backend_options=email_form_options,
)

pre_registration(submission.pk, event=PostSubmissionEvents.on_completion)

submission.refresh_from_db()
self.assertFalse(submission.needs_on_completion_retry)
self.assertTrue(submission.pre_registration_completed)
self.assertNotEqual(submission.public_registration_reference, "")
2 changes: 1 addition & 1 deletion src/openforms/templates/includes/forms/radio.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
utrecht-form-fieldset__legend
utrecht-form-fieldset__legend--html-legend
utrecht-form-field__label">
<label class="utrecht-form-label utrecht-form-label--openforms-required">
<label class="utrecht-form-label utrecht-form-label--openforms utrecht-form-label--openforms-required">
{{ field.label }}
</label>
</legend>
Expand Down
2 changes: 2 additions & 0 deletions src/openforms/ui/static/ui/scss/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
@import 'page-header';

// Custom
@import '../../../../../scss/components/form-choices';

@import 'a11y-toolbar';
@import 'auth-mode';
@import 'fa-icon';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="utrecht-form-field utrecht-form-field--radio utrecht-form-field--openforms">
{% include "django/forms/widgets/input.html" %}
<p class="utrecht-paragraph utrecht-form-field__label utrecht-form-field__label--radio">
<label for="{{ widget.attrs.id }}" class="utrecht-form-label utrecht-form-label--radio">
<label for="{{ widget.attrs.id }}" class="utrecht-form-label utrecht-form-label--radio utrecht-form-label--openforms">
{{ widget.label }}
</label>
</p>
Expand Down

0 comments on commit 4a72d18

Please sign in to comment.