Skip to content

Commit

Permalink
deposit: really remove old user email when present
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ntarocco committed Nov 14, 2024
1 parent ecad6b6 commit c70c8f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cds/modules/invenio_deposit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,16 @@ 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)
try:
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
Expand Down
8 changes: 7 additions & 1 deletion cds/modules/records/serializers/schemas/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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."""
Expand Down
8 changes: 7 additions & 1 deletion cds/modules/records/serializers/schemas/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit c70c8f5

Please sign in to comment.