mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-21 20:28:10 +00:00
Missed committing a pile of changes last night.
This commit is contained in:
commit
4090667a5d
@ -808,12 +808,12 @@ paths:
|
|||||||
$ref: "#/components/schemas/Script"
|
$ref: "#/components/schemas/Script"
|
||||||
/approval:
|
/approval:
|
||||||
parameters:
|
parameters:
|
||||||
- name: approver_uid
|
- name: everything
|
||||||
in: query
|
in: query
|
||||||
required: false
|
required: false
|
||||||
description: Restrict results to a given approver uid, maybe we restrict the use of this at somepoint.
|
description: If set to true, returns all the approvals known to the system.
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: boolean
|
||||||
get:
|
get:
|
||||||
operationId: crc.api.approval.get_approvals
|
operationId: crc.api.approval.get_approvals
|
||||||
summary: Provides a list of workflows approvals
|
summary: Provides a list of workflows approvals
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from flask import g
|
||||||
|
|
||||||
from crc import app, db, session
|
from crc import app, db, session
|
||||||
|
|
||||||
from crc.api.common import ApiError, ApiErrorSchema
|
from crc.api.common import ApiError, ApiErrorSchema
|
||||||
@ -5,11 +7,11 @@ from crc.models.approval import Approval, ApprovalModel, ApprovalSchema
|
|||||||
from crc.services.approval_service import ApprovalService
|
from crc.services.approval_service import ApprovalService
|
||||||
|
|
||||||
|
|
||||||
def get_approvals(approver_uid=None):
|
def get_approvals(everything=False):
|
||||||
if not approver_uid:
|
if everything:
|
||||||
db_approvals = ApprovalService.get_all_approvals()
|
db_approvals = ApprovalService.get_all_approvals()
|
||||||
else:
|
else:
|
||||||
db_approvals = ApprovalService.get_approvals_per_user(approver_uid)
|
db_approvals = ApprovalService.get_approvals_per_user(g.user.uid)
|
||||||
approvals = [Approval.from_model(approval_model) for approval_model in db_approvals]
|
approvals = [Approval.from_model(approval_model) for approval_model in db_approvals]
|
||||||
|
|
||||||
results = ApprovalSchema(many=True).dump(approvals)
|
results = ApprovalSchema(many=True).dump(approvals)
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import json
|
|
||||||
|
|
||||||
import connexion
|
|
||||||
import flask
|
import flask
|
||||||
from flask import redirect, g, request
|
from flask import g, request
|
||||||
|
|
||||||
from crc import app, db
|
from crc import app, db
|
||||||
from crc.api.common import ApiError
|
from crc.api.common import ApiError
|
||||||
|
@ -68,31 +68,33 @@ class Approval(object):
|
|||||||
if model.study:
|
if model.study:
|
||||||
instance.title = model.study.title
|
instance.title = model.study.title
|
||||||
|
|
||||||
principal_investigator_id = model.study.primary_investigator_id
|
instance.approver = {}
|
||||||
instance.approver = {'uid': model.approver_uid}
|
|
||||||
instance.primary_investigator = {'uid': principal_investigator_id}
|
|
||||||
try:
|
try:
|
||||||
ldap_service = LdapService()
|
ldap_service = LdapService()
|
||||||
# Primary investigator details
|
user_info = ldap_service.user_info(model.approver_uid)
|
||||||
pi_info = ldap_service.user_info(principal_investigator_id)
|
|
||||||
instance.primary_investigator['uid'] = principal_investigator_id
|
|
||||||
instance.primary_investigator['display_name'] = pi_info.display_name
|
|
||||||
instance.primary_investigator['title'] = pi_info.title
|
|
||||||
instance.primary_investigator['department'] = pi_info.department
|
|
||||||
# Approver details
|
|
||||||
approver_info = ldap_service.user_info(model.approver_uid)
|
|
||||||
instance.approver['uid'] = model.approver_uid
|
instance.approver['uid'] = model.approver_uid
|
||||||
instance.approver['display_name'] = approver_info.display_name
|
instance.approver['display_name'] = user_info.display_name
|
||||||
instance.approver['title'] = approver_info.title
|
instance.approver['title'] = user_info.title
|
||||||
instance.approver['department'] = approver_info.department
|
instance.approver['department'] = user_info.department
|
||||||
except (ApiError, LDAPSocketOpenError) as exception:
|
except (ApiError, LDAPSocketOpenError) as exception:
|
||||||
instance.primary_investigator['display_name'] = 'Primary Investigator details'
|
user_info = None
|
||||||
instance.primary_investigator['department'] = 'currently not available'
|
instance.approver['display_name'] = 'Unknown'
|
||||||
instance.approver['display_name'] = 'Approver details'
|
|
||||||
instance.approver['department'] = 'currently not available'
|
instance.approver['department'] = 'currently not available'
|
||||||
|
|
||||||
# TODO: Organize it properly, move it to services
|
instance.primary_investigator = {}
|
||||||
# TODO: Rely on Dan's new service for file creation
|
try:
|
||||||
|
ldap_service = LdapService()
|
||||||
|
user_info = ldap_service.user_info(model.study.primary_investigator_id)
|
||||||
|
instance.primary_investigator['uid'] = model.approver_uid
|
||||||
|
instance.primary_investigator['display_name'] = user_info.display_name
|
||||||
|
instance.primary_investigator['title'] = user_info.title
|
||||||
|
instance.primary_investigator['department'] = user_info.department
|
||||||
|
except (ApiError, LDAPSocketOpenError) as exception:
|
||||||
|
user_info = None
|
||||||
|
instance.primary_investigator['display_name'] = 'Primary Investigator details'
|
||||||
|
instance.primary_investigator['department'] = 'currently not available'
|
||||||
|
|
||||||
|
|
||||||
doc_dictionary = FileService.get_reference_data(FileService.DOCUMENT_LIST, 'code', ['id'])
|
doc_dictionary = FileService.get_reference_data(FileService.DOCUMENT_LIST, 'code', ['id'])
|
||||||
|
|
||||||
instance.associated_files = []
|
instance.associated_files = []
|
||||||
@ -105,12 +107,13 @@ class Approval(object):
|
|||||||
associated_file['id'] = approval_file.file_data.file_model.id
|
associated_file['id'] = approval_file.file_data.file_model.id
|
||||||
if extra_info:
|
if extra_info:
|
||||||
irb_doc_code = approval_file.file_data.file_model.irb_doc_code
|
irb_doc_code = approval_file.file_data.file_model.irb_doc_code
|
||||||
associated_file['name'] = '_'.join((irb_doc_code, approval_file.file_data.file_model.name))
|
associated_file['name'] = '_'.join((extra_info['category1'],
|
||||||
|
approval_file.file_data.file_model.name))
|
||||||
associated_file['description'] = extra_info['description']
|
associated_file['description'] = extra_info['description']
|
||||||
else:
|
else:
|
||||||
associated_file['name'] = approval_file.file_data.file_model.name
|
associated_file['name'] = approval_file.file_data.file_model.name
|
||||||
associated_file['description'] = 'No description available'
|
associated_file['description'] = 'No description available'
|
||||||
associated_file['name'] = '(' + principal_investigator_id + ')' + associated_file['name']
|
associated_file['name'] = '(' + model.study.primary_investigator_id + ')' + associated_file['name']
|
||||||
associated_file['content_type'] = approval_file.file_data.file_model.content_type
|
associated_file['content_type'] = approval_file.file_data.file_model.content_type
|
||||||
instance.associated_files.append(associated_file)
|
instance.associated_files.append(associated_file)
|
||||||
|
|
||||||
|
3
package-lock.json
generated
Normal file
3
package-lock.json
generated
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"lockfileVersion": 1
|
||||||
|
}
|
@ -64,7 +64,7 @@ class TestApprovals(BaseTest):
|
|||||||
def test_list_approvals_per_approver(self):
|
def test_list_approvals_per_approver(self):
|
||||||
"""Only approvals associated with approver should be returned"""
|
"""Only approvals associated with approver should be returned"""
|
||||||
approver_uid = self.approval_2.approver_uid
|
approver_uid = self.approval_2.approver_uid
|
||||||
rv = self.app.get(f'/v1.0/approval?approver_uid={approver_uid}', headers=self.logged_in_headers())
|
rv = self.app.get(f'/v1.0/approval', headers=self.logged_in_headers())
|
||||||
self.assert_success(rv)
|
self.assert_success(rv)
|
||||||
|
|
||||||
response = json.loads(rv.get_data(as_text=True))
|
response = json.loads(rv.get_data(as_text=True))
|
||||||
@ -82,7 +82,7 @@ class TestApprovals(BaseTest):
|
|||||||
|
|
||||||
def test_list_approvals_per_admin(self):
|
def test_list_approvals_per_admin(self):
|
||||||
"""All approvals will be returned"""
|
"""All approvals will be returned"""
|
||||||
rv = self.app.get('/v1.0/approval', headers=self.logged_in_headers())
|
rv = self.app.get('/v1.0/approval?everything=true', headers=self.logged_in_headers())
|
||||||
self.assert_success(rv)
|
self.assert_success(rv)
|
||||||
|
|
||||||
response = json.loads(rv.get_data(as_text=True))
|
response = json.loads(rv.get_data(as_text=True))
|
||||||
@ -90,7 +90,16 @@ class TestApprovals(BaseTest):
|
|||||||
# Returned approvals should match what's in the db
|
# Returned approvals should match what's in the db
|
||||||
approvals_count = ApprovalModel.query.count()
|
approvals_count = ApprovalModel.query.count()
|
||||||
response_count = len(response)
|
response_count = len(response)
|
||||||
self.assertEqual(approvals_count, response_count)
|
self.assertEqual(2, response_count)
|
||||||
|
|
||||||
|
rv = self.app.get('/v1.0/approval', headers=self.logged_in_headers())
|
||||||
|
self.assert_success(rv)
|
||||||
|
response = json.loads(rv.get_data(as_text=True))
|
||||||
|
response_count = len(response)
|
||||||
|
self.assertEqual(1, response_count)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_approval(self):
|
def test_update_approval(self):
|
||||||
"""Approval status will be updated"""
|
"""Approval status will be updated"""
|
||||||
|
@ -10,7 +10,6 @@ from crc.models.api_models import WorkflowApiSchema, MultiInstanceType, TaskSche
|
|||||||
from crc.models.file import FileModelSchema
|
from crc.models.file import FileModelSchema
|
||||||
from crc.models.stats import TaskEventModel
|
from crc.models.stats import TaskEventModel
|
||||||
from crc.models.workflow import WorkflowStatus
|
from crc.models.workflow import WorkflowStatus
|
||||||
from crc.services.protocol_builder import ProtocolBuilderService
|
|
||||||
from crc.services.workflow_service import WorkflowService
|
from crc.services.workflow_service import WorkflowService
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user