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 Nov 28, 2024
1 parent f0aa235 commit 0ddb6e4
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 278 deletions.
18 changes: 18 additions & 0 deletions docs/installation/upgrade-300.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@ Removal of legacy translations conversion
Old (from before Open Forms 2.4) form export files containing form field translations
in the legacy format are now ignored instead of converted to the new format. We
recommend re-creating the exports on a newer version of Open Forms.

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.

Removal of single registration on forms
=======================================

The old registration backend configuration (from before Open Forms 2.3) is now completely
removed. This removes `registrationBackend` and `registrationBackendOptions` from all api
endpoints. You should be using the `registrationBackends` property.

This also means that the import no-longer converts the old configuration to the current
format. When importing a form using the legacy registration configuration,
the created form won't contain any registrations.
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 @@ -7508,7 +7498,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 @@ -7530,12 +7520,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 @@ -8021,7 +8005,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 @@ -8192,7 +8176,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 @@ -9126,7 +9110,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 @@ -9148,12 +9132,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
97 changes: 1 addition & 96 deletions src/openforms/forms/api/serializers/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ def validate(self, attrs):

@extend_schema_serializer(
deprecate_fields=[
"registration_backend",
"registration_backend_options",
"cosign_login_info",
]
)
Expand Down Expand Up @@ -240,12 +238,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 @@ -255,8 +247,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 @@ -358,26 +348,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 @@ -392,33 +362,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 @@ -429,8 +372,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 @@ -462,43 +403,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 @@ -525,7 +434,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 @@ -639,10 +548,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 0ddb6e4

Please sign in to comment.