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

Conditional dumping #499

Merged
merged 2 commits into from
Sep 12, 2023
Merged
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
18 changes: 13 additions & 5 deletions invenio_records_resources/records/systemfields/files/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
bucket_attr=FilesAttrConfig["_files_bucket_attr_key"],
store=True,
dump=False,
dump_entries=True,
file_cls=None,
enabled=True,
bucket_args=None,
Expand All @@ -81,6 +82,7 @@ def __init__(
"""
self._store = store
self._dump = dump
self._dump_entries = dump_entries
self._enabled = enabled
self._bucket_id_attr = bucket_id_attr
self._bucket_attr = bucket_attr
Expand Down Expand Up @@ -120,19 +122,25 @@ def post_create(self, record):

self.store(record, files)

def pre_dump(self, record, data, **kwargs):
"""Called before a record is dumped in a secondary storage system."""
def post_dump(self, record, data, **kwargs):
"""Called after a record is dumped in a secondary storage system."""
# Dump files into index if requested (if store=True, files are already
# part of the dumped record)
if self._dump and not self._store:
files = getattr(record, self.attr_name)
if files is not None:
# Determine if entries should be included.
# Use to remove file entries from search dump in case a record
# is public but files are restricted.
if callable(self._dump_entries):
include_entries = self._dump_entries(record)
else:
include_entries = self._dump_entries

self.set_dictkey(
data, self.dump(record, files, include_entries=self._dump)
data, self.dump(record, files, include_entries=include_entries)
)

def post_dump(self, record, data, **kwargs):
"""Called after a record is dumped in a secondary storage system."""
# Prepare file entries for index (dict to list)
if self._dump or self._store:
files = self.get_dictkey(data)
Expand Down