Merge pull request #356 from sartography/bug/missing_pi_name_246

Bug/missing pi name 246
This commit is contained in:
Dan Funk 2021-08-17 11:28:38 -04:00 committed by GitHub
commit 9ca3fd4e12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 16 deletions

2
.gitignore vendored Normal file → Executable file
View File

@ -14,7 +14,7 @@ local.properties
.settings/ .settings/
.loadpath .loadpath
.recommenders .recommenders
.vscode/
# External tool builders # External tool builders
.externalToolBuilders/ .externalToolBuilders/

2
Pipfile.lock generated
View File

@ -979,7 +979,7 @@
}, },
"spiffworkflow": { "spiffworkflow": {
"git": "https://github.com/sartography/SpiffWorkflow.git", "git": "https://github.com/sartography/SpiffWorkflow.git",
"ref": "0b4a878f9b6d4f7fc320c26f59ca5e458a6130e8" "ref": "1df28b940ec0d32b672e59e3d17e7a804cb2b186"
}, },
"sqlalchemy": { "sqlalchemy": {
"hashes": [ "hashes": [

View File

@ -99,6 +99,12 @@ def user_studies():
user = UserService.current_user(allow_admin_impersonate=True) user = UserService.current_user(allow_admin_impersonate=True)
StudyService.synch_with_protocol_builder_if_enabled(user) StudyService.synch_with_protocol_builder_if_enabled(user)
studies = StudyService().get_studies_for_user(user) studies = StudyService().get_studies_for_user(user)
if len(studies) == 0:
studies = StudyService().get_studies_for_user(user, include_invalid=True)
if len(studies) > 0:
message = f"All studies associated with User: {user.display_name} failed study validation"
raise ApiError(code="study_integrity_error", message=message)
results = StudySchema(many=True).dump(studies) results = StudySchema(many=True).dump(studies)
return results return results

4
crc/services/study_service.py Normal file → Executable file
View File

@ -42,7 +42,7 @@ class StudyService(object):
return True return True
return False return False
def get_studies_for_user(self, user): def get_studies_for_user(self, user, include_invalid=False):
"""Returns a list of all studies for the given user.""" """Returns a list of all studies for the given user."""
associated = session.query(StudyAssociated).filter_by(uid=user.uid, access=True).all() associated = session.query(StudyAssociated).filter_by(uid=user.uid, access=True).all()
associated_studies = [x.study_id for x in associated] associated_studies = [x.study_id for x in associated]
@ -51,7 +51,7 @@ class StudyService(object):
studies = [] studies = []
for study_model in db_studies: for study_model in db_studies:
if self._is_valid_study(study_model.id): if include_invalid or self._is_valid_study(study_model.id):
studies.append(StudyService.get_study(study_model.id, study_model, do_status=False)) studies.append(StudyService.get_study(study_model.id, study_model, do_status=False))
return studies return studies

3
crc/services/workflow_service.py Normal file → Executable file
View File

@ -781,6 +781,7 @@ class WorkflowService(object):
if not hasattr(spiff_task.task_spec, 'lane') or spiff_task.task_spec.lane is None: if not hasattr(spiff_task.task_spec, 'lane') or spiff_task.task_spec.lane is None:
associated = StudyService.get_study_associates(processor.workflow_model.study.id) associated = StudyService.get_study_associates(processor.workflow_model.study.id)
return [user.uid for user in associated if user.access] return [user.uid for user in associated if user.access]
if spiff_task.task_spec.lane not in spiff_task.data: if spiff_task.task_spec.lane not in spiff_task.data:
return [] # No users are assignable to the task at this moment return [] # No users are assignable to the task at this moment
lane_users = spiff_task.data[spiff_task.task_spec.lane] lane_users = spiff_task.data[spiff_task.task_spec.lane]
@ -790,7 +791,7 @@ class WorkflowService(object):
lane_uids = [] lane_uids = []
for user in lane_users: for user in lane_users:
if isinstance(user, dict): if isinstance(user, dict):
if 'value' in user and user['value'] is not None: if user.get("value"):
lane_uids.append(user['value']) lane_uids.append(user['value'])
else: else:
raise ApiError.from_task(code="task_lane_user_error", message="Spiff Task %s lane user dict must have a key called 'value' with the user's uid in it." % raise ApiError.from_task(code="task_lane_user_error", message="Spiff Task %s lane user dict must have a key called 'value' with the user's uid in it." %

View File

@ -56,7 +56,6 @@ class TestStudyDetailsDocumentsScript(BaseTest):
@patch('crc.services.protocol_builder.requests.get') @patch('crc.services.protocol_builder.requests.get')
def test_no_validation_error_when_correct_file_exists(self, mock_get): def test_no_validation_error_when_correct_file_exists(self, mock_get):
mock_get.return_value.ok = True mock_get.return_value.ok = True
mock_get.return_value.text = self.protocol_builder_response('required_docs.json') mock_get.return_value.text = self.protocol_builder_response('required_docs.json')

View File

@ -40,7 +40,7 @@ class TestTimerEvent(BaseTest):
with self.assertLogs('crc', level='ERROR') as cm: with self.assertLogs('crc', level='ERROR') as cm:
WorkflowService.do_waiting() WorkflowService.do_waiting()
self.assertEqual(1, len(cm.output)) self.assertEqual(1, len(cm.output))
self.assertRegexpMatches(cm.output[0], f"workflow #%i" % workflow.id) self.assertRegex(cm.output[0], f"workflow #%i" % workflow.id)
self.assertRegexpMatches(cm.output[0], f"study #%i" % workflow.study_id) self.assertRegex(cm.output[0], f"study #%i" % workflow.study_id)
self.assertTrue(wf.status == WorkflowStatus.waiting) self.assertTrue(wf.status == WorkflowStatus.waiting)