Made a very stupid mistake with LDAP connections, pushing up quickly to production.
This commit is contained in:
parent
68aeaf1273
commit
50d2acac9c
|
@ -24,7 +24,8 @@ def get_approvals(everything=False):
|
||||||
|
|
||||||
def get_approvals_for_study(study_id=None):
|
def get_approvals_for_study(study_id=None):
|
||||||
db_approvals = ApprovalService.get_approvals_for_study(study_id)
|
db_approvals = ApprovalService.get_approvals_for_study(study_id)
|
||||||
approvals = [Approval.from_model(approval_model) for approval_model in db_approvals]
|
ldap_service = LdapService()
|
||||||
|
approvals = [Approval.from_model(approval_model, ldap_service) for approval_model in db_approvals]
|
||||||
results = ApprovalSchema(many=True).dump(approvals)
|
results = ApprovalSchema(many=True).dump(approvals)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
|
@ -48,13 +48,12 @@ class ApprovalModel(db.Model):
|
||||||
|
|
||||||
|
|
||||||
class Approval(object):
|
class Approval(object):
|
||||||
ldap_service = LdapService()
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.__dict__.update(kwargs)
|
self.__dict__.update(kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_model(cls, model: ApprovalModel):
|
def from_model(cls, model: ApprovalModel, ldap_service: LdapSchema):
|
||||||
# TODO: Reduce the code by iterating over model's dict keys
|
# TODO: Reduce the code by iterating over model's dict keys
|
||||||
instance = cls()
|
instance = cls()
|
||||||
instance.id = model.id
|
instance.id = model.id
|
||||||
|
@ -73,8 +72,8 @@ class Approval(object):
|
||||||
if model.study:
|
if model.study:
|
||||||
instance.title = model.study.title
|
instance.title = model.study.title
|
||||||
try:
|
try:
|
||||||
instance.approver = Approval.ldap_service.user_info(model.approver_uid)
|
instance.approver = ldap_service.user_info(model.approver_uid)
|
||||||
instance.primary_investigator = Approval.ldap_service.user_info(model.study.primary_investigator_id)
|
instance.primary_investigator = ldap_service.user_info(model.study.primary_investigator_id)
|
||||||
except ApiError as ae:
|
except ApiError as ae:
|
||||||
app.logger.error("Ldap lookup failed for approval record %i" % model.id)
|
app.logger.error("Ldap lookup failed for approval record %i" % model.id)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ from crc.models.approval import ApprovalModel, ApprovalStatus, ApprovalFile, App
|
||||||
from crc.models.study import StudyModel
|
from crc.models.study import StudyModel
|
||||||
from crc.models.workflow import WorkflowModel
|
from crc.models.workflow import WorkflowModel
|
||||||
from crc.services.file_service import FileService
|
from crc.services.file_service import FileService
|
||||||
|
from crc.services.ldap_service import LdapService
|
||||||
|
|
||||||
|
|
||||||
class ApprovalService(object):
|
class ApprovalService(object):
|
||||||
|
@ -27,11 +28,12 @@ class ApprovalService(object):
|
||||||
query=query.filter(ApprovalModel.status != ApprovalStatus.CANCELED.value)
|
query=query.filter(ApprovalModel.status != ApprovalStatus.CANCELED.value)
|
||||||
|
|
||||||
approvals = query.all()
|
approvals = query.all()
|
||||||
|
ldap_service = LdapService()
|
||||||
for approval_model in approvals:
|
for approval_model in approvals:
|
||||||
if approval_model.approver_uid == approver_uid:
|
if approval_model.approver_uid == approver_uid:
|
||||||
main_approval = Approval.from_model(approval_model)
|
main_approval = Approval.from_model(approval_model, ldap_service)
|
||||||
else:
|
else:
|
||||||
related_approvals.append(Approval.from_model(approval_model))
|
related_approvals.append(Approval.from_model(approval_model, ldap_service))
|
||||||
if not main_approval and len(related_approvals) > 0:
|
if not main_approval and len(related_approvals) > 0:
|
||||||
main_approval = related_approvals[0]
|
main_approval = related_approvals[0]
|
||||||
related_approvals = related_approvals[1:]
|
related_approvals = related_approvals[1:]
|
||||||
|
@ -68,11 +70,12 @@ class ApprovalService(object):
|
||||||
def get_approvals_for_study(study_id, include_cancelled=True):
|
def get_approvals_for_study(study_id, include_cancelled=True):
|
||||||
"""Returns an array of Approval objects for the study, it does not
|
"""Returns an array of Approval objects for the study, it does not
|
||||||
compute the related approvals."""
|
compute the related approvals."""
|
||||||
|
ldap_service = LdapService()
|
||||||
query = session.query(ApprovalModel).filter_by(study_id=study_id)
|
query = session.query(ApprovalModel).filter_by(study_id=study_id)
|
||||||
if not include_cancelled:
|
if not include_cancelled:
|
||||||
query = query.filter(ApprovalModel.status != ApprovalStatus.CANCELED.value)
|
query = query.filter(ApprovalModel.status != ApprovalStatus.CANCELED.value)
|
||||||
db_approvals = query.all()
|
db_approvals = query.all()
|
||||||
return [Approval.from_model(approval_model) for approval_model in db_approvals]
|
return [Approval.from_model(approval_model, ldap_service) for approval_model in db_approvals]
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue