From 7f6f2f9ff31ec564fe5e0e5661543a0ffaeb443c Mon Sep 17 00:00:00 2001 From: Lars Holm Nielsen Date: Tue, 12 Sep 2023 13:17:14 +0200 Subject: [PATCH 1/2] records: revert file dumper --- invenio_rdm_records/records/api.py | 24 ++++++----------- .../records/dumpers/__init__.py | 2 -- invenio_rdm_records/records/dumpers/files.py | 26 ------------------- 3 files changed, 8 insertions(+), 44 deletions(-) delete mode 100644 invenio_rdm_records/records/dumpers/files.py diff --git a/invenio_rdm_records/records/api.py b/invenio_rdm_records/records/api.py index b0e933f7c..6110d3c47 100644 --- a/invenio_rdm_records/records/api.py +++ b/invenio_rdm_records/records/api.py @@ -43,7 +43,6 @@ from .dumpers import ( EDTFDumperExt, EDTFListDumperExt, - FilesDumperExt, GrantTokensDumperExt, StatisticsDumperExt, ) @@ -57,7 +56,7 @@ TombstoneField, ) from .systemfields.draft_status import DraftStatus - +from .systemfields.access.protection import Visibility # # Parent record API @@ -97,15 +96,6 @@ class RDMParent(ParentRecordBase): # # Common properties between records and drafts. # -COMMON_DUMPER_EXTENSIONS = [ - EDTFDumperExt("metadata.publication_date"), - EDTFListDumperExt("metadata.dates", "date"), - RelationDumperExt("relations"), - CustomFieldsDumperExt(fields_var="RDM_CUSTOM_FIELDS"), - StatisticsDumperExt("stats"), -] - - class CommonFieldsMixin: """Common system fields between records and drafts.""" @@ -116,7 +106,13 @@ class CommonFieldsMixin: # update the JSONSchema and mappings to a new version. schema = ConstantField("$schema", "local://records/record-v6.0.0.json") - dumper = SearchDumper(extensions=COMMON_DUMPER_EXTENSIONS) + dumper = SearchDumper(extensions=[ + EDTFDumperExt("metadata.publication_date"), + EDTFListDumperExt("metadata.dates", "date"), + RelationDumperExt("relations"), + CustomFieldsDumperExt(fields_var="RDM_CUSTOM_FIELDS"), + StatisticsDumperExt("stats"), + ]) relations = MultiRelationsField( creator_affiliations=PIDNestedListRelation( @@ -331,8 +327,6 @@ class RDMDraftMediaFiles(RDMDraft): RDMMediaFileDraft.record_cls = RDMDraftMediaFiles - -# # Record API # class RDMFileRecord(FileRecord): @@ -358,8 +352,6 @@ class RDMRecord(CommonFieldsMixin, Record): "rdmrecords-records-record-v6.0.0", search_alias="rdmrecords-records" ) - dumper = SearchDumper(extensions=COMMON_DUMPER_EXTENSIONS + [FilesDumperExt()]) - files = FilesField( store=False, dump=True, diff --git a/invenio_rdm_records/records/dumpers/__init__.py b/invenio_rdm_records/records/dumpers/__init__.py index 622b16755..0eaa889f6 100644 --- a/invenio_rdm_records/records/dumpers/__init__.py +++ b/invenio_rdm_records/records/dumpers/__init__.py @@ -9,7 +9,6 @@ from .access import GrantTokensDumperExt from .edtf import EDTFDumperExt, EDTFListDumperExt -from .files import FilesDumperExt from .locations import LocationsDumper from .pids import PIDsDumperExt from .statistics import StatisticsDumperExt @@ -17,7 +16,6 @@ __all__ = ( "EDTFDumperExt", "EDTFListDumperExt", - "FilesDumperExt", "PIDsDumperExt", "GrantTokensDumperExt", "LocationsDumper", diff --git a/invenio_rdm_records/records/dumpers/files.py b/invenio_rdm_records/records/dumpers/files.py deleted file mode 100644 index 925461379..000000000 --- a/invenio_rdm_records/records/dumpers/files.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2020 CERN. -# -# Invenio-RDM-Records is free software; you can redistribute it and/or modify -# it under the terms of the MIT License; see LICENSE file for more details. - -"""Search dumpers for location information.""" - - -from invenio_records.dumpers import SearchDumperExt - -from ..systemfields.access.protection import Visibility - - -class FilesDumperExt(SearchDumperExt): - """Files dumper.""" - - def dump(self, record, data): - """Dump the data.""" - public_record_with_restricted_files = ( - data["access"].get("record") == Visibility.PUBLIC.value - and data["access"].get("files") == Visibility.RESTRICTED.value - ) - if public_record_with_restricted_files: - data["files"] = {"enabled": data["files"]["enabled"]} From b99bb4d89690e7446d4646ff23b88142264fd237 Mon Sep 17 00:00:00 2001 From: Lars Holm Nielsen Date: Tue, 12 Sep 2023 13:18:05 +0200 Subject: [PATCH 2/2] records: adds conditional dumping of files --- invenio_rdm_records/records/api.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/invenio_rdm_records/records/api.py b/invenio_rdm_records/records/api.py index 6110d3c47..cf1d67d4e 100644 --- a/invenio_rdm_records/records/api.py +++ b/invenio_rdm_records/records/api.py @@ -55,8 +55,9 @@ RecordStatisticsField, TombstoneField, ) -from .systemfields.draft_status import DraftStatus from .systemfields.access.protection import Visibility +from .systemfields.draft_status import DraftStatus + # # Parent record API @@ -106,13 +107,15 @@ class CommonFieldsMixin: # update the JSONSchema and mappings to a new version. schema = ConstantField("$schema", "local://records/record-v6.0.0.json") - dumper = SearchDumper(extensions=[ - EDTFDumperExt("metadata.publication_date"), - EDTFListDumperExt("metadata.dates", "date"), - RelationDumperExt("relations"), - CustomFieldsDumperExt(fields_var="RDM_CUSTOM_FIELDS"), - StatisticsDumperExt("stats"), - ]) + dumper = SearchDumper( + extensions=[ + EDTFDumperExt("metadata.publication_date"), + EDTFListDumperExt("metadata.dates", "date"), + RelationDumperExt("relations"), + CustomFieldsDumperExt(fields_var="RDM_CUSTOM_FIELDS"), + StatisticsDumperExt("stats"), + ] + ) relations = MultiRelationsField( creator_affiliations=PIDNestedListRelation( @@ -327,6 +330,7 @@ class RDMDraftMediaFiles(RDMDraft): RDMMediaFileDraft.record_cls = RDMDraftMediaFiles + # Record API # class RDMFileRecord(FileRecord): @@ -355,6 +359,11 @@ class RDMRecord(CommonFieldsMixin, Record): files = FilesField( store=False, dump=True, + # Don't dump files if record is public and files restricted. + dump_entries=lambda record: not ( + record.access.protection.record == Visibility.PUBLIC.value + and record.access.protection.files == Visibility.RESTRICTED.value + ), file_cls=RDMFileRecord, # Don't create create=False,