Download this file

77 lines (65 with data), 2.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The Qiita Development Team.
#
# Distributed under the terms of the BSD 3-clause License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from os.path import exists, join
from qiita_db.exceptions import QiitaDBUnknownIDError
from qiita_db.study import Study
from qiita_db.user import User
from qiita_db.util import get_mountpoint
def check_access(study_id, user_id):
"""Checks if user given has access to the study given
Parameters
----------
study_id : int
ID of the study to check access to
user_id : str
ID of the user to check access for
Returns
-------
dict
Empty dict if access allowed, else a dict in the form
{'status': 'error',
'message': reason for error}
"""
try:
study = Study(int(study_id))
except QiitaDBUnknownIDError:
return {'status': 'error',
'message': 'Study does not exist'}
if not study.has_access(User(user_id)):
return {'status': 'error',
'message': 'User has insufficient permissions'}
return {}
def check_fp(study_id, filename):
"""Check whether an uploaded file exists
Parameters
----------
study_id : int
Study file uploaded to
filename : str
name of the uploaded file
Returns
-------
dict
{'status': status,
'message': msg,
'file': str}
file contains full filepath if status is success, otherwise it contains
the filename
"""
# Get the uploads folder
_, base_fp = get_mountpoint("uploads")[0]
# Get the path of the sample template in the uploads folder
fp_rsp = join(base_fp, str(study_id), filename)
if not exists(fp_rsp):
# The file does not exist, fail nicely
return {'status': 'error',
'message': 'file does not exist',
'file': filename}
return {'status': 'success',
'message': '',
'file': fp_rsp}