Skip to content

Commit 1f39e37

Browse files
committed
records: files update on publishing edited
Signed-off-by: Parth Shandilya <[email protected]>
1 parent 83582cb commit 1f39e37

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cap/modules/deposit/api.py

+11
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ def permissions(self, pid=None):
232232
def _publish_edited(self):
233233
record = super(CAPDeposit, self)._publish_edited()
234234
record._add_deposit_permissions(record, record.id)
235+
with db.session.begin_nested():
236+
if self.files and record.files.bucket is not None:
237+
# Unlock the record bucket
238+
record.files.bucket.locked = False
239+
# Lock the deposit's files bucket
240+
self.files.bucket.locked = True
241+
# Sync the record files with the deposit files
242+
self.files.bucket.sync(record.files.bucket)
243+
# lock the record bucket after update
244+
record.files.bucket.locked = True
245+
db.session.commit()
235246

236247
if record["_experiment"]:
237248
record._add_experiment_permissions(record, record.id)

tests/integration/deposits/test_edit_published_deposit.py

+25
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
# or submit itself to any jurisdiction.
2525
"""Integration tests for record edit."""
2626

27+
from io import BytesIO
28+
2729

2830
###########################################
2931
# api/deposits/{pid}/actions/edit [POST]
@@ -130,3 +132,26 @@ def test_edit_record(client, create_deposit, users, auth_headers_for_superuser):
130132
.format(depid)
131133
}
132134
}
135+
136+
137+
def test_edit_record_with_uploading_new_files(client, users, auth_headers_for_user, create_deposit):
138+
owner = users['cms_user']
139+
deposit = create_deposit(owner, 'test-analysis-v0.0.1')
140+
deposit.files['file_1.txt'] = BytesIO(b'Hello world!')
141+
pid = deposit['_deposit']['id']
142+
143+
client.post('/deposits/{}/actions/publish'.format(pid),
144+
headers=auth_headers_for_user(owner))
145+
146+
client.post('/deposits/{}/actions/edit'.format(pid),
147+
headers=auth_headers_for_user(owner))
148+
149+
bucket = deposit.files.bucket
150+
client.put('/files/{}/file_2.txt'.format(bucket),
151+
input_stream=BytesIO(b'Hello brave new world!'),
152+
headers=auth_headers_for_user(owner))
153+
154+
resp = client.post('/deposits/{}/actions/publish'.format(pid),
155+
headers=auth_headers_for_user(owner))
156+
157+
assert len(resp.json['files']) == 2

0 commit comments

Comments
 (0)