Skip to content

Commit

Permalink
Merge pull request #5010 from open-formulieren/fix/4825-2-digest-repo…
Browse files Browse the repository at this point in the history
…rts-prefill-failures-when-multiple-auth-flows

[#4825] Fix prefill when authentication is needed
  • Loading branch information
sergei-maertens authored Jan 14, 2025
2 parents 134ee74 + bcf2262 commit 41616e3
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 102 deletions.
11 changes: 6 additions & 5 deletions src/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9541,11 +9541,12 @@ components:
type: string
description: The human-readable name for a plugin.
requiresAuth:
type: string
nullable: true
title: Required authentication attribute
description: The authentication attribute required for this plugin to lookup
remote data.
type: array
items:
type: string
title: Required authentication attribute
description: The authentication attribute required for this plugin to
lookup remote data.
configurationContext:
nullable: true
title: Extra configuration context
Expand Down
44 changes: 22 additions & 22 deletions src/openforms/js/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,28 @@
"value": "Component"
}
],
"MIrPon": [
{
"type": 0,
"value": "Component \""
},
{
"type": 1,
"value": "label"
},
{
"type": 0,
"value": "\" uses a prefill that requires one of the \""
},
{
"type": 1,
"value": "requiredAuthAttribute"
},
{
"type": 0,
"value": "\" attributes. Please select one or more authentication plugins that provide such an attribute."
}
],
"MTdKuN": [
{
"type": 0,
Expand Down Expand Up @@ -3529,28 +3551,6 @@
"value": "Maximum selected checkboxes (e.g. 1)"
}
],
"VQYmOD": [
{
"type": 0,
"value": "Component \""
},
{
"type": 1,
"value": "label"
},
{
"type": 0,
"value": "\" uses a prefill that requires the \""
},
{
"type": 1,
"value": "requiredAuthAttribute"
},
{
"type": 0,
"value": "\" attribute. Please select an authentication plugin that provides this attribute."
}
],
"VUOOSy": [
{
"type": 0,
Expand Down
44 changes: 22 additions & 22 deletions src/openforms/js/compiled-lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,28 @@
"value": "Veld"
}
],
"MIrPon": [
{
"type": 0,
"value": "Component \""
},
{
"type": 1,
"value": "label"
},
{
"type": 0,
"value": "\" uses a prefill that requires one of the \""
},
{
"type": 1,
"value": "requiredAuthAttribute"
},
{
"type": 0,
"value": "\" attributes. Please select one or more authentication plugins that provide such an attribute."
}
],
"MTdKuN": [
{
"type": 0,
Expand Down Expand Up @@ -3542,28 +3564,6 @@
"value": "Maximaal aantal aangevinkte opties (bijv. 1)"
}
],
"VQYmOD": [
{
"type": 0,
"value": "De component \""
},
{
"type": 1,
"value": "label"
},
{
"type": 0,
"value": "\" gebruikt een prefill die het \""
},
{
"type": 1,
"value": "requiredAuthAttribute"
},
{
"type": 0,
"value": "\"-attribuut nodig heeft. Gebruik een authenticatiemethode die dit attribuut aanbiedt."
}
],
"VUOOSy": [
{
"type": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const PluginWarning = ({loginRequired, configuration}) => {
const authPlugin = availableAuthPlugins.find(plugin => plugin.id === pluginName);
if (!authPlugin) break;

if (authPlugin.providesAuth.includes(requiredAuthAttribute)) {
if (requiredAuthAttribute.includes(authPlugin.providesAuth)) {
pluginProvidesAttribute = true;
break;
}
Expand All @@ -46,12 +46,12 @@ const PluginWarning = ({loginRequired, configuration}) => {
<FormattedMessage
description="Prefill plugin requires unavailable auth attribute warning"
defaultMessage={
'Component "{label}" uses a prefill that requires the "{requiredAuthAttribute}" attribute. \
Please select an authentication plugin that provides this attribute.'
'Component "{label}" uses a prefill that requires one of the "{requiredAuthAttribute}" attributes. \
Please select one or more authentication plugins that provide such an attribute.'
}
values={{
label: configuration.label,
requiredAuthAttribute,
requiredAuthAttribute: requiredAuthAttribute.join(', '),
}}
/>
);
Expand Down
10 changes: 5 additions & 5 deletions src/openforms/js/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,11 @@
"description": "Formio component selection label",
"originalDefault": "Component"
},
"MIrPon": {
"defaultMessage": "Component \"{label}\" uses a prefill that requires one of the \"{requiredAuthAttribute}\" attributes. Please select one or more authentication plugins that provide such an attribute.",
"description": "Prefill plugin requires unavailable auth attribute warning",
"originalDefault": "Component \"{label}\" uses a prefill that requires one of the \"{requiredAuthAttribute}\" attributes. Please select one or more authentication plugins that provide such an attribute."
},
"MUfBmP": {
"defaultMessage": "The value of the selected field will be the process variable value.",
"description": "Column help text for variable to map to property",
Expand Down Expand Up @@ -1694,11 +1699,6 @@
"description": "Confirmation page content label",
"originalDefault": "Page content"
},
"VQYmOD": {
"defaultMessage": "Component \"{label}\" uses a prefill that requires the \"{requiredAuthAttribute}\" attribute. Please select an authentication plugin that provides this attribute.",
"description": "Prefill plugin requires unavailable auth attribute warning",
"originalDefault": "Component \"{label}\" uses a prefill that requires the \"{requiredAuthAttribute}\" attribute. Please select an authentication plugin that provides this attribute."
},
"VUOOSy": {
"defaultMessage": "Name",
"description": "Camunda complex process var 'name' label",
Expand Down
10 changes: 5 additions & 5 deletions src/openforms/js/lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,11 @@
"description": "Formio component selection label",
"originalDefault": "Component"
},
"MIrPon": {
"defaultMessage": "Component \"{label}\" uses a prefill that requires one of the \"{requiredAuthAttribute}\" attributes. Please select one or more authentication plugins that provide such an attribute.",
"description": "Prefill plugin requires unavailable auth attribute warning",
"originalDefault": "Component \"{label}\" uses a prefill that requires one of the \"{requiredAuthAttribute}\" attributes. Please select one or more authentication plugins that provide such an attribute."
},
"MUfBmP": {
"defaultMessage": "De waarde van de geselecteerde variabele wordt de waarde van de zaakeigenschap.",
"description": "Column help text for variable to map to property",
Expand Down Expand Up @@ -1710,11 +1715,6 @@
"description": "Confirmation page content label",
"originalDefault": "Page content"
},
"VQYmOD": {
"defaultMessage": "De component \"{label}\" gebruikt een prefill die het \"{requiredAuthAttribute}\"-attribuut nodig heeft. Gebruik een authenticatiemethode die dit attribuut aanbiedt.",
"description": "Prefill plugin requires unavailable auth attribute warning",
"originalDefault": "Component \"{label}\" uses a prefill that requires the \"{requiredAuthAttribute}\" attribute. Please select an authentication plugin that provides this attribute."
},
"VUOOSy": {
"defaultMessage": "Naam",
"description": "Camunda complex process var 'name' label",
Expand Down
11 changes: 6 additions & 5 deletions src/openforms/prefill/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@


class PrefillPluginSerializer(PluginBaseSerializer):
requires_auth = serializers.CharField(
label=_("Required authentication attribute"),
help_text=_(
"The authentication attribute required for this plugin to lookup remote data."
requires_auth = serializers.ListField(
child=serializers.CharField(
label=_("Required authentication attribute"),
help_text=_(
"The authentication attribute required for this plugin to lookup remote data."
),
),
allow_null=True,
)
configuration_context = serializers.JSONField(
label=_("Extra configuration context"),
Expand Down
16 changes: 8 additions & 8 deletions src/openforms/prefill/api/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class TestPrefill(BasePlugin):
requires_auth = AuthAttribute.bsn
requires_auth = (AuthAttribute.bsn,)
verbose_name = "Test"

def get_available_attributes(self):
Expand All @@ -26,7 +26,7 @@ def get_available_attributes(self):

@register("onlyvars")
class OnlyVarsPrefill(BasePlugin):
requires_auth = AuthAttribute.bsn
requires_auth = (AuthAttribute.bsn,)
verbose_name = "Only Vars"
for_components = ()

Expand All @@ -36,7 +36,7 @@ def get_available_attributes(self):

@register("vanityplates")
class VanityPlatePrefill(BasePlugin):
requires_auth = AuthAttribute.bsn
requires_auth = (AuthAttribute.bsn,)
verbose_name = "Vanity Plates"
for_components = {"licenseplate"}

Expand Down Expand Up @@ -111,19 +111,19 @@ def test_prefill_list(self):
{
"id": "test",
"label": "Test",
"requiresAuth": AuthAttribute.bsn,
"requiresAuth": [AuthAttribute.bsn],
"configurationContext": None,
},
{
"id": "onlyvars",
"label": "Only Vars",
"requiresAuth": AuthAttribute.bsn,
"requiresAuth": [AuthAttribute.bsn],
"configurationContext": None,
},
{
"id": "vanityplates",
"label": "Vanity Plates",
"requiresAuth": AuthAttribute.bsn,
"requiresAuth": [AuthAttribute.bsn],
"configurationContext": None,
},
]
Expand All @@ -141,14 +141,14 @@ def test_prefill_list_for_component_type(self):
{
"id": "test",
"label": "Test",
"requiresAuth": AuthAttribute.bsn,
"requiresAuth": [AuthAttribute.bsn],
"configurationContext": None,
},
# spec'd for licenseplate
{
"id": "vanityplates",
"label": "Vanity Plates",
"requiresAuth": AuthAttribute.bsn,
"requiresAuth": [AuthAttribute.bsn],
"configurationContext": None,
},
]
Expand Down
6 changes: 4 additions & 2 deletions src/openforms/prefill/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Collection
from typing import Any, Container, Iterable, TypedDict

from rest_framework import serializers
Expand Down Expand Up @@ -29,7 +30,7 @@ class Options(TypedDict):


class BasePlugin[OptionsT: Options](AbstractBasePlugin):
requires_auth: AuthAttribute | None = None
requires_auth: Collection[AuthAttribute] = ()
for_components: Container[str] = AllComponentTypes()
options: SerializerCls = EmptyOptions

Expand Down Expand Up @@ -139,7 +140,8 @@ def get_identifier_value(

if (
identifier_role == IdentifierRoles.main
and submission.auth_info.attribute == cls.requires_auth
and cls.requires_auth
and submission.auth_info.attribute in cls.requires_auth
):
return submission.auth_info.value

Expand Down
5 changes: 3 additions & 2 deletions src/openforms/prefill/contrib/haalcentraal_brp/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_attributes_cls():
@register(PLUGIN_IDENTIFIER)
class HaalCentraalPrefill(BasePlugin):
verbose_name = _("Haal Centraal: BRP Personen Bevragen")
requires_auth = AuthAttribute.bsn
requires_auth = (AuthAttribute.bsn,)

@staticmethod
def get_available_attributes() -> list[tuple[str, str]]:
Expand Down Expand Up @@ -84,7 +84,8 @@ def get_identifier_value(

if (
identifier_role == IdentifierRoles.main
and submission.auth_info.attribute == cls.requires_auth
and cls.requires_auth
and submission.auth_info.attribute in cls.requires_auth
):
return submission.auth_info.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_store_names_on_co_sign_auth(self):
}
)

add_co_sign_representation(submission, plugin.requires_auth)
add_co_sign_representation(submission, plugin.requires_auth[0])

submission.refresh_from_db()
expected = {
Expand All @@ -96,7 +96,7 @@ def test_incomplete_data_returned(self):
}
)

add_co_sign_representation(submission, plugin.requires_auth)
add_co_sign_representation(submission, plugin.requires_auth[0])

submission.refresh_from_db()
expected = {
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_store_names_on_co_sign_auth(self):
}
)

add_co_sign_representation(submission, plugin.requires_auth)
add_co_sign_representation(submission, plugin.requires_auth[0])

submission.refresh_from_db()
expected = {
Expand Down
5 changes: 3 additions & 2 deletions src/openforms/prefill/contrib/kvk/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _select_address(items, type_):
class KVK_KVKNumberPrefill(BasePlugin):
verbose_name = _("KvK Company by KvK number")

requires_auth = AuthAttribute.kvk
requires_auth = (AuthAttribute.kvk,)

@staticmethod
def get_available_attributes() -> list[tuple[str, str]]:
Expand All @@ -50,7 +50,8 @@ def get_identifier_value(

if (
identifier_role == IdentifierRoles.main
and submission.auth_info.attribute == cls.requires_auth
and cls.requires_auth
and submission.auth_info.attribute in cls.requires_auth
):
return submission.auth_info.value

Expand Down
Loading

0 comments on commit 41616e3

Please sign in to comment.