Skip to content

Commit

Permalink
records: override new bucket methods
Browse files Browse the repository at this point in the history
Signed-off-by: Parth Shandilya <[email protected]>
  • Loading branch information
ParthS007 committed May 16, 2023
1 parent 0b4852a commit f639ed9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cap/modules/deposit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ def _publish_edited(self):
record = super(CAPDeposit, self)._publish_edited()
record._add_deposit_permissions(record, record.id)

with db.session.begin_nested():
if self.files and record.files.bucket is not None:
# Unlock the record bucket
record.files.bucket.locked = False
# Lock the deposit's files bucket
self.files.bucket.locked = True
# Sync the record files with the deposit files
self.files.bucket.sync(record.files.bucket)
# lock the record bucket after update
record.files.bucket.locked = True
db.session.commit()
if record["_experiment"]:
record._add_experiment_permissions(record, record.id)

Expand Down
40 changes: 40 additions & 0 deletions cap/modules/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,46 @@ def RECORD_ACTION_NEEDS(id):
class CAPRecord(Record):
"""Record API class for CAP."""

@classmethod
def create_bucket(cls, data):
"""Create a bucket for this record.
Override this method to provide more advanced bucket creation
capabilities. This method may return a new or existing bucket, or may
return None, in case no bucket should be created.
"""
return None

@classmethod
def load_bucket(cls, record):
"""Load the bucket id from the record metadata.
Override this method to provide custom behavior for retrieving the
bucket id from the record metadata. By default the bucket id is
retrieved from the ``_bucket`` key. If you override this method, make
sure you also override :py:data:`Record.dump_bucket()`.
:param record: A record instance.
"""
return

@classmethod
def dump_bucket(cls, data, bucket):
"""Dump the bucket id into the record metadata.
Override this method to provide custom behavior for storing the bucket
id in the record metadata. By default the bucket id is stored in the
``_bucket`` key. If you override this method, make sure you also
override :py:data:`Record.load_bucket()`.
This method is called after the bucket is created, but before the
record is created in the database.
:param data: A dictionary of the record metadata.
:param bucket: The created bucket for the record.
"""
pass

def get_record_metadata(self):
"""Get Record Metadata instance for deposit."""
return RecordMetadata.query.filter_by(id=self.id).one_or_none()
Expand Down

0 comments on commit f639ed9

Please sign in to comment.