Skip to content

Commit

Permalink
💥 [#3283] Removing registration_backend from form
Browse files Browse the repository at this point in the history
The deprecated fields `registration_backend` and `registration_backend_options` have been removed. The field `registration_backends` should now be used in all situations.

These fields have also been removed from the import and export. This means, when you import a form using the `registration_backend` config, the registration will no longer be converted to `registration_backends`.
  • Loading branch information
robinmolen committed Dec 2, 2024
1 parent 0bda3f3 commit f519038
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 280 deletions.
7 changes: 7 additions & 0 deletions docs/installation/upgrade-300.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ StUF-ZDS payments extension conversion
The import conversion of StUF-ZDS plugin extensions, back to the default StUF-ZDS plugin,
has been removed. We recommend re-creating the exports on a newer version of Open Forms,
or manually changing the plugin to `stuf-zds-create-zaak` in the export files.

Removal of single registration conversion
-----------------------------------------

The legacy format (from before Open Forms 2.3) for registration backend will no longer be
converted to the current standard. When importing a form with this configuration,
the form will be created without registration backends.
30 changes: 4 additions & 26 deletions src/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1325,8 +1325,6 @@ paths:
- `internalName`
- `registrationBackends`
- `registrationBackend`
- `registrationBackendOptions`
- `authenticationBackendOptions`
- `paymentBackend`
- `paymentBackendOptions`
Expand Down Expand Up @@ -1399,8 +1397,6 @@ paths:
- `internalName`
- `registrationBackends`
- `registrationBackend`
- `registrationBackendOptions`
- `authenticationBackendOptions`
- `paymentBackend`
- `paymentBackendOptions`
Expand Down Expand Up @@ -1917,8 +1913,6 @@ paths:
- `internalName`
- `registrationBackends`
- `registrationBackend`
- `registrationBackendOptions`
- `authenticationBackendOptions`
- `paymentBackend`
- `paymentBackendOptions`
Expand Down Expand Up @@ -1997,8 +1991,6 @@ paths:
- `internalName`
- `registrationBackends`
- `registrationBackend`
- `registrationBackendOptions`
- `authenticationBackendOptions`
- `paymentBackend`
- `paymentBackendOptions`
Expand Down Expand Up @@ -2081,8 +2073,6 @@ paths:
- `internalName`
- `registrationBackends`
- `registrationBackend`
- `registrationBackendOptions`
- `authenticationBackendOptions`
- `paymentBackend`
- `paymentBackendOptions`
Expand Down Expand Up @@ -7564,7 +7554,7 @@ components:
Note that this schema is used for both non-admin users filling out forms and
admin users designing forms. The fields that are only relevant for admin users are:
`internalName`, `registrationBackends`, `registrationBackend`, `registrationBackendOptions`, `authenticationBackendOptions`, `paymentBackend`, `paymentBackendOptions`, `priceVariableKey`, `product`, `category`, `theme`, `activateOn`, `deactivateOn`, `isDeleted`, `submissionConfirmationTemplate`, `askPrivacyConsent`, `askStatementOfTruth`, `submissionsRemovalOptions`, `confirmationEmailTemplate`, `sendConfirmationEmail`, `displayMainWebsiteLink`, `includeConfirmationPageContentInPdf`, `translations`, `brpPersonenRequestOptions`.
`internalName`, `registrationBackends`, `authenticationBackendOptions`, `paymentBackend`, `paymentBackendOptions`, `priceVariableKey`, `product`, `category`, `theme`, `activateOn`, `deactivateOn`, `isDeleted`, `submissionConfirmationTemplate`, `askPrivacyConsent`, `askStatementOfTruth`, `submissionsRemovalOptions`, `confirmationEmailTemplate`, `sendConfirmationEmail`, `displayMainWebsiteLink`, `includeConfirmationPageContentInPdf`, `translations`, `brpPersonenRequestOptions`.
properties:
uuid:
type: string
Expand All @@ -7586,12 +7576,6 @@ components:
type: array
items:
$ref: '#/components/schemas/FormRegistrationBackend'
registrationBackend:
type: string
deprecated: true
registrationBackendOptions:
nullable: true
deprecated: true
authenticationBackends:
type: array
items:
Expand Down Expand Up @@ -8077,7 +8061,7 @@ components:
Note that this schema is used for both non-admin users filling out forms and
admin users designing forms. The fields that are only relevant for admin users are:
`internalName`, `registrationBackends`, `registrationBackend`, `registrationBackendOptions`, `authenticationBackendOptions`, `paymentBackend`, `paymentBackendOptions`, `priceVariableKey`, `product`, `category`, `theme`, `activateOn`, `deactivateOn`, `isDeleted`, `submissionConfirmationTemplate`, `askPrivacyConsent`, `askStatementOfTruth`, `submissionsRemovalOptions`, `confirmationEmailTemplate`, `sendConfirmationEmail`, `displayMainWebsiteLink`, `includeConfirmationPageContentInPdf`, `translations`, `brpPersonenRequestOptions`.
`internalName`, `registrationBackends`, `authenticationBackendOptions`, `paymentBackend`, `paymentBackendOptions`, `priceVariableKey`, `product`, `category`, `theme`, `activateOn`, `deactivateOn`, `isDeleted`, `submissionConfirmationTemplate`, `askPrivacyConsent`, `askStatementOfTruth`, `submissionsRemovalOptions`, `confirmationEmailTemplate`, `sendConfirmationEmail`, `displayMainWebsiteLink`, `includeConfirmationPageContentInPdf`, `translations`, `brpPersonenRequestOptions`.
properties:
name:
type: string
Expand Down Expand Up @@ -8248,7 +8232,7 @@ components:
Note that this schema is used for both non-admin users filling out forms and
admin users designing forms. The fields that are only relevant for admin users are:
`internalName`, `registrationBackends`, `registrationBackend`, `registrationBackendOptions`, `authenticationBackendOptions`, `paymentBackend`, `paymentBackendOptions`, `priceVariableKey`, `product`, `category`, `theme`, `activateOn`, `deactivateOn`, `isDeleted`, `submissionConfirmationTemplate`, `askPrivacyConsent`, `askStatementOfTruth`, `submissionsRemovalOptions`, `confirmationEmailTemplate`, `sendConfirmationEmail`, `displayMainWebsiteLink`, `includeConfirmationPageContentInPdf`, `translations`, `brpPersonenRequestOptions`.
`internalName`, `registrationBackends`, `authenticationBackendOptions`, `paymentBackend`, `paymentBackendOptions`, `priceVariableKey`, `product`, `category`, `theme`, `activateOn`, `deactivateOn`, `isDeleted`, `submissionConfirmationTemplate`, `askPrivacyConsent`, `askStatementOfTruth`, `submissionsRemovalOptions`, `confirmationEmailTemplate`, `sendConfirmationEmail`, `displayMainWebsiteLink`, `includeConfirmationPageContentInPdf`, `translations`, `brpPersonenRequestOptions`.
properties:
name:
type: string
Expand Down Expand Up @@ -9182,7 +9166,7 @@ components:
Note that this schema is used for both non-admin users filling out forms and
admin users designing forms. The fields that are only relevant for admin users are:
`internalName`, `registrationBackends`, `registrationBackend`, `registrationBackendOptions`, `authenticationBackendOptions`, `paymentBackend`, `paymentBackendOptions`, `priceVariableKey`, `product`, `category`, `theme`, `activateOn`, `deactivateOn`, `isDeleted`, `submissionConfirmationTemplate`, `askPrivacyConsent`, `askStatementOfTruth`, `submissionsRemovalOptions`, `confirmationEmailTemplate`, `sendConfirmationEmail`, `displayMainWebsiteLink`, `includeConfirmationPageContentInPdf`, `translations`, `brpPersonenRequestOptions`.
`internalName`, `registrationBackends`, `authenticationBackendOptions`, `paymentBackend`, `paymentBackendOptions`, `priceVariableKey`, `product`, `category`, `theme`, `activateOn`, `deactivateOn`, `isDeleted`, `submissionConfirmationTemplate`, `askPrivacyConsent`, `askStatementOfTruth`, `submissionsRemovalOptions`, `confirmationEmailTemplate`, `sendConfirmationEmail`, `displayMainWebsiteLink`, `includeConfirmationPageContentInPdf`, `translations`, `brpPersonenRequestOptions`.
properties:
uuid:
type: string
Expand All @@ -9204,12 +9188,6 @@ components:
type: array
items:
$ref: '#/components/schemas/FormRegistrationBackend'
registrationBackend:
type: string
deprecated: true
registrationBackendOptions:
nullable: true
deprecated: true
authenticationBackends:
type: array
items:
Expand Down
17 changes: 13 additions & 4 deletions src/openforms/fixtures/demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"name": "\u2615\ufe0f",
"slug": "koffie",
"active": true,
"product": null,
"registration_backend": "openforms.core.backends.console_backend"
"product": null
}
},
{
Expand All @@ -19,8 +18,18 @@
"name": "Demo multiple steps",
"slug": "demo-multiple-steps",
"active": true,
"product": null,
"registration_backend": ""
"product": null
}
},
{
"model": "forms.form_formregistrationbackend",
"pk": 1,
"fields": {
"key": "backend",
"name": "backend",
"backend": "openforms.core.backends.console_backend",
"options": {},
"form": 1
}
},
{
Expand Down
99 changes: 1 addition & 98 deletions src/openforms/forms/api/serializers/form.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import warnings

from django.db import transaction
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -100,8 +98,6 @@ def validate(self, attrs):

@extend_schema_serializer(
deprecate_fields=[
"registration_backend",
"registration_backend_options",
"cosign_login_info",
]
)
Expand Down Expand Up @@ -224,12 +220,6 @@ class FormSerializer(PublicFieldsSerializerMixin, serializers.ModelSerializer):

registration_backends = FormRegistrationBackendSerializer(many=True, required=False)

# deprecated fields
registration_backend = serializers.CharField(required=False, allow_blank=True)
registration_backend_options = serializers.JSONField(
required=False, allow_null=True
)

class Meta:
model = Form
fields = (
Expand All @@ -239,8 +229,6 @@ class Meta:
"login_required",
"translation_enabled",
"registration_backends",
"registration_backend",
"registration_backend_options",
"authentication_backends",
"authentication_backend_options",
"login_options",
Expand Down Expand Up @@ -342,26 +330,6 @@ def create(self, validated_data):
)
registration_backends = validated_data.pop("registration_backends", [])

registration_backend_options = (
validated_data.pop("registration_backend_options", None) or {}
)
if "registration_backend" in validated_data:
warnings.warn(
(
"Form 'registration_backend' and 'registration_backend_options' "
"are deprecated, use 'registration_backends' instead."
),
DeprecationWarning,
)
registration_backends.append(
{
"key": "default",
"name": _("Default"),
"backend": validated_data.pop("registration_backend"),
"options": registration_backend_options,
}
)

instance = super().create(validated_data)
ConfirmationEmailTemplate.objects.set_for_form(
form=instance, data=confirmation_email_template
Expand All @@ -376,33 +344,6 @@ def create(self, validated_data):
)
return instance

def _update_v2_registration_backend(self, form, validated_data):
new_data = {}
if "registration_backend" in validated_data:
new_data["backend"] = validated_data.pop("registration_backend")
if "registration_backend_options" in validated_data:
new_data["options"] = validated_data.pop("registration_backend_options")
if not any(v is not None for v in new_data.values()):
return

warnings.warn(
(
"Form 'registration_backend' and 'registration_backend_options' "
"are deprecated, use 'registration_backends' instead."
),
DeprecationWarning,
)

backend = form.registration_backends.first() or FormRegistrationBackend(
form=form, name=_("Default"), key="default"
)
serializer = FormRegistrationBackendSerializer(
instance=backend, data=new_data, context=self.context, partial=self.partial
)
# validated_data ought to be correct already
assert serializer.is_valid()
serializer.save()

@transaction.atomic()
def update(self, instance, validated_data):
confirmation_email_template = validated_data.pop(
Expand All @@ -413,8 +354,6 @@ def update(self, instance, validated_data):
)
registration_backends = validated_data.pop("registration_backends", None)

self._update_v2_registration_backend(instance, validated_data)

instance = super().update(instance, validated_data)
ConfirmationEmailTemplate.objects.set_for_form(
form=instance, data=confirmation_email_template
Expand Down Expand Up @@ -446,43 +385,11 @@ def get_fields(self):
("", "")
] + payment_register.get_choices()

# adapt fields for v2 backwards compatibility
if "registration_backends" in fields:
v2_backend = fields["registration_backend"]
v3_backend = fields["registration_backends"].child.get_fields()["backend"]
v2_backend.choices = v3_backend.choices

return fields

def validate(self, attrs):
super().validate(attrs)

if "registration_backend" in attrs and "registration_backends" in attrs:
raise serializers.ValidationError(
{
"registration_backend": ErrorDetail(
_(
"registration_backend is deprecated, please use just registration_backends",
),
code="invalid",
),
"registration_backend_options": ErrorDetail(
_(
"registration_backend is deprecated, please use just registration_backends",
),
code="invalid",
),
}
)

if "registration_backends" not in attrs:
self.validate_backend_options(
attrs,
"registration_backend",
"registration_backend_options",
registration_register,
)

self.validate_backend_options(
attrs, "payment_backend", "payment_backend_options", payment_register
)
Expand All @@ -509,7 +416,7 @@ def validate_backend_options(self, attrs, backend_field, options_field, registry
except serializers.ValidationError as e:
# wrap detail in dict so we can attach it to the field
# DRF will create the .invalidParams with a dotted path to nested fields
# like registrationBackendOptions.toEmails.0 if the first email was invalid
# like registrationBackends.0.options.toEmails.0 if the first email was invalid
detail = {options_field: e.detail}
raise serializers.ValidationError(detail) from e
# serializer does some normalization, so make sure to update the data
Expand Down Expand Up @@ -623,10 +530,6 @@ def get_fields(self):
del fields["payment_options"]
if "authentication_backends" in fields:
fields["authentication_backends"].write_only = False
if "registration_backend" in fields:
del fields["registration_backend"]
if "registration_backend_options" in fields:
del fields["registration_backend_options"]
return fields


Expand Down
14 changes: 0 additions & 14 deletions src/openforms/forms/models/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,6 @@ def get_absolute_url(self):
def get_api_url(self):
return reverse("api:form-detail", kwargs={"uuid": self.uuid})

@property
def registration_backend(self) -> str | None:
"For backwards compatibility"
return (
backend.backend if (backend := self.registration_backends.first()) else None
)

@property
def registration_backend_options(self) -> str | None:
"For backwards compatibility"
return (
backend.options if (backend := self.registration_backends.first()) else None
)

def get_registration_backend_display(self) -> str:
return (
", ".join(
Expand Down
Loading

0 comments on commit f519038

Please sign in to comment.