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: files update on publishing edited #2806

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions cap/modules/deposit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ def permissions(self, pid=None):
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
25 changes: 25 additions & 0 deletions tests/integration/deposits/test_edit_published_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# or submit itself to any jurisdiction.
"""Integration tests for record edit."""

from io import BytesIO


###########################################
# api/deposits/{pid}/actions/edit [POST]
Expand Down Expand Up @@ -130,3 +132,26 @@ def test_edit_record(client, create_deposit, users, auth_headers_for_superuser):
.format(depid)
}
}


def test_edit_record_with_uploading_new_files(client, users, auth_headers_for_user, create_deposit):
owner = users['cms_user']
deposit = create_deposit(owner, 'test-analysis-v0.0.1')
deposit.files['file_1.txt'] = BytesIO(b'Hello world!')
pid = deposit['_deposit']['id']

client.post('/deposits/{}/actions/publish'.format(pid),
headers=auth_headers_for_user(owner))

client.post('/deposits/{}/actions/edit'.format(pid),
headers=auth_headers_for_user(owner))

bucket = deposit.files.bucket
client.put('/files/{}/file_2.txt'.format(bucket),
input_stream=BytesIO(b'Hello brave new world!'),
headers=auth_headers_for_user(owner))

resp = client.post('/deposits/{}/actions/publish'.format(pid),
headers=auth_headers_for_user(owner))

assert len(resp.json['files']) == 2
Loading