Skip to content

Commit

Permalink
🗃️ [#4246] Rename choice value to authorizee
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergei-maertens committed Jul 2, 2024
1 parent cbf22bb commit ef6d968
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/openforms/formio/migration_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/openforms/formio/typing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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",
),
),
]
13 changes: 13 additions & 0 deletions src/openforms/forms/tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
2 changes: 1 addition & 1 deletion src/openforms/prefill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
2 changes: 1 addition & 1 deletion src/openforms/prefill/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit ef6d968

Please sign in to comment.