2021-02-24 17:05:06 +00:00
|
|
|
from crc.api.common import ApiError
|
|
|
|
from crc.scripts.script import Script
|
|
|
|
from crc.services.study_service import StudyService
|
|
|
|
|
|
|
|
|
|
|
|
class UpdateStudyAssociates(Script):
|
|
|
|
argument_error_message = "You must supply at least one argument to the " \
|
|
|
|
"update_study_associates task, an array of objects in the form " \
|
|
|
|
"{'uid':'someid', 'role': 'text', 'send_email: 'boolean', " \
|
|
|
|
"'access':'boolean'} "
|
|
|
|
|
|
|
|
def get_description(self):
|
2021-09-22 16:12:26 +00:00
|
|
|
return """Allows you to associate other users with a study - only 'uid' is required in the
|
2021-02-24 17:05:06 +00:00
|
|
|
incoming dictionary, but will be useless without other information - all values will default to
|
|
|
|
false or blank
|
|
|
|
|
|
|
|
An empty list will delete the existing Associated list (except owner)
|
|
|
|
|
|
|
|
Each UID will be validated vs ldap and will raise an error if the uva_uid is not found. This supplied list will replace
|
|
|
|
any
|
|
|
|
associations already in place.
|
|
|
|
|
|
|
|
example : update_study_associates([{'uid':'sbp3ey','role':'Unicorn Herder', 'send_email': False, 'access':True}])
|
|
|
|
|
|
|
|
"""
|
2021-06-01 15:46:43 +00:00
|
|
|
|
|
|
|
def validate_arg(self, arg):
|
|
|
|
if not isinstance(arg, list):
|
2021-02-24 17:05:06 +00:00
|
|
|
raise ApiError("invalid parameter", "This function is expecting a list of dictionaries")
|
2021-06-01 15:46:43 +00:00
|
|
|
if len(arg[0]) > 0:
|
|
|
|
if not len(arg) > 0 and not isinstance(arg[0], dict):
|
|
|
|
raise ApiError("invalid paramemter", "This function is expecting a list of dictionaries")
|
2021-02-24 17:05:06 +00:00
|
|
|
|
|
|
|
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
2021-06-01 15:46:43 +00:00
|
|
|
if len(args) == 0:
|
|
|
|
items = []
|
|
|
|
else:
|
|
|
|
items = args[0]
|
|
|
|
self.validate_arg(items)
|
|
|
|
return all([x.get('uid', False) for x in items])
|
2021-02-24 17:05:06 +00:00
|
|
|
|
|
|
|
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
2021-06-01 15:46:43 +00:00
|
|
|
if len(args) == 0:
|
|
|
|
access_list = []
|
|
|
|
else:
|
|
|
|
access_list = args[0]
|
|
|
|
self.validate_arg(access_list)
|
|
|
|
return StudyService.update_study_associates(study_id, access_list)
|