Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Records: Add conditional file dumping #1459

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions invenio_rdm_records/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from .dumpers import (
EDTFDumperExt,
EDTFListDumperExt,
FilesDumperExt,
GrantTokensDumperExt,
StatisticsDumperExt,
)
Expand All @@ -56,6 +55,7 @@
RecordStatisticsField,
TombstoneField,
)
from .systemfields.access.protection import Visibility
from .systemfields.draft_status import DraftStatus


Expand Down Expand Up @@ -97,15 +97,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."""

Expand All @@ -116,7 +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=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(
Expand Down Expand Up @@ -332,7 +331,6 @@ class RDMDraftMediaFiles(RDMDraft):
RDMMediaFileDraft.record_cls = RDMDraftMediaFiles


#
# Record API
#
class RDMFileRecord(FileRecord):
Expand All @@ -358,11 +356,14 @@ 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,
# 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
2 changes: 0 additions & 2 deletions invenio_rdm_records/records/dumpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

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

__all__ = (
"EDTFDumperExt",
"EDTFListDumperExt",
"FilesDumperExt",
"PIDsDumperExt",
"GrantTokensDumperExt",
"LocationsDumper",
Expand Down
26 changes: 0 additions & 26 deletions invenio_rdm_records/records/dumpers/files.py

This file was deleted.