Skip to content

Commit

Permalink
records: adds conditional dumping of files
Browse files Browse the repository at this point in the history
  • Loading branch information
lnielsen authored and zzacharo committed Sep 12, 2023
1 parent 7141817 commit 90646c8
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions invenio_rdm_records/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -327,6 +330,7 @@ class RDMDraftMediaFiles(RDMDraft):

RDMMediaFileDraft.record_cls = RDMDraftMediaFiles


# Record API
#
class RDMFileRecord(FileRecord):
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 90646c8

Please sign in to comment.