Skip to content

Commit 5c598c7

Browse files
committed
rm vfabu + addressing @wasade and @josenavas comments + fix errors
1 parent f7b61e7 commit 5c598c7

File tree

2 files changed

+27
-35
lines changed

2 files changed

+27
-35
lines changed

qiita_pet/handlers/download.py

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,13 @@ def get(self, study_id):
5757
str(study_id)))
5858

5959
study = Study(study_id)
60-
user = self.current_user
6160
basedir = get_db_files_base_dir()
6261
basedir_len = len(basedir) + 1
6362
# loop over artifacts and retrieve those that we have access to
6463
to_download = []
65-
vfabu = validate_filepath_access_by_user
6664
for a in study.artifacts():
6765
if a.artifact_type == 'BIOM':
68-
to_add = True
6966
for i, (fid, path, data_type) in enumerate(a.filepaths):
70-
# validate access only of the first artifact filepath,
71-
# the rest have the same permissions
72-
if (i == 0 and not vfabu(user, fid)):
73-
to_add = False
74-
break
7567
# ignore if tgz as they could create problems and the
7668
# raw data is in the folder
7769
if data_type == 'tgz':
@@ -97,16 +89,15 @@ def get(self, study_id):
9789
# how to trigger it
9890
to_download.append((path, path, path))
9991

100-
if to_add:
101-
for pt in a.prep_templates:
102-
qmf = pt.qiime_map_fp
103-
if qmf is not None:
104-
sqmf = qmf
105-
if qmf.startswith(basedir):
106-
sqmf = qmf[basedir_len:]
107-
to_download.append(
108-
(qmf, sqmf, 'mapping_files/%s_mapping_file.txt'
109-
% a.id))
92+
for pt in a.prep_templates:
93+
qmf = pt.qiime_map_fp
94+
if qmf is not None:
95+
sqmf = qmf
96+
if qmf.startswith(basedir):
97+
sqmf = qmf[basedir_len:]
98+
to_download.append(
99+
(qmf, sqmf, 'mapping_files/%s_mapping_file.txt'
100+
% a.id))
110101

111102
# If we don't have nginx, write a file that indicates this
112103
all_files = '\n'.join(["- %s /protected/%s %s" % (getsize(fp), sfp, n)
@@ -172,16 +163,9 @@ def get(self, study_id):
172163
basedir_len = len(basedir) + 1
173164
# loop over artifacts and retrieve raw data (no parents)
174165
to_download = []
175-
vfabu = validate_filepath_access_by_user
176166
for a in study.artifacts():
177167
if not a.parents:
178-
to_add = True
179168
for i, (fid, path, data_type) in enumerate(a.filepaths):
180-
# validate access only of the first artifact filepath,
181-
# the rest have the same permissions
182-
if (i == 0 and not vfabu(user, fid)):
183-
to_add = False
184-
break
185169
if data_type == 'directory':
186170
# If we have a directory, we actually need to list
187171
# all the files from the directory so NGINX can
@@ -203,16 +187,15 @@ def get(self, study_id):
203187
# how to trigger it
204188
to_download.append((path, path, path))
205189

206-
if to_add:
207-
for pt in a.prep_templates:
208-
qmf = pt.qiime_map_fp
209-
if qmf is not None:
210-
sqmf = qmf
211-
if qmf.startswith(basedir):
212-
sqmf = qmf[basedir_len:]
213-
to_download.append(
214-
(qmf, sqmf, 'mapping_files/%s_mapping_file.txt'
215-
% a.id))
190+
for pt in a.prep_templates:
191+
qmf = pt.qiime_map_fp
192+
if qmf is not None:
193+
sqmf = qmf
194+
if qmf.startswith(basedir):
195+
sqmf = qmf[basedir_len:]
196+
to_download.append(
197+
(qmf, sqmf, 'mapping_files/%s_mapping_file.txt'
198+
% a.id))
216199

217200
# If we don't have nginx, write a file that indicates this
218201
# Note that this configuration will automatically create and download

qiita_pet/test/test_download.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from qiita_pet.test.tornado_test_base import TestHandlerBase
2020
from qiita_pet.handlers.base_handlers import BaseHandler
2121
from qiita_db.user import User
22+
from qiita_db.study import Study
2223
from qiita_db.artifact import Artifact
2324
from qiita_db.software import Parameters, Command
2425

@@ -170,6 +171,14 @@ def tearDown(self):
170171
remove(fp)
171172

172173
def test_download_raw_data(self):
174+
# it's possible that one of the tests is deleting the raw data
175+
# so we will make sure that the files exists so this test passes
176+
all_files = [fp for a in Study(1).artifacts()
177+
for _, fp, _ in a.filepaths]
178+
for fp in all_files:
179+
if not exists(fp):
180+
with open(fp, 'w') as f:
181+
f.write('test`')
173182
response = self.get('/download_raw_data/1')
174183
self.assertEqual(response.code, 200)
175184

0 commit comments

Comments
 (0)