2021-02-24 17:05:06 +00:00
|
|
|
from crc.api.common import ApiError
|
2021-08-10 20:16:08 +00:00
|
|
|
from crc.models.study import StudyAssociatedSchema
|
2021-02-24 17:05:06 +00:00
|
|
|
from crc.scripts.script import Script
|
|
|
|
from crc.services.study_service import StudyService
|
|
|
|
|
|
|
|
|
2021-08-10 20:16:08 +00:00
|
|
|
class GetStudyAssociate(Script):
|
2021-02-24 17:05:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_description(self):
|
|
|
|
return """
|
2021-08-10 20:16:08 +00:00
|
|
|
Returns how a single person is associated with a study and what access they need,
|
|
|
|
or raises an error if the person is not associated with the study.
|
2021-02-24 17:05:06 +00:00
|
|
|
example : get_study_associate('sbp3ey') => {'uid':'sbp3ey','role':'Unicorn Herder', 'send_email': False,
|
|
|
|
'access':True}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
2021-06-04 15:44:55 +00:00
|
|
|
if len(args) < 1:
|
|
|
|
raise ApiError('no_user_id_specified', 'A uva uid is the sole argument to this function')
|
|
|
|
return {'uid': 'sbp3ey', 'role': 'Unicorn Herder', 'send_email': False, 'access': True}
|
2021-02-24 17:05:06 +00:00
|
|
|
|
|
|
|
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
2021-06-04 15:44:55 +00:00
|
|
|
if len(args) < 1:
|
2021-02-24 17:05:06 +00:00
|
|
|
raise ApiError('no_user_id_specified', 'A uva uid is the sole argument to this function')
|
2021-06-04 15:44:55 +00:00
|
|
|
if not isinstance(args[0], str):
|
2021-02-24 17:05:06 +00:00
|
|
|
raise ApiError('argument_should_be_string', 'A uva uid is always a string, please check type')
|
2021-08-10 20:16:08 +00:00
|
|
|
associate = StudyService.get_study_associate(study_id=study_id, uid=args[0])
|
|
|
|
return StudyAssociatedSchema().dump(associate)
|