Skip to content

Commit e11a68e

Browse files
committed
Merge branch 'release/2.025.43' into dev-1358-erase-anonymous-exports
2 parents 6dc9562 + 5c1ba9b commit e11a68e

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

jsapp/js/components/formLanding/formLanding.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ class FormLanding extends React.Component {
246246
<bem.FormView__label>
247247
<ActionIcon
248248
variant='transparent'
249+
onClick={() => {
250+
this.saveCloneAs(item.uid)
251+
}}
249252
tooltip={t('Clone this version as a new project')}
250253
iconName='duplicate'
251254
size='md'

kpi/models/import_export_task.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,13 @@ def export_upload_to(self, filename):
497497
more information, see
498498
https://docs.djangoproject.com/en/1.8/topics/migrations/#serializing-values
499499
"""
500+
501+
if hasattr(self, 'asset'):
502+
return posixpath.join(self.user.username, 'exports', self.asset.uid, filename)
503+
504+
if getattr(self, 'asset_uid', None):
505+
return posixpath.join(self.user.username, 'exports', self.asset_uid, filename)
506+
500507
return posixpath.join(self.user.username, 'exports', filename)
501508

502509

kpi/tests/api/v1/test_api_assets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ def test_owner_can_create_and_delete_export(self):
388388
"inline; filename*=utf-8''", ''
389389
)
390390
)
391-
file_path = export_upload_to(self, file_name)
391+
export = SubmissionExportTask.objects.get(uid=detail_response.data['uid'])
392+
file_path = export_upload_to(export, file_name)
392393

393394
detail_url = reverse('submissionexporttask-detail', kwargs={
394395
'uid': detail_response.data['uid']

kpi/tests/api/v2/test_api_exports.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def test_create_export_anon(self):
147147
download_response = self.client.get(download_url)
148148
assert download_response.status_code == status.HTTP_200_OK
149149

150+
self.asset.remove_perm(anon, PERM_VIEW_SUBMISSIONS)
151+
download_response = self.client.get(download_url)
152+
assert download_response.status_code == status.HTTP_403_FORBIDDEN
153+
150154
def test_export_task_list_anotheruser(self):
151155
for _type in ['csv', 'xls', 'spss_labels']:
152156
self._create_export_task(_type=_type)

kpi/utils/private_storage.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# coding: utf-8
2+
import re
3+
24
from rest_framework.request import Request as DRFRequest
35
from rest_framework.settings import api_settings
46

7+
from kpi.constants import PERM_VIEW_SUBMISSIONS, PERM_PARTIAL_SUBMISSIONS
8+
from kpi.models import Asset
59
from kpi.utils.object_permission import get_database_user
610

711

@@ -37,9 +41,21 @@ def superuser_or_username_matches_prefix(private_file):
3741
if user.is_superuser:
3842
return True
3943

40-
if private_file.relative_name.startswith(
41-
'{}/'.format(user.username)
42-
):
44+
if private_file.relative_name.startswith(f'{user.username}/'):
45+
filename_regex = rf'{user.username}/exports/(a[^/]*)/.*'
46+
match = re.search(filename_regex, private_file.relative_name)
47+
if match:
48+
uid = match.groups()[0]
49+
# Only loads what's needed for a permission check
50+
a = (
51+
Asset.objects.only('pk', 'owner_id', 'uid')
52+
.select_related('owner')
53+
.get(uid=uid)
54+
)
55+
return (
56+
a.has_perm(user_obj=user, perm=PERM_VIEW_SUBMISSIONS)
57+
or a.has_perm(user_obj=user, perm=PERM_PARTIAL_SUBMISSIONS)
58+
)
4359
return True
4460

4561
return False

0 commit comments

Comments
 (0)