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

[#4825] Fix prefill when authentication is needed #5010

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
13 changes: 7 additions & 6 deletions src/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9541,11 +9541,13 @@ 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
nullable: true
title: Required authentication attribute
description: The authentication attribute required for this plugin to
lookup remote data.
configurationContext:
nullable: true
title: Extra configuration context
Expand All @@ -9555,7 +9557,6 @@ components:
- configurationContext
- id
- label
- requiresAuth
PrefillTargetPaths:
type: object
properties:
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 @@ -1819,6 +1819,28 @@
"value": "Save as new"
}
],
"EmcgDt": [
{
"type": 0,
"value": "Component \""
},
{
"type": 1,
"value": "label"
},
{
"type": 0,
"value": "\" uses a prefill that requires the \""
},
{
"type": 1,
"value": "requiredAuthAttribute"
},
{
"type": 0,
"value": "\" attributes. Please select an authentication plugin that provides these attributes."
}
],
"ErwGIQ": [
{
"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 @@ -1840,6 +1840,28 @@
"value": "Opslaan als nieuw"
}
],
"EmcgDt": [
{
"type": 0,
"value": "Component \""
},
{
"type": 1,
"value": "label"
},
{
"type": 0,
"value": "\" uses a prefill that requires the \""
},
{
"type": 1,
"value": "requiredAuthAttribute"
},
{
"type": 0,
"value": "\" attributes. Please select an authentication plugin that provides these attributes."
}
],
"ErwGIQ": [
{
"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 the "{requiredAuthAttribute}" attributes. \
Please select an authentication plugin that provides these attributes.'
}
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 @@ -774,6 +774,11 @@
"description": "Save as new service fetch configuration button label",
"originalDefault": "Save as new"
},
"EmcgDt": {
"defaultMessage": "Component \"{label}\" uses a prefill that requires the \"{requiredAuthAttribute}\" attributes. Please select an authentication plugin that provides these attributes.",
"description": "Prefill plugin requires unavailable auth attribute warning",
"originalDefault": "Component \"{label}\" uses a prefill that requires the \"{requiredAuthAttribute}\" attributes. Please select an authentication plugin that provides these attributes."
},
"EtAvFF": {
"defaultMessage": "Duplicate this form",
"description": "Copy form button title",
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 @@ -781,6 +781,11 @@
"description": "Save as new service fetch configuration button label",
"originalDefault": "Save as new"
},
"EmcgDt": {
"defaultMessage": "Component \"{label}\" uses a prefill that requires the \"{requiredAuthAttribute}\" attributes. Please select an authentication plugin that provides these attributes.",
"description": "Prefill plugin requires unavailable auth attribute warning",
"originalDefault": "Component \"{label}\" uses a prefill that requires the \"{requiredAuthAttribute}\" attributes. Please select an authentication plugin that provides these attributes."
},
"EtAvFF": {
"defaultMessage": "Maak een kopie van dit formulier",
"description": "Copy form button title",
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
13 changes: 8 additions & 5 deletions src/openforms/prefill/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@


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,
),
allow_null=True,
default=list,
)
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] | None = None
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
19 changes: 14 additions & 5 deletions src/openforms/prefill/co_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import logging
from collections.abc import Collection

from openforms.authentication.service import AuthAttribute
from openforms.submissions.cosigning import CosignV1Data
Expand All @@ -26,11 +27,19 @@


def get_default_plugin_for_auth_attribute(
auth_attribute: AuthAttribute | None,
auth_attribute: Collection[AuthAttribute] | None,
) -> str | None:
if not auth_attribute or not (
config_field := AUTH_ATTRIBUTE_TO_CONFIG_FIELD.get(auth_attribute)
):
if not auth_attribute:
logger.info("No auth_attribute provided")
return

config_field = ""
for attribute in auth_attribute:
if AUTH_ATTRIBUTE_TO_CONFIG_FIELD.get(attribute):
config_field = AUTH_ATTRIBUTE_TO_CONFIG_FIELD[attribute]
break

if not config_field:
logger.info("Unsupported auth_attribute '%s'", auth_attribute)
return

Expand All @@ -44,7 +53,7 @@ def get_default_plugin_for_auth_attribute(


def add_co_sign_representation(
submission: Submission, auth_attribute: AuthAttribute | None
submission: Submission, auth_attribute: Collection[AuthAttribute] | None
):
default_plugin = get_default_plugin_for_auth_attribute(auth_attribute)
# configuration may be incomplete, do nothing in that case!
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
Loading
Loading