本文整理汇总了Python中qiita_db.study.Study.has_access方法的典型用法代码示例。如果您正苦于以下问题:Python Study.has_access方法的具体用法?Python Study.has_access怎么用?Python Study.has_access使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qiita_db.study.Study
的用法示例。
在下文中一共展示了Study.has_access方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sample_template_checks
# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import has_access [as 别名]
def sample_template_checks(study_id, user, check_exists=False):
"""Performs different checks and raises errors if any of the checks fail
Parameters
----------
study_id : int
The study id
user : qiita_db.user.User
The user trying to access the study
check_exists : bool, optional
If true, check if the sample template exists
Raises
------
HTTPError
404 if the study does not exist
403 if the user does not have access to the study
404 if check_exists == True and the sample template doesn't exist
"""
try:
study = Study(int(study_id))
except QiitaDBUnknownIDError:
raise HTTPError(404, reason='Study does not exist')
if not study.has_access(user):
raise HTTPError(403, reason='User does not have access to study')
# Check if the sample template exists
if check_exists and not SampleTemplate.exists(study_id):
raise HTTPError(404, reason="Study %s doesn't have sample information"
% study_id)
示例2: check_access
# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import has_access [as 别名]
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 does not have access to study'}
return {}
示例3: get
# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import has_access [as 别名]
def get(self, arguments):
study_id = int(self.get_argument('study_id'))
# this block is tricky because you can either pass the sample or the
# prep template and if none is passed then we will let an exception
# be raised because template will not be declared for the logic below
if self.get_argument('prep_template', None):
template = PrepTemplate(int(self.get_argument('prep_template')))
if self.get_argument('sample_template', None):
template = None
tid = int(self.get_argument('sample_template'))
try:
template = SampleTemplate(tid)
except QiitaDBUnknownIDError:
raise HTTPError(404, "SampleTemplate %d does not exist" % tid)
study = Study(template.study_id)
# check whether or not the user has access to the requested information
if not study.has_access(User(self.current_user)):
raise HTTPError(403, "You do not have access to access this "
"information.")
df = dataframe_from_template(template)
stats = stats_from_df(df)
self.render('metadata_summary.html', user=self.current_user,
study_title=study.title, stats=stats,
study_id=study_id)
示例4: get
# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import has_access [as 别名]
def get(self, arguments):
study_id = int(self.get_argument('study_id'))
# Get the arguments
prep_template = self.get_argument('prep_template', None)
sample_template = self.get_argument('sample_template', None)
if prep_template and sample_template:
raise HTTPError(500, "You should provide either a sample template "
"or a prep template, but not both")
elif prep_template:
# The prep template has been provided
template = self._get_template(PrepTemplate, prep_template)
back_button_path = (
"/study/description/%s?top_tab=prep_template_tab&sub_tab=%s"
% (study_id, template.id))
elif sample_template:
# The sample template has been provided
template = self._get_template(SampleTemplate, sample_template)
back_button_path = (
"/study/description/%s"
% study_id)
else:
# Neither a sample template or a prep template has been provided
# Fail nicely
raise HTTPError(500, "You should provide either a sample template "
"or a prep template")
study = Study(template.study_id)
# check whether or not the user has access to the requested information
if not study.has_access(self.current_user):
raise HTTPError(403, "You do not have access to access this "
"information.")
df = template.to_dataframe()
num_samples = df.shape[0]
stats = stats_from_df(df)
self.render('metadata_summary.html',
study_title=study.title, stats=stats,
num_samples=num_samples, back_button_path=back_button_path)
示例5: TestStudy
# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import has_access [as 别名]
#.........这里部分代码省略.........
exp = {
'metadata_complete': True, 'reprocess': False,
'timeseries_type': 'None',
'pmid': ['123456', '7891011'],
'study_title': 'Identification of the Microbiomes for Cannabis '
'Soils'}
self.assertItemsEqual(obs, exp)
# Test get specific keys for all studies
info = {
'timeseries_type_id': 1,
'lab_person_id': None,
'principal_investigator_id': 3,
'metadata_complete': False,
'mixs_compliant': True,
'study_description': 'desc',
'study_alias': 'alias',
'study_abstract': 'abstract'}
user = User('[email protected]')
Study.create(user, 'test_study_1', efo=[1], info=info)
obs = Study.get_info(info_cols=exp_keys)
exp = [[True, ['123456', '7891011'], False,
'Identification of the Microbiomes for Cannabis Soils',
'None'],
[False, None, False, 'test_study_1', 'None']]
self.assertEqual(obs, exp)
# test portal restriction working
qiita_config.portal = 'EMP'
with self.assertRaises(QiitaDBError):
Study.get_info([1])
def test_has_access_public(self):
self._change_processed_data_status('public')
qiita_config.portal = 'QIITA'
self.assertTrue(self.study.has_access(User("[email protected]")))
qiita_config.portal = 'EMP'
with self.assertRaises(QiitaDBError):
Study(1).has_access(User("[email protected]"))
def test_has_access_no_public(self):
self._change_processed_data_status('public')
self.assertFalse(self.study.has_access(User("[email protected]"), True))
def test_owner(self):
self.assertEqual(self.study.owner, "[email protected]")
def test_share(self):
# Clear all sharing associations
self._change_processed_data_status('sandbox')
self.conn_handler.execute("delete from qiita.study_users")
self.assertEqual(self.study.shared_with, [])
# Try to share with the owner, which should not work
self.study.share(User("[email protected]"))
self.assertEqual(self.study.shared_with, [])
# Then share the study with [email protected]
self.study.share(User("[email protected]"))
self.assertEqual(self.study.shared_with, ["[email protected]"])
def test_unshare(self):
self._change_processed_data_status('sandbox')
self.study.unshare(User("[email protected]"))
示例6: study_get_req
# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import has_access [as 别名]
def study_get_req(study_id, user_id):
"""Returns information available for the given study
Parameters
----------
study_id : int
Study id to get prep template info for
user_id : str
User requesting the info
Returns
-------
dict
Data types information in the form
{'status': status,
'message': message,
'info': dict of objects
status can be success, warning, or error depending on result
message has the warnings or errors
info contains study information seperated by data type, in the form
{col_name: value, ...} with value being a string, int, or list of
strings or ints
"""
access_error = check_access(study_id, user_id)
if access_error:
return access_error
# Can only pass ids over API, so need to instantiate object
study = Study(study_id)
study_info = study.info
# Add needed info that is not part of the initial info pull
study_info['publication_doi'] = []
study_info['publication_pid'] = []
for pub, is_doi in study.publications:
if is_doi:
study_info['publication_doi'].append(pub)
else:
study_info['publication_pid'].append(pub)
study_info['study_id'] = study.id
study_info['study_title'] = study.title
study_info['shared_with'] = [s.id for s in study.shared_with]
study_info['status'] = study.status
study_info['ebi_study_accession'] = study.ebi_study_accession
study_info['ebi_submission_status'] = study.ebi_submission_status
# Clean up StudyPerson objects to string for display
pi = study_info['principal_investigator']
study_info['principal_investigator'] = {
'name': pi.name,
'email': pi.email,
'affiliation': pi.affiliation}
lab_person = study_info['lab_person']
if lab_person:
study_info['lab_person'] = {
'name': lab_person.name,
'email': lab_person.email,
'affiliation': lab_person.affiliation}
samples = study.sample_template
study_info['num_samples'] = 0 if samples is None else len(list(samples))
study_info['owner'] = study.owner.id
# Study.has_access no_public=True, will return True only if the user_id is
# the owner of the study or if the study is shared with the user_id
study_info['has_access_to_raw_data'] = study.has_access(
User(user_id), True)
study_info['show_biom_download_button'] = 'BIOM' in [
a.artifact_type for a in study.artifacts()]
study_info['show_raw_download_button'] = any([
True for pt in study.prep_templates() if pt.artifact is not None])
# getting study processing status from redis
processing = False
study_info['level'] = ''
study_info['message'] = ''
job_info = r_client.get(STUDY_KEY_FORMAT % study_id)
if job_info:
job_info = defaultdict(lambda: '', loads(job_info))
job_id = job_info['job_id']
job = ProcessingJob(job_id)
job_status = job.status
processing = job_status not in ('success', 'error')
if processing:
study_info['level'] = 'info'
study_info['message'] = 'This study is currently being processed'
elif job_status == 'error':
study_info['level'] = 'danger'
study_info['message'] = job.log.msg.replace('\n', '</br>')
else:
study_info['level'] = job_info['alert_type']
study_info['message'] = job_info['alert_msg'].replace(
'\n', '</br>')
return {'status': 'success',
'message': '',
'study_info': study_info,
'editable': study.can_edit(User(user_id))}