-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SIMSBIOHUB-593: Add constraint for a user to have only one role per P…
…roject (#1307) * Add database constraint to enforce one role per user per project * Add project member role icons to form control --------- Co-authored-by: Nick Phura <[email protected]>
- Loading branch information
1 parent
a3cb8a7
commit e4a401e
Showing
10 changed files
with
322 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -944,7 +944,7 @@ describe('ProjectParticipationService', () => { | |
}); | ||
}); | ||
|
||
describe('doProjectParticipantsHaveARole', () => { | ||
describe('_doProjectParticipantsHaveARole', () => { | ||
it('should return true if one project user has a specified role', () => { | ||
const projectUsers: PostParticipantData[] = [ | ||
{ | ||
|
@@ -962,7 +962,7 @@ describe('ProjectParticipationService', () => { | |
const dbConnection = getMockDBConnection(); | ||
const service = new ProjectParticipationService(dbConnection); | ||
|
||
const result = service.doProjectParticipantsHaveARole(projectUsers, PROJECT_ROLE.COLLABORATOR); | ||
const result = service._doProjectParticipantsHaveARole(projectUsers, PROJECT_ROLE.COLLABORATOR); | ||
|
||
expect(result).to.be.true; | ||
}); | ||
|
@@ -984,7 +984,7 @@ describe('ProjectParticipationService', () => { | |
const dbConnection = getMockDBConnection(); | ||
const service = new ProjectParticipationService(dbConnection); | ||
|
||
const result = service.doProjectParticipantsHaveARole(projectUsers, PROJECT_ROLE.COLLABORATOR); | ||
const result = service._doProjectParticipantsHaveARole(projectUsers, PROJECT_ROLE.COLLABORATOR); | ||
|
||
expect(result).to.be.true; | ||
}); | ||
|
@@ -1006,7 +1006,97 @@ describe('ProjectParticipationService', () => { | |
const dbConnection = getMockDBConnection(); | ||
const service = new ProjectParticipationService(dbConnection); | ||
|
||
const result = service.doProjectParticipantsHaveARole(projectUsers, PROJECT_ROLE.COLLABORATOR); | ||
const result = service._doProjectParticipantsHaveARole(projectUsers, PROJECT_ROLE.COLLABORATOR); | ||
|
||
expect(result).to.be.false; | ||
}); | ||
}); | ||
|
||
describe('_doProjectParticipantsHaveOneRole', () => { | ||
it('should return true if one project user has one specified role', () => { | ||
const projectUsers: PostParticipantData[] = [ | ||
{ | ||
project_participation_id: 23, | ||
system_user_id: 22, | ||
project_role_names: [PROJECT_ROLE.COLLABORATOR] | ||
} | ||
]; | ||
|
||
const dbConnection = getMockDBConnection(); | ||
const service = new ProjectParticipationService(dbConnection); | ||
|
||
const result = service._doProjectParticipantsHaveOneRole(projectUsers); | ||
|
||
expect(result).to.be.true; | ||
}); | ||
|
||
it('should return true if multiple project users have one specified role', () => { | ||
const projectUsers: PostParticipantData[] = [ | ||
{ | ||
project_participation_id: 12, | ||
system_user_id: 11, | ||
project_role_names: [PROJECT_ROLE.COLLABORATOR] | ||
}, | ||
{ | ||
project_participation_id: 23, | ||
system_user_id: 22, | ||
project_role_names: [PROJECT_ROLE.OBSERVER] | ||
} | ||
]; | ||
|
||
const dbConnection = getMockDBConnection(); | ||
const service = new ProjectParticipationService(dbConnection); | ||
|
||
const result = service._doProjectParticipantsHaveOneRole(projectUsers); | ||
|
||
expect(result).to.be.true; | ||
}); | ||
|
||
it('should return false if a participant has multiple specified role', () => { | ||
const projectUsers: PostParticipantData[] = [ | ||
{ | ||
project_participation_id: 12, | ||
system_user_id: 11, | ||
project_role_names: [PROJECT_ROLE.COORDINATOR] | ||
}, | ||
{ | ||
project_participation_id: 23, | ||
system_user_id: 22, | ||
project_role_names: [PROJECT_ROLE.OBSERVER] | ||
}, | ||
{ | ||
project_participation_id: 23, | ||
system_user_id: 22, | ||
project_role_names: [PROJECT_ROLE.COLLABORATOR] | ||
} | ||
]; | ||
|
||
const dbConnection = getMockDBConnection(); | ||
const service = new ProjectParticipationService(dbConnection); | ||
|
||
const result = service._doProjectParticipantsHaveOneRole(projectUsers); | ||
|
||
expect(result).to.be.false; | ||
}); | ||
|
||
it('should return false if a participant has multiple specified roles in the same record', () => { | ||
const projectUsers: PostParticipantData[] = [ | ||
{ | ||
project_participation_id: 12, | ||
system_user_id: 11, | ||
project_role_names: [PROJECT_ROLE.COORDINATOR] | ||
}, | ||
{ | ||
project_participation_id: 23, | ||
system_user_id: 22, | ||
project_role_names: [PROJECT_ROLE.OBSERVER, PROJECT_ROLE.COLLABORATOR] | ||
} | ||
]; | ||
|
||
const dbConnection = getMockDBConnection(); | ||
const service = new ProjectParticipationService(dbConnection); | ||
|
||
const result = service._doProjectParticipantsHaveOneRole(projectUsers); | ||
|
||
expect(result).to.be.false; | ||
}); | ||
|
@@ -1058,6 +1148,10 @@ describe('ProjectParticipationService', () => { | |
project_participation_id: 12, | ||
project_role_names: [PROJECT_ROLE.COORDINATOR] // Existing user to be updated | ||
}, | ||
{ | ||
system_user_id: 33, | ||
project_role_names: [PROJECT_ROLE.COLLABORATOR] // Existing user to be unaffected | ||
}, | ||
{ | ||
system_user_id: 44, | ||
project_role_names: [PROJECT_ROLE.OBSERVER] // New user | ||
|
@@ -1086,6 +1180,25 @@ describe('ProjectParticipationService', () => { | |
user_guid: '123-456-789-1', | ||
user_identifier: 'testuser1' | ||
}, | ||
{ | ||
project_participation_id: 6, // Existing user to be unaffected | ||
project_id: 1, | ||
system_user_id: 33, | ||
project_role_ids: [2], | ||
project_role_names: [PROJECT_ROLE.COLLABORATOR], | ||
project_role_permissions: ['Permission1'], | ||
agency: null, | ||
display_name: 'test user 1', | ||
email: '[email protected]', | ||
family_name: 'lname', | ||
given_name: 'fname', | ||
identity_source: SYSTEM_IDENTITY_SOURCE.IDIR, | ||
record_end_date: null, | ||
role_ids: [2], | ||
role_names: [SYSTEM_ROLE.PROJECT_CREATOR], | ||
user_guid: '123-456-789-1', | ||
user_identifier: 'testuser1' | ||
}, | ||
{ | ||
project_participation_id: 23, // Existing user to be removed | ||
project_id: 1, | ||
|
@@ -1121,6 +1234,8 @@ describe('ProjectParticipationService', () => { | |
expect(getProjectParticipantsStub).to.have.been.calledOnceWith(projectId); | ||
expect(deleteProjectParticipationRecordStub).to.have.been.calledWith(1, 23); | ||
expect(updateProjectParticipationRoleStub).to.have.been.calledOnceWith(12, PROJECT_ROLE.COORDINATOR); | ||
expect(updateProjectParticipationRoleStub).to.not.have.been.calledWith(6, PROJECT_ROLE.COLLABORATOR); | ||
expect(postProjectParticipantStub).to.not.have.been.calledWith(projectId, 6, PROJECT_ROLE.COLLABORATOR); | ||
expect(postProjectParticipantStub).to.have.been.calledOnceWith(projectId, 44, PROJECT_ROLE.OBSERVER); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.