From ef6d968b9006fe7c52f57f8580d875a0adc9e98e Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Tue, 2 Jul 2024 11:50:06 +0200 Subject: [PATCH] :card_file_box: [#4246] Rename choice value to authorizee authorised_person is a confusing value when the authorizee is actually a company identified by KVK or RSIN, so we rename the value to authorizee instead. --- src/openforms/formio/migration_converters.py | 14 +++++++ src/openforms/formio/typing/base.py | 2 +- .../0103_rename_identifier_role_prefill.py | 38 ++++++++++++++++++- src/openforms/forms/tests/test_migrations.py | 13 +++++++ src/openforms/prefill/__init__.py | 2 +- src/openforms/prefill/constants.py | 2 +- 6 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/openforms/formio/migration_converters.py b/src/openforms/formio/migration_converters.py index 6d57099041..fc1599f1fa 100644 --- a/src/openforms/formio/migration_converters.py +++ b/src/openforms/formio/migration_converters.py @@ -236,6 +236,15 @@ def ensure_addressnl_has_deriveAddress(component: Component) -> bool: return True +def rename_identifier_role_authorizee(component: Component) -> bool: + if "prefill" not in component: + return False + if component["prefill"].get("identifierRole") != "authorised_person": + return False + component["prefill"]["identifierRole"] = "authorizee" + return True + + DEFINITION_CONVERTERS = [ convert_simple_conditionals, ] @@ -246,16 +255,19 @@ def ensure_addressnl_has_deriveAddress(component: Component) -> bool: "textfield": { "alter_prefill_default_values": alter_prefill_default_values, "fix_empty_validate_lengths": fix_empty_validate_lengths, + "rename_identifier_role_authorizee": rename_identifier_role_authorizee, }, "email": { "fix_empty_validate_lengths": fix_empty_validate_lengths, }, "date": { "alter_prefill_default_values": alter_prefill_default_values, + "rename_identifier_role_authorizee": rename_identifier_role_authorizee, }, "datetime": { "alter_prefill_default_values": alter_prefill_default_values, "prevent_datetime_components_from_emptying_invalid_values": prevent_datetime_components_from_emptying_invalid_values, + "rename_identifier_role_authorizee": rename_identifier_role_authorizee, }, "time": { "move_time_validators": move_time_validators, @@ -267,6 +279,7 @@ def ensure_addressnl_has_deriveAddress(component: Component) -> bool: "alter_prefill_default_values": alter_prefill_default_values, "ensure_validate_pattern": ensure_postcode_validate_pattern, "fix_empty_validate_lengths": fix_empty_validate_lengths, + "rename_identifier_role_authorizee": rename_identifier_role_authorizee, }, "file": { "fix_default_value": fix_file_default_value, @@ -297,6 +310,7 @@ def ensure_addressnl_has_deriveAddress(component: Component) -> bool: "bsn": { "alter_prefill_default_values": alter_prefill_default_values, "fix_empty_validate_lengths": fix_empty_validate_lengths, + "rename_identifier_role_authorizee": rename_identifier_role_authorizee, }, "cosign": { "fix_empty_validate_lengths": fix_empty_validate_lengths, diff --git a/src/openforms/formio/typing/base.py b/src/openforms/formio/typing/base.py index 1ff2d631a0..8a4c39e203 100644 --- a/src/openforms/formio/typing/base.py +++ b/src/openforms/formio/typing/base.py @@ -59,7 +59,7 @@ class OptionDict(TypedDict): class PrefillConfiguration(TypedDict): plugin: str attribute: str - identifierRole: Literal["main", "authorised_person"] + identifierRole: Literal["main", "authorizee"] class Component(TypedDict): diff --git a/src/openforms/forms/migrations/0103_rename_identifier_role_prefill.py b/src/openforms/forms/migrations/0103_rename_identifier_role_prefill.py index f737e2f1d0..58eb450970 100644 --- a/src/openforms/forms/migrations/0103_rename_identifier_role_prefill.py +++ b/src/openforms/forms/migrations/0103_rename_identifier_role_prefill.py @@ -1,6 +1,16 @@ # Generated by Django 4.2.11 on 2024-07-02 09:03 -from django.db import migrations +from django.db import migrations, models +from django.db.migrations.state import StateApps + +from openforms.forms.migration_operations import ConvertComponentsOperation + + +def rename_authorizee_enum(apps: StateApps, _): + FormVariable = apps.get_model("forms", "FormVariable") + FormVariable.objects.filter(prefill_identifier_role="authorised_person").update( + prefill_identifier_role="authorizee" + ) class Migration(migrations.Migration): @@ -9,4 +19,28 @@ class Migration(migrations.Migration): ("forms", "0102_alter_formvariable_prefill_identifier_role"), ] - operations = [] + operations = [ + migrations.RunPython( + rename_authorizee_enum, + # no point in adding a reverse operation when ConvertComponent doesn't + # support it - if it's wrong, we recommend restoring a backup. + migrations.RunPython.noop, + ), + # only lists the components that have prefill + ConvertComponentsOperation("textfield", "rename_identifier_role_authorizee"), + ConvertComponentsOperation("date", "rename_identifier_role_authorizee"), + ConvertComponentsOperation("datetime", "rename_identifier_role_authorizee"), + ConvertComponentsOperation("postcode", "rename_identifier_role_authorizee"), + ConvertComponentsOperation("bsn", "rename_identifier_role_authorizee"), + migrations.AlterField( + model_name="formvariable", + name="prefill_identifier_role", + field=models.CharField( + choices=[("main", "Main"), ("authorizee", "Authorizee")], + default="main", + help_text="In case that multiple identifiers are returned (in the case of eHerkenning bewindvoering and DigiD Machtigen), should the prefill data related to the main identifier be used, or that related to the authorised person?", + max_length=100, + verbose_name="prefill identifier role", + ), + ), + ] diff --git a/src/openforms/forms/tests/test_migrations.py b/src/openforms/forms/tests/test_migrations.py index e342cc9dde..8c938d88a7 100644 --- a/src/openforms/forms/tests/test_migrations.py +++ b/src/openforms/forms/tests/test_migrations.py @@ -545,6 +545,16 @@ def setUpBeforeMigration(self, apps: StateApps): }, }, {"type": "number", "key": "number", "label": "no prefill configured"}, + { + "type": "bsn", + "key": "other", + "label": "Some bsn field with prefill", + "prefill": { + "plugin": "demo", + "attribute": "random_string", + "identifierRole": "main", + }, + }, ] } FormDefinition.objects.create(name="legacy", configuration=configuration) @@ -567,6 +577,9 @@ def test_identifier_role_updated_to_authorizee(self): variable = FormVariable.objects.get() self.assertEqual(variable.prefill_identifier_role, "authorizee") + fd = FormDefinition.objects.get() component = fd.configuration["components"][0] self.assertEqual(component["prefill"]["identifierRole"], "authorizee") + component3 = fd.configuration["components"][2] + self.assertEqual(component3["prefill"]["identifierRole"], "main") diff --git a/src/openforms/prefill/__init__.py b/src/openforms/prefill/__init__.py index f8ea4e9da9..177a8e13b4 100644 --- a/src/openforms/prefill/__init__.py +++ b/src/openforms/prefill/__init__.py @@ -170,7 +170,7 @@ def prefill_variables(submission: Submission, register: Registry | None = None) # grouped_fields is a dict of the following shape: # {"plugin_id": {"identifier_role": ["attr_1", "attr_2"]}} - # "identifier_role" is either "main" or "authorised_person" + # "identifier_role" is either "main" or "authorizee" grouped_fields: defaultdict[str, defaultdict[str, list[str]]] = defaultdict( lambda: defaultdict(list) ) diff --git a/src/openforms/prefill/constants.py b/src/openforms/prefill/constants.py index 7b2d20385d..90baaa2a20 100644 --- a/src/openforms/prefill/constants.py +++ b/src/openforms/prefill/constants.py @@ -9,4 +9,4 @@ class IdentifierRoles(models.TextChoices): # 2. with eHerkenning (bewindvoering), the authorizee is de *company* (legal # subject). For the acting subject, we only get an opaque, encrypted identifier # that cannot be used to prefill information (this is by design). - authorizee = "authorised_person", _("Authorizee") + authorizee = "authorizee", _("Authorizee")