From 592f1f393bd9df3640da154854dd798aec2c88de Mon Sep 17 00:00:00 2001 From: vasileios Date: Fri, 20 Dec 2024 11:51:06 +0100 Subject: [PATCH] [#4825] Log prefill retrieve empty only for the used authentication flow This is a fix which is meant for backporting. The 'proper' fix will be implemented in a different PR, out of the scope of the v3.0. --- src/openforms/prefill/sources.py | 6 +++- .../prefill/tests/test_prefill_hook.py | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/openforms/prefill/sources.py b/src/openforms/prefill/sources.py index fd947c7780..ca1dc68ec9 100644 --- a/src/openforms/prefill/sources.py +++ b/src/openforms/prefill/sources.py @@ -70,7 +70,11 @@ def invoke_plugin( if values: logevent.prefill_retrieve_success(submission, plugin, fields) else: - logevent.prefill_retrieve_empty(submission, plugin, fields) + if (required_attribute := plugin.requires_auth) is None or ( + (auth_info := getattr(submission, "auth_info", None)) + and auth_info.attribute == required_attribute + ): + logevent.prefill_retrieve_empty(submission, plugin, fields) return fields, values invoke_plugin_args = [] diff --git a/src/openforms/prefill/tests/test_prefill_hook.py b/src/openforms/prefill/tests/test_prefill_hook.py index 3fb97e08f7..76ff099849 100644 --- a/src/openforms/prefill/tests/test_prefill_hook.py +++ b/src/openforms/prefill/tests/test_prefill_hook.py @@ -626,3 +626,36 @@ class TestPlugin(BasePlugin): result = plugin.get_identifier_value(submission, IdentifierRoles.main) self.assertEqual("123123123", result) + + def test_prefill_logging_with_mismatching_login_method(self): + components = [ + { + "key": "mainPersonName", + "type": "textfield", + "prefill": { + "plugin": "demo", + "attribute": "naam.voornamen", + "identifierRole": IdentifierRoles.main, + }, + }, + ] + submission = SubmissionFactory.from_components( + components_list=components, kvk="69599084" + ) + register = Registry() + + @register("demo") + class MismatchPlugin(DemoPrefill): + requires_auth = AuthAttribute.bsn + + @staticmethod + def get_prefill_values(submission, attributes, identifier_role): + return {} + + apply_prefill( + configuration={"components": components}, + submission=submission, + register=register, + ) + + self.assertFalse(TimelineLogProxy.objects.exists())