本文整理汇总了Python中qiita_pet.handlers.api_proxy.util.check_access函数的典型用法代码示例。如果您正苦于以下问题:Python check_access函数的具体用法?Python check_access怎么用?Python check_access使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_access函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check_permissions
def _check_permissions(self, sid):
# Check general access to study
study_info = check_access(sid, self.current_user.id)
if study_info:
raise HTTPError(405, reason="%s: %s, %s" % (
study_info['message'], self.current_user.email, sid))
return Study(sid)
示例2: artifact_get_prep_req
def artifact_get_prep_req(user_id, artifact_ids):
"""Returns all prep info sample ids for the given artifact_ids
Parameters
----------
user_id : str
user making the request
artifact_ids : list of int
list of artifact ids
Returns
-------
dict of objects
A dictionary containing the artifact information
{'status': status,
'message': message,
'data': {artifact_id: [prep info sample ids]}
"""
samples = {}
for aid in sorted(artifact_ids):
artifact = Artifact(aid)
access_error = check_access(artifact.study.id, user_id)
if access_error:
return access_error
samples[aid] = list(chain(
*[sorted(pt.keys()) for pt in Artifact(aid).prep_templates]))
return {'status': 'success', 'msg': '', 'data': samples}
示例3: artifact_delete_req
def artifact_delete_req(artifact_id, user_id):
"""Deletes the artifact
Parameters
----------
artifact_id : int
Artifact being acted on
user_id : str
The user requesting the action
Returns
-------
dict
Status of action, in the form {'status': status, 'message': msg}
status: status of the action, either success or error
message: Human readable message for status
"""
pd = Artifact(int(artifact_id))
pt_id = pd.prep_templates[0].id
access_error = check_access(pd.study.id, user_id)
if access_error:
return access_error
job_id = safe_submit(user_id, delete_artifact, artifact_id)
r_client.set(PREP_TEMPLATE_KEY_FORMAT % pt_id,
dumps({'job_id': job_id}))
return {'status': 'success',
'message': ''}
示例4: prep_template_get_req
def prep_template_get_req(prep_id, user_id):
"""Gets the json of the full prep template
Parameters
----------
prep_id : int
PrepTemplate id to get info for
user_id : str
User requesting the sample template info
Returns
-------
dict of objects
{'status': status,
'message': message,
'template': {sample: {column: value, ...}, ...}
"""
exists = _check_prep_template_exists(int(prep_id))
if exists['status'] != 'success':
return exists
prep = PrepTemplate(int(prep_id))
access_error = check_access(prep.study_id, user_id)
if access_error:
return access_error
df = prep.to_dataframe()
return {'status': 'success',
'message': '',
'template': df.to_dict(orient='index')}
示例5: study_delete_req
def study_delete_req(study_id, user_id):
"""Delete a given study
Parameters
----------
study_id : int
Study id to delete
user_id : str
User requesting the deletion
Returns
-------
dict
Status of deletion, in the format
{status: status,
message: message}
"""
access_error = check_access(study_id, user_id)
if access_error:
return access_error
qiita_plugin = Software.from_name_and_version('Qiita', 'alpha')
cmd = qiita_plugin.get_command('delete_study')
params = Parameters.load(cmd, values_dict={'study': study_id})
job = ProcessingJob.create(User(user_id), params, True)
# Store the job id attaching it to the sample template id
r_client.set(STUDY_KEY_FORMAT % study_id,
dumps({'job_id': job.id}))
job.submit()
return {'status': 'success', 'message': ''}
示例6: study_get_tags_request
def study_get_tags_request(user_id, study_id):
"""Retrieve available study tags for study_id
Parameters
----------
user_id : int
The id of the user performing the operation
study_id : int
The id of the study on which we will be performing the operation
Returns
-------
dict of {str, str}
A dictionary with the following keys:
- status: str, whether if the request is successful or not
- message: str, if the request is unsuccessful, a human readable error
- tags: [value, ..., ...]
"""
access_error = check_access(study_id, user_id)
if access_error:
return access_error
study = Study(study_id)
return {'status': 'success',
'message': '',
'tags': study.tags}
示例7: artifact_delete_req
def artifact_delete_req(artifact_id, user_id):
"""Deletes the artifact
Parameters
----------
artifact_id : int
Artifact being acted on
user_id : str
The user requesting the action
Returns
-------
dict
Status of action, in the form {'status': status, 'message': msg}
status: status of the action, either success or error
message: Human readable message for status
"""
pd = Artifact(int(artifact_id))
access_error = check_access(pd.study.id, user_id)
if access_error:
return access_error
try:
Artifact.delete(int(artifact_id))
except QiitaDBArtifactDeletionError as e:
return {'status': 'error',
'message': str(e)}
return {'status': 'success',
'message': ''}
示例8: prep_template_jobs_get_req
def prep_template_jobs_get_req(prep_id, user_id):
"""Returns graph of all artifacts created from the prep base artifact
Parameters
----------
prep_id : int
Prep template ID to get graph for
user_id : str
User making the request
Returns
-------
dict with the jobs information
Notes
-----
Nodes are identified by the corresponding Artifact ID.
"""
prep = PrepTemplate(int(prep_id))
access_error = check_access(prep.study_id, user_id)
if access_error:
return access_error
job_info = r_client.get(PREP_TEMPLATE_KEY_FORMAT % prep_id)
result = {}
if job_info:
job_info = defaultdict(lambda: '', loads(job_info))
job_id = job_info['job_id']
job = ProcessingJob(job_id)
result[job.id] = {'status': job.status, 'step': job.step,
'error': job.log.msg if job.log else ""}
return result
示例9: prep_template_filepaths_get_req
def prep_template_filepaths_get_req(prep_id, user_id):
"""Returns all filepaths attached to a prep template
Parameters
----------
prep_id : int
The current prep template id
user_id : int
The current user object id
Returns
-------
dict of objects
{'status': status,
'message': message,
'filepaths': [(filepath_id, filepath), ...]}
"""
exists = _check_prep_template_exists(int(prep_id))
if exists['status'] != 'success':
return exists
prep = PrepTemplate(int(prep_id))
access_error = check_access(prep.study_id, user_id)
if access_error:
return access_error
return {'status': 'success',
'message': '',
'filepaths': prep.get_filepaths()
}
示例10: prep_template_delete_req
def prep_template_delete_req(prep_id, user_id):
"""Delete the prep template
Parameters
----------
prep_id : int
The prep template to update
user_id : str
The current user object id
Returns
-------
dict of str
{'status': status,
'message': message}
"""
exists = _check_prep_template_exists(int(prep_id))
if exists['status'] != 'success':
return exists
prep = PrepTemplate(int(prep_id))
access_error = check_access(prep.study_id, user_id)
if access_error:
return access_error
msg = ''
status = 'success'
try:
PrepTemplate.delete(prep.id)
except Exception as e:
msg = str(e)
status = 'error'
return {'status': status,
'message': msg}
示例11: artifact_patch_request
def artifact_patch_request(user_id, req_op, req_path, req_value=None,
req_from=None):
"""Modifies an attribute of the artifact
Parameters
----------
user_id : str
The id of the user performing the patch operation
req_op : str
The operation to perform on the artifact
req_path : str
The prep information and attribute to patch
req_value : str, optional
The value that needs to be modified
req_from : str, optional
The original path of the element
Returns
-------
dict of {str, str}
A dictionary with the following keys:
- status: str, whether if the request is successful or not
- message: str, if the request is unsuccessful, a human readable error
"""
if req_op == 'replace':
req_path = [v for v in req_path.split('/') if v]
if len(req_path) != 2:
return {'status': 'error',
'message': 'Incorrect path parameter'}
artifact_id = req_path[0]
attribute = req_path[1]
# Check if the user actually has access to the artifact
artifact = Artifact(artifact_id)
access_error = check_access(artifact.study.id, user_id)
if access_error:
return access_error
if not req_value:
return {'status': 'error',
'message': 'A value is required'}
if attribute == 'name':
artifact.name = req_value
return {'status': 'success',
'message': ''}
else:
# We don't understand the attribute so return an error
return {'status': 'error',
'message': 'Attribute "%s" not found. '
'Please, check the path parameter' % attribute}
else:
return {'status': 'error',
'message': 'Operation "%s" not supported. '
'Current supported operations: replace' % req_op}
示例12: study_tags_patch_request
def study_tags_patch_request(user_id, study_id,
req_op, req_path, req_value=None, req_from=None):
"""Modifies an attribute of the artifact
Parameters
----------
user_id : int
The id of the user performing the patch operation
study_id : int
The id of the study on which we will be performing the patch operation
req_op : str
The operation to perform on the study
req_path : str
The attribute to patch
req_value : str, optional
The value that needs to be modified
req_from : str, optional
The original path of the element
Returns
-------
dict of {str, str}
A dictionary with the following keys:
- status: str, whether if the request is successful or not
- message: str, if the request is unsuccessful, a human readable error
"""
if req_op == 'replace':
req_path = [v for v in req_path.split('/') if v]
if len(req_path) != 1:
return {'status': 'error',
'message': 'Incorrect path parameter'}
attribute = req_path[0]
# Check if the user actually has access to the study
access_error = check_access(study_id, user_id)
if access_error:
return access_error
study = Study(study_id)
if attribute == 'tags':
message = study.update_tags(User(user_id), req_value)
return {'status': 'success',
'message': message}
else:
# We don't understand the attribute so return an error
return {'status': 'error',
'message': 'Attribute "%s" not found. '
'Please, check the path parameter' % attribute}
else:
return {'status': 'error',
'message': 'Operation "%s" not supported. '
'Current supported operations: replace' % req_op}
示例13: prep_template_graph_get_req
def prep_template_graph_get_req(prep_id, user_id):
"""Returns graph of all artifacts created from the prep base artifact
Parameters
----------
prep_id : int
Prep template ID to get graph for
user_id : str
User making the request
Returns
-------
dict of lists of tuples
A dictionary containing the edge list representation of the graph,
and the node labels. Formatted as:
{'status': status,
'message': message,
'edge_list': [(0, 1), (0, 2)...],
'node_labels': [(0, 'label0'), (1, 'label1'), ...]}
Notes
-----
Nodes are identified by the corresponding Artifact ID.
"""
exists = _check_prep_template_exists(int(prep_id))
if exists['status'] != 'success':
return exists
prep = PrepTemplate(int(prep_id))
access_error = check_access(prep.study_id, user_id)
if access_error:
return access_error
# We should filter for only the public artifacts if the user
# doesn't have full access to the study
full_access = Study(prep.study_id).can_edit(User(user_id))
artifact = prep.artifact
if artifact is None:
return {'edges': [], 'nodes': [],
'status': 'success', 'message': ''}
G = artifact.descendants_with_jobs
nodes, edges, wf_id = get_network_nodes_edges(G, full_access)
return {'edges': edges,
'nodes': nodes,
'workflow': wf_id,
'status': 'success',
'message': ''}
示例14: prep_template_graph_get_req
def prep_template_graph_get_req(prep_id, user_id):
"""Returns graph of all artifacts created from the prep base artifact
Parameters
----------
prep_id : int
Prep template ID to get graph for
user_id : str
User making the request
Returns
-------
dict of lists of tuples
A dictionary containing the edge list representation of the graph,
and the node labels. Formatted as:
{'status': status,
'message': message,
'edge_list': [(0, 1), (0, 2)...],
'node_labels': [(0, 'label0'), (1, 'label1'), ...]}
Notes
-----
Nodes are identified by the corresponding Artifact ID.
"""
exists = _check_prep_template_exists(int(prep_id))
if exists['status'] != 'success':
return exists
prep = PrepTemplate(int(prep_id))
access_error = check_access(prep.study_id, user_id)
if access_error:
return access_error
# We should filter for only the public artifacts if the user
# doesn't have full access to the study
full_access = Study(prep.study_id).can_edit(User(user_id))
G = prep.artifact.descendants
node_labels = [(n.id, ' - '.join([n.name, n.artifact_type]))
for n in G.nodes()
if full_access or n.visibility == 'public']
node_ids = [id_ for id_, label in node_labels]
edge_list = [(n.id, m.id) for n, m in G.edges()
if n.id in node_ids and m.id in node_ids]
return {'status': 'success',
'message': '',
'edge_list': edge_list,
'node_labels': node_labels}
示例15: prep_template_summary_get_req
def prep_template_summary_get_req(prep_id, user_id):
"""Get the summarized prep template data for each metadata column
Parameters
----------
prep_id : int
PrepTemplate id to get info for
user_id : str
User requesting the sample template info
Returns
-------
dict of objects
Dictionary object where the keys are the metadata categories
and the values are list of tuples. Each tuple is an observed value in
the category and the number of times its seen.
Format {'status': status,
'message': message,
'num_samples': value,
'category': [(val1, count1), (val2, count2), ...],
'editable': bool}
"""
exists = _check_prep_template_exists(int(prep_id))
if exists['status'] != 'success':
return exists
prep = PrepTemplate(int(prep_id))
access_error = check_access(prep.study_id, user_id)
if access_error:
return access_error
editable = Study(prep.study_id).can_edit(User(user_id))
df = prep.to_dataframe()
out = {'num_samples': df.shape[0],
'summary': [],
'status': 'success',
'message': '',
'editable': editable}
cols = sorted(list(df.columns))
for column in cols:
counts = df[column].value_counts()
out['summary'].append(
(str(column), [(str(key), counts[key])
for key in natsorted(counts.index)]))
return out