From c70c8f5c24b76ccd9f08374e3fe0d8287ca3fb9d Mon Sep 17 00:00:00 2001 From: Nicola Date: Thu, 14 Nov 2024 18:58:05 +0100 Subject: [PATCH] deposit: really remove old user email when present * It is not enough to remove the `current_user_mail` legacy field from the merge comparison, but it must be removed also by the dump when merging the deposit and the record. * Given that the `current_user_mail` field might still be present in some records, it should be ignored/removed when loading the record via marshmallow. --- cds/modules/invenio_deposit/api.py | 4 +++- cds/modules/records/serializers/schemas/project.py | 8 +++++++- cds/modules/records/serializers/schemas/video.py | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cds/modules/invenio_deposit/api.py b/cds/modules/invenio_deposit/api.py index 82fafe42b..b4a1982a1 100644 --- a/cds/modules/invenio_deposit/api.py +++ b/cds/modules/invenio_deposit/api.py @@ -188,7 +188,7 @@ def merge_with_published(self): args = [lca.dumps(), first.dumps(), self.dumps()] for arg in args: del arg["$schema"], arg["_deposit"] - # pop optional removed key `current_user_mail` when present + # skip legacy `current_user_mail` when comparing for merging arg.get("_cds", {}).pop("current_user_mail", None) args.append({}) m = Merger(*args) @@ -196,6 +196,8 @@ def merge_with_published(self): m.run() except UnresolvedConflictsException: raise MergeConflict() + # remove legacy `current_user_mail` when merging + lca.get("_cds", {}).pop("current_user_mail", None) return patch(m.unified_patches, lca) @index diff --git a/cds/modules/records/serializers/schemas/project.py b/cds/modules/records/serializers/schemas/project.py index 06b13ccb1..9cabff3b8 100644 --- a/cds/modules/records/serializers/schemas/project.py +++ b/cds/modules/records/serializers/schemas/project.py @@ -19,7 +19,7 @@ """Project JSON schema.""" from invenio_jsonschemas import current_jsonschemas -from marshmallow import Schema, fields, post_load +from marshmallow import Schema, fields, pre_load, post_load from ....deposit.api import Project, deposit_video_resolver from .common import ( @@ -44,6 +44,12 @@ class _CDSSSchema(Schema): state = fields.Raw() modified_by = fields.Int() + @pre_load + def remove_legacy_fields(self, data, **kwargs): + """Remove legacy fields.""" + data.pop("current_user_mail", None) + return data + class ProjectDepositSchema(DepositSchema): """Project Deposit Schema.""" diff --git a/cds/modules/records/serializers/schemas/video.py b/cds/modules/records/serializers/schemas/video.py index 1a0597670..c83e2e83a 100644 --- a/cds/modules/records/serializers/schemas/video.py +++ b/cds/modules/records/serializers/schemas/video.py @@ -19,7 +19,7 @@ """Video JSON schema.""" from invenio_jsonschemas import current_jsonschemas -from marshmallow import Schema, fields, post_load +from marshmallow import Schema, fields, pre_load, post_load from ....deposit.api import Video from ..fields.datetime import DateString @@ -47,6 +47,12 @@ class _CDSSSchema(Schema): extracted_metadata = fields.Raw() modified_by = fields.Int() + @pre_load + def remove_legacy_fields(self, data, **kwargs): + """Remove legacy fields.""" + data.pop("current_user_mail", None) + return data + class VideoDepositSchema(DepositSchema): """Project Deposit Schema."""