Merge pull request #512 from sartography/bug/same_uid_different_roles

Study Associates Bug
This commit is contained in:
Mike Cullerton 2022-04-04 16:23:00 -04:00 committed by GitHub
commit 65da5a34ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 9 deletions

View File

@ -236,16 +236,19 @@ class StudyService(object):
study = db.session.query(StudyModel).filter(StudyModel.id == study_id).first()
if study is None:
raise ApiError('study_id not found', "A study with id# %d was not found" % study_id)
db.session.query(StudyAssociated).filter((StudyAssociated.study_id == study_id) & (StudyAssociated.uid ==
uid)).delete()
newAssociate = StudyAssociated()
newAssociate.study_id = study_id
newAssociate.uid = uid
newAssociate.role = role
newAssociate.send_email = send_email
newAssociate.access = access
session.add(newAssociate)
assoc = db.session.query(StudyAssociated).filter((StudyAssociated.study_id == study_id) &
(StudyAssociated.uid == uid) &
(StudyAssociated.role == role)).first()
if not assoc:
assoc = StudyAssociated()
assoc.study_id = study_id
assoc.uid = uid
assoc.role = role
assoc.send_email = send_email
assoc.access = access
session.add(assoc)
session.commit()
return True

View File

@ -0,0 +1,33 @@
from tests.base_test import BaseTest
from crc import session, db
from crc.models.study import StudyModel, StudyAssociated
from crc.scripts.update_study_associate import UpdateStudyAssociates
class TestSetStudyAssociate(BaseTest):
def setUp(self):
self.workflow = self.create_workflow('study_associates_validation')
self.workflow_api = self.get_workflow_api(self.workflow)
self.task = self.workflow_api.next_task
self.study_id = self.workflow.study_id
self.update_script = UpdateStudyAssociates()
def test_update_study_associate(self):
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
associates = db.session.query(StudyAssociated).filter(StudyAssociated.study_id == self.study_id).all()
self.assertEqual(1, len(associates))
def test_no_duplicate_associates(self):
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
associates = db.session.query(StudyAssociated).filter(StudyAssociated.study_id == self.study_id).all()
self.assertEqual(1, len(associates))
def test_same_uid_in_two_rules(self):
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='DC')
associates = db.session.query(StudyAssociated).filter(StudyAssociated.study_id == self.study_id).all()
self.assertEqual(2, len(associates))