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 bugs in email registraton + objects API prefill combination #4977

Merged
merged 3 commits into from
Dec 31, 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
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
Loading