Skip to content

Commit f639ed9

Browse files
committed
records: override new bucket methods
Signed-off-by: Parth Shandilya <[email protected]>
1 parent 0b4852a commit f639ed9

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

cap/modules/deposit/api.py

+11
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,17 @@ def _publish_edited(self):
233233
record = super(CAPDeposit, self)._publish_edited()
234234
record._add_deposit_permissions(record, record.id)
235235

236+
with db.session.begin_nested():
237+
if self.files and record.files.bucket is not None:
238+
# Unlock the record bucket
239+
record.files.bucket.locked = False
240+
# Lock the deposit's files bucket
241+
self.files.bucket.locked = True
242+
# Sync the record files with the deposit files
243+
self.files.bucket.sync(record.files.bucket)
244+
# lock the record bucket after update
245+
record.files.bucket.locked = True
246+
db.session.commit()
236247
if record["_experiment"]:
237248
record._add_experiment_permissions(record, record.id)
238249

cap/modules/records/api.py

+40
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,46 @@ def RECORD_ACTION_NEEDS(id):
6868
class CAPRecord(Record):
6969
"""Record API class for CAP."""
7070

71+
@classmethod
72+
def create_bucket(cls, data):
73+
"""Create a bucket for this record.
74+
75+
Override this method to provide more advanced bucket creation
76+
capabilities. This method may return a new or existing bucket, or may
77+
return None, in case no bucket should be created.
78+
"""
79+
return None
80+
81+
@classmethod
82+
def load_bucket(cls, record):
83+
"""Load the bucket id from the record metadata.
84+
85+
Override this method to provide custom behavior for retrieving the
86+
bucket id from the record metadata. By default the bucket id is
87+
retrieved from the ``_bucket`` key. If you override this method, make
88+
sure you also override :py:data:`Record.dump_bucket()`.
89+
90+
:param record: A record instance.
91+
"""
92+
return
93+
94+
@classmethod
95+
def dump_bucket(cls, data, bucket):
96+
"""Dump the bucket id into the record metadata.
97+
98+
Override this method to provide custom behavior for storing the bucket
99+
id in the record metadata. By default the bucket id is stored in the
100+
``_bucket`` key. If you override this method, make sure you also
101+
override :py:data:`Record.load_bucket()`.
102+
103+
This method is called after the bucket is created, but before the
104+
record is created in the database.
105+
106+
:param data: A dictionary of the record metadata.
107+
:param bucket: The created bucket for the record.
108+
"""
109+
pass
110+
71111
def get_record_metadata(self):
72112
"""Get Record Metadata instance for deposit."""
73113
return RecordMetadata.query.filter_by(id=self.id).one_or_none()

0 commit comments

Comments
 (0)