BE VERY CAREFUL where you create a new LdapService() - construction is expensive.

Adding a few more details to the "csv" endpoint for RRT.
This commit is contained in:
Dan Funk 2020-06-04 10:33:17 -04:00
parent bbcbfef1ba
commit 68aeaf1273
3 changed files with 16 additions and 8 deletions

View File

@ -49,6 +49,7 @@ def get_csv():
last_task = find_task(data['last_task']['__uuid__'], data['task_tree'])
personnel = extract_value(last_task, 'personnel')
training_val = extract_value(last_task, 'RequiredTraining')
pi_supervisor = extract_value(last_task, 'PISupervisor')['value']
review_complete = 'AllRequiredTraining' in training_val
pi_uid = workflow.study.primary_investigator_id
pi_details = ldapService.user_info(pi_uid)
@ -59,14 +60,22 @@ def get_csv():
details.append(ldapService.user_info(uid))
for person in details:
output.append({
record = {
"study_id": approval.study_id,
"pi_uid": pi_details.uid,
"pi": pi_details.display_name,
"name": person.display_name,
"uid": person.uid,
"email": person.email_address,
"supervisor": "",
"review_complete": review_complete,
})
}
# We only know the PI's supervisor.
if person.uid == pi_details.uid:
record["supervisor"] = pi_supervisor
output.append(record)
except Exception as e:
errors.append("Error pulling data for workflow #%i: %s" % (approval.workflow_id, str(e)))
return {"results": output, "errors": errors }

View File

@ -48,6 +48,7 @@ class ApprovalModel(db.Model):
class Approval(object):
ldap_service = LdapService()
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
@ -71,11 +72,9 @@ class Approval(object):
if model.study:
instance.title = model.study.title
ldap_service = LdapService()
try:
instance.approver = ldap_service.user_info(model.approver_uid)
instance.primary_investigator = ldap_service.user_info(model.study.primary_investigator_id)
instance.approver = Approval.ldap_service.user_info(model.approver_uid)
instance.primary_investigator = Approval.ldap_service.user_info(model.study.primary_investigator_id)
except ApiError as ae:
app.logger.error("Ldap lookup failed for approval record %i" % model.id)

View File

@ -26,6 +26,7 @@ from crc.models.approval import Approval
class StudyService(object):
"""Provides common tools for working with a Study"""
ldap_service = LdapService()
@staticmethod
def get_studies_for_user(user):
@ -206,8 +207,7 @@ class StudyService(object):
@staticmethod
def get_ldap_dict_if_available(user_id):
try:
ldap_service = LdapService()
return LdapSchema().dump(ldap_service.user_info(user_id))
return LdapSchema().dump(StudyService.ldap_service.user_info(user_id))
except ApiError as ae:
app.logger.info(str(ae))
return {"error": str(ae)}