src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
DocumentsServiceImpl extends AbstractProjectServiceImpl implements DocumentsService { @Override public ServiceResult<FileAndContents> getFileContents(long projectId, long documentConfigId) { return getProject(projectId).andOnSuccess(project -> { FileEntry fileEntry = getFileEntry(project, documentConfigId); return fileService.getFileByFileEntryId(fileEntry.getId()) .andOnSuccessReturn(inputStream -> new BasicFileAndContents(fileEntryMapper.mapToResource(fileEntry), inputStream)); }); } @Override ServiceResult<List<String>> getValidMediaTypesForDocument(long documentConfigId); @Override @Transactional ServiceResult<FileEntryResource> createDocumentFileEntry(long projectId, long documentConfigId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override ServiceResult<FileAndContents> getFileContents(long projectId, long documentConfigId); @Override ServiceResult<FileEntryResource> getFileEntryDetails(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> deleteDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> submitDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void getFileContents() { FileEntryResource fileEntryResource = FileEntryResourceBuilder.newFileEntryResource().build(); Supplier<InputStream> inputStreamSupplier = () -> null; when(fileServiceMock.getFileByFileEntryId(fileEntryId)).thenReturn(serviceSuccess(inputStreamSupplier)); when(fileEntryMapperMock.mapToResource(fileEntry)).thenReturn(fileEntryResource); ServiceResult<FileAndContents> result = service.getFileContents(projectId, documentConfigId); assertTrue(result.isSuccess()); assertEquals(fileEntryResource, result.getSuccess().getFileEntry()); assertEquals(inputStreamSupplier, result.getSuccess().getContentsSupplier()); }
DocumentsServiceImpl extends AbstractProjectServiceImpl implements DocumentsService { @Override public ServiceResult<FileEntryResource> getFileEntryDetails(long projectId, long documentConfigId) { return getProject(projectId) .andOnSuccessReturn(project -> fileEntryMapper.mapToResource(getFileEntry(project, documentConfigId))); } @Override ServiceResult<List<String>> getValidMediaTypesForDocument(long documentConfigId); @Override @Transactional ServiceResult<FileEntryResource> createDocumentFileEntry(long projectId, long documentConfigId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override ServiceResult<FileAndContents> getFileContents(long projectId, long documentConfigId); @Override ServiceResult<FileEntryResource> getFileEntryDetails(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> deleteDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> submitDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void getFileEntryDetails() { FileEntryResource fileEntryResource = FileEntryResourceBuilder.newFileEntryResource().build(); when(fileEntryMapperMock.mapToResource(fileEntry)).thenReturn(fileEntryResource); ServiceResult<FileEntryResource> result = service.getFileEntryDetails(projectId, documentConfigId); assertTrue(result.isSuccess()); assertEquals(fileEntryResource, result.getSuccess()); }
DocumentsServiceImpl extends AbstractProjectServiceImpl implements DocumentsService { @Override @Transactional public ServiceResult<Void> deleteDocument(long projectId, long documentConfigId) { return find(getProject(projectId), getCompetitionDocumentConfig(documentConfigId)). andOnSuccess((project, projectDocumentConfig) -> validateProjectActive(project) .andOnSuccess(() -> deleteProjectDocument(project, documentConfigId)) .andOnSuccess(() -> deleteFile(project, documentConfigId)) ); } @Override ServiceResult<List<String>> getValidMediaTypesForDocument(long documentConfigId); @Override @Transactional ServiceResult<FileEntryResource> createDocumentFileEntry(long projectId, long documentConfigId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override ServiceResult<FileAndContents> getFileContents(long projectId, long documentConfigId); @Override ServiceResult<FileEntryResource> getFileEntryDetails(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> deleteDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> submitDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void deleteDocumentWhenProjectNotInSetup() { when(projectWorkflowHandlerMock.getState(project)).thenReturn(ProjectState.LIVE); ServiceResult<Void> result = service.deleteDocument(projectId, documentConfigId); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_ALREADY_COMPLETE)); verify(projectDocumentRepositoryMock, never()).delete(any(ProjectDocument.class)); verify(fileServiceMock, never()).deleteFileIgnoreNotFound(fileEntryId); } @Test public void deleteDocumentWhenProjectDocumentAlreadyApproved() { projectDocument.setStatus(APPROVED); ServiceResult<Void> result = service.deleteDocument(projectId, documentConfigId); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_PROJECT_DOCUMENT_CANNOT_BE_DELETED)); verify(projectDocumentRepositoryMock, never()).delete(any(ProjectDocument.class)); verify(fileServiceMock, never()).deleteFileIgnoreNotFound(fileEntryId); } @Test public void deleteDocumentWhenProjectDocumentAlreadySubmitted() { projectDocument.setStatus(SUBMITTED); ServiceResult<Void> result = service.deleteDocument(projectId, documentConfigId); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_PROJECT_DOCUMENT_CANNOT_BE_DELETED)); verify(projectDocumentRepositoryMock, never()).delete(any(ProjectDocument.class)); verify(fileServiceMock, never()).deleteFileIgnoreNotFound(fileEntryId); } @Test public void deleteDocument() { projectDocument.setStatus(UPLOADED); ServiceResult<Void> result = service.deleteDocument(projectId, documentConfigId); assertTrue(result.isSuccess()); verify(projectDocumentRepositoryMock).delete(projectDocument); verify(fileServiceMock).deleteFileIgnoreNotFound(fileEntryId); }
UserPermissionRules { @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") public boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user) { return isSystemMaintenanceUser(user); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void systemMaintenanceUserCanUpdateUsersEmailAddresses() { UserResource userResource = newUserResource().withRoleGlobal(APPLICANT).build(); allGlobalRoleUsers.forEach(user -> { if (user.equals(systemMaintenanceUser())) { assertTrue(rules.systemMaintenanceUserCanUpdateUsersEmailAddresses(userResource, user)); } else { assertFalse(rules.systemMaintenanceUserCanUpdateUsersEmailAddresses(userResource, user)); } }); }
DocumentsServiceImpl extends AbstractProjectServiceImpl implements DocumentsService { @Override @Transactional public ServiceResult<Void> submitDocument(long projectId, long documentConfigId) { return find(getProject(projectId), getCompetitionDocumentConfig(documentConfigId)). andOnSuccess((project, projectDocumentConfig) -> validateProjectActive(project) .andOnSuccess(() -> submitDocument(project, documentConfigId)) ).andOnSuccessReturnVoid(() -> activityLogService.recordDocumentActivityByProjectId(projectId, ActivityType.DOCUMENT_UPLOADED, documentConfigId)); } @Override ServiceResult<List<String>> getValidMediaTypesForDocument(long documentConfigId); @Override @Transactional ServiceResult<FileEntryResource> createDocumentFileEntry(long projectId, long documentConfigId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override ServiceResult<FileAndContents> getFileContents(long projectId, long documentConfigId); @Override ServiceResult<FileEntryResource> getFileEntryDetails(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> deleteDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> submitDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void submitDocumentWhenProjectNotInSetup() { when(projectWorkflowHandlerMock.getState(project)).thenReturn(ProjectState.LIVE); ServiceResult<Void> result = service.submitDocument(projectId, documentConfigId); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_ALREADY_COMPLETE)); verify(projectDocumentRepositoryMock, never()).save(any(ProjectDocument.class)); } @Test public void submitDocumentWhenProjectDocumentNotInUploadedState() { projectDocument.setStatus(UNSET); ServiceResult<Void> result = service.submitDocument(projectId, documentConfigId); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_PROJECT_DOCUMENT_NOT_YET_UPLOADED)); verify(projectDocumentRepositoryMock, never()).save(any(ProjectDocument.class)); } @Test public void submitDocument() { projectDocument.setStatus(UPLOADED); ServiceResult<Void> result = service.submitDocument(projectId, documentConfigId); assertTrue(result.isSuccess()); assertEquals(SUBMITTED, projectDocument.getStatus()); verify(projectDocumentRepositoryMock).save(projectDocument); verify(activityLogService).recordDocumentActivityByProjectId(projectId, ActivityType.DOCUMENT_UPLOADED, documentConfigId); }
DocumentsServiceImpl extends AbstractProjectServiceImpl implements DocumentsService { @Override @Transactional public ServiceResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision) { return validateProjectDocumentDecision(decision) .andOnSuccess(() -> find(getProject(projectId), getCompetitionDocumentConfig(documentConfigId)). andOnSuccess((project, projectDocumentConfig) -> validateProjectActive(project) .andOnSuccess(() -> applyDocumentDecision(project, documentConfigId, decision)) )).andOnSuccessReturnVoid(() -> { if (decision.getApproved()) { activityLogService.recordDocumentActivityByProjectId(projectId, ActivityType.DOCUMENT_APPROVED, documentConfigId); } else { activityLogService.recordDocumentActivityByProjectId(projectId, ActivityType.DOCUMENT_REJECTED, documentConfigId); } }); } @Override ServiceResult<List<String>> getValidMediaTypesForDocument(long documentConfigId); @Override @Transactional ServiceResult<FileEntryResource> createDocumentFileEntry(long projectId, long documentConfigId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override ServiceResult<FileAndContents> getFileContents(long projectId, long documentConfigId); @Override ServiceResult<FileEntryResource> getFileEntryDetails(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> deleteDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> submitDocument(long projectId, long documentConfigId); @Override @Transactional ServiceResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void documentDecisionWhenDecisionInvalid() { ProjectDocumentDecision documentDecision = new ProjectDocumentDecision(); ServiceResult<Void> result = service.documentDecision(projectId, documentConfigId, documentDecision); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_PROJECT_DOCUMENT_INVALID_DECISION)); verify(projectDocumentRepositoryMock, never()).save(any(ProjectDocument.class)); } @Test public void documentDecisionWhenRejectedWithoutReason() { ProjectDocumentDecision documentDecision = new ProjectDocumentDecision(false, null); ServiceResult<Void> result = service.documentDecision(projectId, documentConfigId, documentDecision); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_PROJECT_DOCUMENT_INVALID_DECISION)); verify(projectDocumentRepositoryMock, never()).save(any(ProjectDocument.class)); } @Test public void documentDecisionWhenRejectedWithEmptyReason() { ProjectDocumentDecision documentDecision = new ProjectDocumentDecision(false, " "); ServiceResult<Void> result = service.documentDecision(projectId, documentConfigId, documentDecision); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_PROJECT_DOCUMENT_INVALID_DECISION)); verify(projectDocumentRepositoryMock, never()).save(any(ProjectDocument.class)); } @Test public void documentDecisionWhenProjectNotInSetup() { when(projectWorkflowHandlerMock.getState(project)).thenReturn(ProjectState.LIVE); ProjectDocumentDecision documentDecision = new ProjectDocumentDecision(false, "Missing details"); ServiceResult<Void> result = service.documentDecision(projectId, documentConfigId, documentDecision); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_ALREADY_COMPLETE)); verify(projectDocumentRepositoryMock, never()).save(any(ProjectDocument.class)); } @Test public void documentDecisionWhenProjectDocumentNotInSubmittedState() { projectDocument.setStatus(UPLOADED); ProjectDocumentDecision documentDecision = new ProjectDocumentDecision(false, "Missing details"); ServiceResult<Void> result = service.documentDecision(projectId, documentConfigId, documentDecision); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_PROJECT_DOCUMENT_CANNOT_BE_ACCEPTED_OR_REJECTED)); verify(projectDocumentRepositoryMock, never()).save(any(ProjectDocument.class)); } @Test public void documentDecisionWhenRejected() { String rejectionReason = "Missing details"; projectDocument.setStatus(SUBMITTED); ProjectDocumentDecision documentDecision = new ProjectDocumentDecision(false, rejectionReason); ServiceResult<Void> result = service.documentDecision(projectId, documentConfigId, documentDecision); assertTrue(result.isSuccess()); assertEquals(REJECTED, projectDocument.getStatus()); assertEquals(rejectionReason, projectDocument.getStatusComments()); verify(projectDocumentRepositoryMock).save(projectDocument); } @Test public void documentDecisionWhenApproved() { String rejectionReason = "Reason not used when approved"; projectDocument.setStatus(SUBMITTED); ProjectDocumentDecision documentDecision = new ProjectDocumentDecision(true, rejectionReason); ServiceResult<Void> result = service.documentDecision(projectId, documentConfigId, documentDecision); assertTrue(result.isSuccess()); assertEquals(APPROVED, projectDocument.getStatus()); assertNull(projectDocument.getStatusComments()); verify(projectDocumentRepositoryMock).save(projectDocument); verify(activityLogService).recordDocumentActivityByProjectId(projectId, ActivityType.DOCUMENT_APPROVED, documentConfigId); }
UserPermissionRules { @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") public boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user) { return userToUpdate.isExternalUser() && user.hasRole(SUPPORT); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void supportCanUpdateExternalUsersEmailAddresses() { UserResource externalUser = newUserResource().withRoleGlobal(APPLICANT).build(); UserResource internalUser = newUserResource().withRoleGlobal(IFS_ADMINISTRATOR).build(); allGlobalRoleUsers.forEach(user -> { if (user.hasRole(SUPPORT)) { assertTrue(rules.supportCanUpdateExternalUsersEmailAddresses(externalUser, user)); assertFalse(rules.supportCanUpdateExternalUsersEmailAddresses(internalUser, user)); } else { assertFalse(rules.supportCanUpdateExternalUsersEmailAddresses(externalUser, user)); assertFalse(rules.supportCanUpdateExternalUsersEmailAddresses(internalUser, user)); } }); }
BankDetailsPermissionRules extends BasePermissionRules { @PermissionRule( value = "READ", description = "Partners can see their own organisations bank details") public boolean partnersCanSeeTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user) { return isPartner(bankDetailsResource.getProject(), user.getId()) && partnerBelongsToOrganisation(bankDetailsResource.getProject(), user.getId(), bankDetailsResource.getOrganisation()); } @PermissionRule( value = "SUBMIT", description = "Partners can submit their own organisations bank details") boolean partnersCanSubmitTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "UPDATE", description = "Project finance users can update any organisations bank details") boolean projectFinanceUsersCanUpdateAnyOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "READ", description = "Partners can see their own organisations bank details") boolean partnersCanSeeTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "READ", description = "Project finance user can see all bank details on all projects") boolean projectFinanceUsersCanSeeAllBankDetailsOnAllProjects(BankDetailsResource bankDetailsResource, UserResource user); }
@Test public void partnersCanSeeBankDetailsOfTheirOwnOrg() { when(projectUserRepository.findByProjectIdAndUserIdAndRoleIsIn(project.getId(), user.getId(), PROJECT_USER_ROLES.stream().collect(Collectors.toList()))).thenReturn(partnerProjectUser); when(projectUserRepository.findFirstByProjectIdAndUserIdAndOrganisationIdAndRoleIn(project.getId(), user.getId(), organisationResource.getId(), PROJECT_USER_ROLES.stream().collect(Collectors.toList()))).thenReturn(partnerProjectUser.get(0)); assertTrue(rules.partnersCanSeeTheirOwnOrganisationsBankDetails(bankDetailsResource, user)); } @Test public void nonPartnersCannotSeeBankDetails() { when(projectUserRepository.findByProjectIdAndUserIdAndRole(project.getId(), user.getId(), PROJECT_PARTNER)).thenReturn(Collections.emptyList()); assertFalse(rules.partnersCanSeeTheirOwnOrganisationsBankDetails(bankDetailsResource, user)); } @Test public void partnersCannotSeeBankDetailsOfAnotherOrganisation() { when(projectUserRepository.findByProjectIdAndUserIdAndRole(project.getId(), user.getId(), PROJECT_PARTNER)).thenReturn(partnerProjectUser); when(projectUserRepository.findFirstByProjectIdAndUserIdAndOrganisationIdAndRoleIn(project.getId(), user.getId(), organisationResource.getId(), PROJECT_USER_ROLES.stream().collect(Collectors.toList()))).thenReturn(null); assertFalse(rules.partnersCanSeeTheirOwnOrganisationsBankDetails(bankDetailsResource, user)); }
BankDetailsPermissionRules extends BasePermissionRules { @PermissionRule( value = "SUBMIT", description = "Partners can submit their own organisations bank details") public boolean partnersCanSubmitTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user) { return isPartner(bankDetailsResource.getProject(), user.getId()) && partnerBelongsToOrganisation(bankDetailsResource.getProject(), user.getId(), bankDetailsResource.getOrganisation()) && isProjectActive(bankDetailsResource.getProject()); } @PermissionRule( value = "SUBMIT", description = "Partners can submit their own organisations bank details") boolean partnersCanSubmitTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "UPDATE", description = "Project finance users can update any organisations bank details") boolean projectFinanceUsersCanUpdateAnyOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "READ", description = "Partners can see their own organisations bank details") boolean partnersCanSeeTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "READ", description = "Project finance user can see all bank details on all projects") boolean projectFinanceUsersCanSeeAllBankDetailsOnAllProjects(BankDetailsResource bankDetailsResource, UserResource user); }
@Test public void partnersCanUpdateTheirOwnOrganisationBankDetails() { when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); when(projectUserRepository.findByProjectIdAndUserIdAndRoleIsIn(project.getId(), user.getId(), PROJECT_USER_ROLES.stream().collect(Collectors.toList()))).thenReturn(partnerProjectUser); when(projectUserRepository.findFirstByProjectIdAndUserIdAndOrganisationIdAndRoleIn(project.getId(), user.getId(), organisationResource.getId(), PROJECT_USER_ROLES.stream().collect(Collectors.toList()))).thenReturn(partnerProjectUser.get(0)); assertTrue(rules.partnersCanSubmitTheirOwnOrganisationsBankDetails(bankDetailsResource, user)); } @Test public void nonPartnersCannotUpdateBankDetails() { when(projectUserRepository.findByProjectIdAndUserIdAndRole(project.getId(), user.getId(), PROJECT_PARTNER)).thenReturn(Collections.emptyList()); assertFalse(rules.partnersCanSubmitTheirOwnOrganisationsBankDetails(bankDetailsResource, user)); } @Test public void partnersCannotUpdateBankDetailsOfAnotherOrg() { when(projectUserRepository.findByProjectIdAndUserIdAndRole(project.getId(), user.getId(), PROJECT_PARTNER)).thenReturn(partnerProjectUser); when(projectUserRepository.findOneByProjectIdAndUserIdAndOrganisationIdAndRole(project.getId(), user.getId(), organisationResource.getId(), PROJECT_PARTNER)).thenReturn(null); assertFalse(rules.partnersCanSubmitTheirOwnOrganisationsBankDetails(bankDetailsResource, user)); }
BankDetailsPermissionRules extends BasePermissionRules { @PermissionRule( value = "READ", description = "Project finance user can see all bank details on all projects") public boolean projectFinanceUsersCanSeeAllBankDetailsOnAllProjects(BankDetailsResource bankDetailsResource, UserResource user) { return isProjectFinanceUser(user); } @PermissionRule( value = "SUBMIT", description = "Partners can submit their own organisations bank details") boolean partnersCanSubmitTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "UPDATE", description = "Project finance users can update any organisations bank details") boolean projectFinanceUsersCanUpdateAnyOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "READ", description = "Partners can see their own organisations bank details") boolean partnersCanSeeTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "READ", description = "Project finance user can see all bank details on all projects") boolean projectFinanceUsersCanSeeAllBankDetailsOnAllProjects(BankDetailsResource bankDetailsResource, UserResource user); }
@Test public void projectFinanceUserCanSeeAllBankDetailsForAllOrganisations() { assertTrue(rules.projectFinanceUsersCanSeeAllBankDetailsOnAllProjects(bankDetailsResource, projectFinanceUser)); }
BankDetailsPermissionRules extends BasePermissionRules { @PermissionRule( value = "UPDATE", description = "Project finance users can update any organisations bank details") public boolean projectFinanceUsersCanUpdateAnyOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user) { return isProjectFinanceUser(user) && isProjectActive(bankDetailsResource.getProject()); } @PermissionRule( value = "SUBMIT", description = "Partners can submit their own organisations bank details") boolean partnersCanSubmitTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "UPDATE", description = "Project finance users can update any organisations bank details") boolean projectFinanceUsersCanUpdateAnyOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "READ", description = "Partners can see their own organisations bank details") boolean partnersCanSeeTheirOwnOrganisationsBankDetails(BankDetailsResource bankDetailsResource, UserResource user); @PermissionRule( value = "READ", description = "Project finance user can see all bank details on all projects") boolean projectFinanceUsersCanSeeAllBankDetailsOnAllProjects(BankDetailsResource bankDetailsResource, UserResource user); }
@Test public void projectFinanceUserCanUpdateBankDetailsForAllOrganisations() { when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); assertTrue(rules.projectFinanceUsersCanUpdateAnyOrganisationsBankDetails(bankDetailsResource, projectFinanceUser)); }
CompetitionsBankDetailsController { @GetMapping("/pending-bank-details-approvals") public RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals() { return bankDetailsService.getPendingBankDetailsApprovals().toGetResponse(); } @GetMapping("/pending-bank-details-approvals") RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @GetMapping("/count-pending-bank-details-approvals") RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void getPendingBankDetailsApprovals() throws Exception { List<BankDetailsReviewResource> pendingBankDetails = singletonList(new BankDetailsReviewResource(1L, 11L, "Comp1", 12L, "project1", 22L, "Org1")); when(bankDetailsServiceMock.getPendingBankDetailsApprovals()).thenReturn(serviceSuccess(pendingBankDetails)); mockMvc.perform(get("/competitions/pending-bank-details-approvals")) .andExpect(status().isOk()) .andExpect(content().json(toJson(pendingBankDetails))); verify(bankDetailsServiceMock, only()).getPendingBankDetailsApprovals(); }
UserPermissionRules { @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") public boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user) { return user.hasRole(IFS_ADMINISTRATOR); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void ifsAdminCanUpdateAllEmailAddresses() { UserResource userResource = newUserResource().withRoleGlobal(APPLICANT).build(); allGlobalRoleUsers.forEach(user -> { if (user.hasRole(IFS_ADMINISTRATOR)) { assertTrue(rules.ifsAdminCanUpdateAllEmailAddresses(userResource, user)); } else { assertFalse(rules.ifsAdminCanUpdateAllEmailAddresses(userResource, user)); } }); }
CompetitionsBankDetailsController { @GetMapping("/count-pending-bank-details-approvals") public RestResult<Long> countPendingBankDetailsApprovals() { return bankDetailsService.countPendingBankDetailsApprovals().toGetResponse(); } @GetMapping("/pending-bank-details-approvals") RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @GetMapping("/count-pending-bank-details-approvals") RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void countPendingBankDetailsApprovals() throws Exception { Long pendingBankDetailsCount = 8L; when(bankDetailsServiceMock.countPendingBankDetailsApprovals()).thenReturn(serviceSuccess(pendingBankDetailsCount)); mockMvc.perform(get("/competitions/count-pending-bank-details-approvals")) .andExpect(status().isOk()) .andExpect(content().json(toJson(pendingBankDetailsCount))); verify(bankDetailsServiceMock, only()).countPendingBankDetailsApprovals(); }
BankDetailsServiceImpl implements BankDetailsService { @Override public ServiceResult<BankDetailsResource> getByProjectAndOrganisation(Long projectId, Long organisationId) { return find(bankDetailsRepository.findByProjectIdAndOrganisationId(projectId, organisationId), new Error(BANK_DETAILS_DONT_EXIST_FOR_GIVEN_PROJECT_AND_ORGANISATION, asList(projectId, organisationId), HttpStatus.NOT_FOUND)). andOnSuccessReturn(bankDetails -> bankDetailsMapper.mapToResource(bankDetails)); } @Override ServiceResult<BankDetailsResource> getById(Long id); @Override @Transactional ServiceResult<Void> submitBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override @Transactional ServiceResult<Void> updateBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override ServiceResult<ProjectBankDetailsStatusSummary> getProjectBankDetailsStatusSummary(Long projectId); @Override ServiceResult<BankDetailsResource> getByProjectAndOrganisation(Long projectId, Long organisationId); @Override ServiceResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override ServiceResult<Long> countPendingBankDetailsApprovals(); }
@Test public void getBankDetailsByProjectAndOrganisation() { when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(project.getId(), organisation.getId())).thenReturn(Optional.of(bankDetails)); when(bankDetailsMapperMock.mapToResource(bankDetails)).thenReturn(bankDetailsResource); ServiceResult<BankDetailsResource> result = service.getByProjectAndOrganisation(project.getId(), organisation.getId()); assertTrue(result.isSuccess()); assertEquals(result.getSuccess(), bankDetailsResource); } @Test public void getBankDetailsByProjectAndOrganisationButTheyDontExist() { when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(project.getId(), organisation.getId())).thenReturn(Optional.empty()); ServiceResult<BankDetailsResource> result = service.getByProjectAndOrganisation(project.getId(), organisation.getId()); assertTrue(result.isFailure()); Error expectedError = new Error(BANK_DETAILS_DONT_EXIST_FOR_GIVEN_PROJECT_AND_ORGANISATION, asList(project.getId(), organisation.getId()), NOT_FOUND); assertTrue(result.getFailure().is(expectedError)); }
BankDetailsServiceImpl implements BankDetailsService { @Override @Transactional public ServiceResult<Void> submitBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource) { return bankDetailsDontExist(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation()). andOnSuccess(() -> validateBankDetails(bankDetailsResource). andOnSuccess(accountDetails -> saveSubmittedBankDetails(accountDetails, bankDetailsResource)). andOnSuccess(accountDetails -> { Optional<BankDetails> bankDetails = bankDetailsRepository.findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation()); return verifyBankDetails(accountDetails, bankDetails.get()); })); } @Override ServiceResult<BankDetailsResource> getById(Long id); @Override @Transactional ServiceResult<Void> submitBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override @Transactional ServiceResult<Void> updateBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override ServiceResult<ProjectBankDetailsStatusSummary> getProjectBankDetailsStatusSummary(Long projectId); @Override ServiceResult<BankDetailsResource> getByProjectAndOrganisation(Long projectId, Long organisationId); @Override ServiceResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override ServiceResult<Long> countPendingBankDetailsApprovals(); }
@Test public void saveValidBankDetails() { ValidationResult validationResult = new ValidationResult(); validationResult.setCheckPassed(true); when(silExperianEndpointMock.validate(silBankDetails)).thenReturn(serviceSuccess(validationResult)); VerificationResult verificationResult = new VerificationResult(); when(silExperianEndpointMock.verify(accountDetails)).thenReturn(serviceSuccess(verificationResult)); when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation())).thenReturn(Optional.empty(), Optional.of(bankDetails)); when(projectDetailsWorkflowHandlerMock.isSubmitted(project)).thenReturn(true); ServiceResult<Void> result = service.submitBankDetails(new ProjectOrganisationCompositeId(project.getId(), organisation.getId()),bankDetailsResource); assertTrue(result.isSuccess()); } @Test public void bankDetailsCanBeSubmittedBeforeProjectDetails() { ValidationResult validationResult = new ValidationResult(); VerificationResult verificationResult = new VerificationResult(); validationResult.setCheckPassed(true); when(projectDetailsWorkflowHandlerMock.isSubmitted(project)).thenReturn(false); when(bankDetailsMapperMock.mapToDomain(bankDetailsResource)).thenReturn(bankDetails); when(silExperianEndpointMock.validate(silBankDetails)).thenReturn(serviceSuccess(validationResult)); when(silExperianEndpointMock.verify(accountDetails)).thenReturn(serviceSuccess(verificationResult)); when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation())).thenReturn(Optional.empty(), Optional.of(bankDetails)); ServiceResult<Void> result = service.submitBankDetails(new ProjectOrganisationCompositeId(project.getId(), organisation.getId()),bankDetailsResource); assertTrue(result.isSuccess()); verify(bankDetailsRepositoryMock, times(2)).save(bankDetails); } @Test public void bankDetailsAreNotSavedIfExperianValidationFails() { ValidationResult validationResult = new ValidationResult(); Condition condition = new Condition(); condition.setSeverity("error"); condition.setDescription("Invalid sort code"); condition.setCode(5); validationResult.setConditions(singletonList(condition)); validationResult.setCheckPassed(false); when(silExperianEndpointMock.validate(silBankDetails)).thenReturn(serviceSuccess(validationResult)); when(projectDetailsWorkflowHandlerMock.isSubmitted(project)).thenReturn(true); service.submitBankDetails(new ProjectOrganisationCompositeId(project.getId(), organisation.getId()), bankDetailsResource); verify(silExperianEndpointMock, never()).verify(accountDetails); verify(bankDetailsRepositoryMock, times(1)).findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation()); } @Test public void testVerificationOccursOnceBankDetailsAreSaved() { ValidationResult validationResult = new ValidationResult(); validationResult.setCheckPassed(true); VerificationResult verificationResult = new VerificationResult(); when(silExperianEndpointMock.validate(silBankDetails)).thenReturn(serviceSuccess(validationResult)); when(silExperianEndpointMock.verify(accountDetails)).thenReturn(serviceSuccess(verificationResult)); when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation())).thenReturn(Optional.empty(), Optional.of(bankDetails)); when(projectDetailsWorkflowHandlerMock.isSubmitted(project)).thenReturn(true); service.submitBankDetails(new ProjectOrganisationCompositeId(project.getId(), organisation.getId()), bankDetailsResource); verify(silExperianEndpointMock, times(1)).verify(accountDetails); verify(bankDetailsRepositoryMock, times(2)).findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation()); }
BankDetailsServiceImpl implements BankDetailsService { @Override @Transactional public ServiceResult<Void> updateBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource) { Address address = toExperianAddressFormat(bankDetailsResource.getAddress()); AccountDetails accountDetails = new AccountDetails( bankDetailsResource.getSortCode(), bankDetailsResource.getAccountNumber(), bankDetailsResource.getCompanyName(), bankDetailsResource.getRegistrationNumber(), address ); return updateExistingBankDetails(accountDetails, bankDetailsResource).andOnSuccessReturnVoid(); } @Override ServiceResult<BankDetailsResource> getById(Long id); @Override @Transactional ServiceResult<Void> submitBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override @Transactional ServiceResult<Void> updateBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override ServiceResult<ProjectBankDetailsStatusSummary> getProjectBankDetailsStatusSummary(Long projectId); @Override ServiceResult<BankDetailsResource> getByProjectAndOrganisation(Long projectId, Long organisationId); @Override ServiceResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override ServiceResult<Long> countPendingBankDetailsApprovals(); }
@Test public void updateOfBankDetailsWithExistingBankDetailsPresent() { when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation())).thenReturn(Optional.of(bankDetails)); when(projectDetailsWorkflowHandlerMock.isSubmitted(project)).thenReturn(true); ServiceResult<Void> result = service.updateBankDetails(new ProjectOrganisationCompositeId(project.getId(), organisation.getId()),bankDetailsResource); assertTrue(result.isSuccess()); } @Test public void updateOfBankDetailsWithProjectDetailsNotSubmited() { when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation())).thenReturn(Optional.of(bankDetails)); when(projectDetailsWorkflowHandlerMock.isSubmitted(project)).thenReturn(false); ServiceResult<Void> result = service.updateBankDetails(new ProjectOrganisationCompositeId(project.getId(), organisation.getId()),bankDetailsResource); assertTrue(result.isSuccess()); } @Test public void updateOfBankDetailsWithExistingBankDetailsNotPresent() { when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation())).thenReturn(Optional.empty()); when(projectDetailsWorkflowHandlerMock.isSubmitted(project)).thenReturn(true); ServiceResult<Void> result = service.updateBankDetails(new ProjectOrganisationCompositeId(project.getId(), organisation.getId()),bankDetailsResource); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(BANK_DETAILS_CANNOT_BE_UPDATED_BEFORE_BEING_SUBMITTED)); } @Test public void updateOfBankDetailsWileApreadyApprovedNotAllowed() { bankDetailsResource.setManualApproval(true); bankDetails.setManualApproval(true); when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(bankDetailsResource.getProject(), bankDetailsResource.getOrganisation())).thenReturn(Optional.of(bankDetails)); when(projectDetailsWorkflowHandlerMock.isSubmitted(project)).thenReturn(true); ServiceResult<Void> result = service.updateBankDetails(new ProjectOrganisationCompositeId(project.getId(), organisation.getId()),bankDetailsResource); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(BANK_DETAILS_HAVE_ALREADY_BEEN_APPROVED_AND_CANNOT_BE_UPDATED)); }
UserPermissionRules { @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") public boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user) { return userToDeactivate.isExternalUser() && user.hasRole(SUPPORT); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void supportUserCanDeactivateExternalUsers() { UserResource externalUser = newUserResource().withRoleGlobal(APPLICANT).build(); UserResource internalUser = newUserResource().withRoleGlobal(IFS_ADMINISTRATOR).build(); allGlobalRoleUsers.forEach(user -> { if (user.hasRole(SUPPORT)) { assertTrue(rules.supportUserCanDeactivateExternalUsers(externalUser, user)); assertFalse(rules.supportUserCanDeactivateExternalUsers(internalUser, user)); } else { assertFalse(rules.supportUserCanDeactivateExternalUsers(externalUser, user)); assertFalse(rules.supportUserCanDeactivateExternalUsers(internalUser, user)); } }); }
BankDetailsServiceImpl implements BankDetailsService { @Override public ServiceResult<ProjectBankDetailsStatusSummary> getProjectBankDetailsStatusSummary(Long projectId) { Project project = projectRepository.findById(projectId).get(); ProcessRole leadProcessRole = project.getApplication().getLeadApplicantProcessRole(); Organisation leadOrganisation = organisationRepository.findById(leadProcessRole.getOrganisationId()).get(); List<Organisation> sortedOrganisations = new PrioritySorting<>(projectUsersHelper.getPartnerOrganisations(projectId), leadOrganisation, Organisation::getName).unwrap(); final List<BankDetailsStatusResource> bankDetailsStatusResources = simpleMap(sortedOrganisations, org -> getBankDetailsStatusForOrg(project, org)); ProjectBankDetailsStatusSummary projectBankDetailsStatusSummary = new ProjectBankDetailsStatusSummary(project.getApplication().getCompetition().getId(), project.getApplication().getCompetition().getName(), project.getId(), project.getName(), project.getApplication().getId(), bankDetailsStatusResources, leadOrganisation.getName()); return serviceSuccess(projectBankDetailsStatusSummary); } @Override ServiceResult<BankDetailsResource> getById(Long id); @Override @Transactional ServiceResult<Void> submitBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override @Transactional ServiceResult<Void> updateBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override ServiceResult<ProjectBankDetailsStatusSummary> getProjectBankDetailsStatusSummary(Long projectId); @Override ServiceResult<BankDetailsResource> getByProjectAndOrganisation(Long projectId, Long organisationId); @Override ServiceResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override ServiceResult<Long> countPendingBankDetailsApprovals(); }
@Test public void getProjectBankDetailsStatusSummary() { Long projectId = 123L; Competition competition = newCompetition().withName("Greener Jet Engines").build(); Application application = newApplication().withCompetition(competition).build(); organisation.setOrganisationType(newOrganisationType().withOrganisationType(OrganisationTypeEnum.BUSINESS).build()); ProcessRole leadApplicantRole = newProcessRole().withRole(Role.LEADAPPLICANT).withOrganisationId(organisation.getId()).withApplication(application).build(); Project project = newProject().withId(projectId).withApplication(application).build(); when(projectRepositoryMock.findById(projectId)).thenReturn(Optional.of(project)); when(bankDetailsRepositoryMock.findByProjectIdAndOrganisationId(projectId, organisation.getId())).thenReturn(Optional.of(bankDetails)); when(bankDetailsMapperMock.mapToResource(bankDetails)).thenReturn(bankDetailsResource); when(projectUsersHelperMock.getPartnerOrganisations(projectId)).thenReturn(singletonList(organisation)); when(projectFinanceService.financeChecksDetails(projectId, organisation.getId())).thenReturn(serviceSuccess(newProjectFinanceResource().thatIsRequestingFunding().build())); when(organisationRepositoryMock.findById(leadApplicantRole.getOrganisationId())).thenReturn(Optional.of(organisation)); List<BankDetailsStatusResource> bankDetailsStatusResource = newBankDetailsStatusResource() .withOrganisationId(organisation.getId()) .withOrganisationName(organisation.getName()) .withBankDetailsStatus(ProjectActivityStates.ACTION_REQUIRED) .build(1); ProjectBankDetailsStatusSummary expected = newProjectBankDetailsStatusSummary().build(); expected.setProjectId(projectId); expected.setApplicationId(application.getId()); expected.setCompetitionId(competition.getId()); expected.setCompetitionName(competition.getName()); expected.setBankDetailsStatusResources(bankDetailsStatusResource); ServiceResult<ProjectBankDetailsStatusSummary> result = service.getProjectBankDetailsStatusSummary(projectId); assertTrue(result.isSuccess()); assertEquals(expected, result.getSuccess()); }
BankDetailsServiceImpl implements BankDetailsService { @Override public ServiceResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals() { List<BankDetailsReviewResource> pendingBankDetails = bankDetailsRepository.getPendingBankDetailsApprovalsForProjectStateNotIn(asList(WITHDRAWN, HANDLED_OFFLINE, COMPLETED_OFFLINE)); return serviceSuccess(pendingBankDetails); } @Override ServiceResult<BankDetailsResource> getById(Long id); @Override @Transactional ServiceResult<Void> submitBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override @Transactional ServiceResult<Void> updateBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override ServiceResult<ProjectBankDetailsStatusSummary> getProjectBankDetailsStatusSummary(Long projectId); @Override ServiceResult<BankDetailsResource> getByProjectAndOrganisation(Long projectId, Long organisationId); @Override ServiceResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override ServiceResult<Long> countPendingBankDetailsApprovals(); }
@Test public void getPendingBankDetailsApprovals() { List<BankDetailsReviewResource> pendingBankDetails = singletonList(new BankDetailsReviewResource( 1L, 11L, "Comp1", 12L, "project1", 22L, "Org1")); when(bankDetailsRepositoryMock.getPendingBankDetailsApprovalsForProjectStateNotIn(asList(WITHDRAWN, HANDLED_OFFLINE, COMPLETED_OFFLINE))).thenReturn(pendingBankDetails); ServiceResult<List<BankDetailsReviewResource>> result = service.getPendingBankDetailsApprovals(); assertTrue(result.isSuccess()); assertEquals(pendingBankDetails, result.getSuccess()); }
BankDetailsServiceImpl implements BankDetailsService { @Override public ServiceResult<Long> countPendingBankDetailsApprovals() { Long countBankDetails = bankDetailsRepository.countPendingBankDetailsApprovalsForProjectStateNotIn(asList(WITHDRAWN, HANDLED_OFFLINE, COMPLETED_OFFLINE)); return serviceSuccess(countBankDetails); } @Override ServiceResult<BankDetailsResource> getById(Long id); @Override @Transactional ServiceResult<Void> submitBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override @Transactional ServiceResult<Void> updateBankDetails(ProjectOrganisationCompositeId projectOrganisationCompositeId, BankDetailsResource bankDetailsResource); @Override ServiceResult<ProjectBankDetailsStatusSummary> getProjectBankDetailsStatusSummary(Long projectId); @Override ServiceResult<BankDetailsResource> getByProjectAndOrganisation(Long projectId, Long organisationId); @Override ServiceResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override ServiceResult<Long> countPendingBankDetailsApprovals(); }
@Test public void countPendingBankDetailsApprovals() { Long pendingBankDetailsCount = 8L; when(bankDetailsRepositoryMock.countPendingBankDetailsApprovalsForProjectStateNotIn(asList(WITHDRAWN, HANDLED_OFFLINE, COMPLETED_OFFLINE))).thenReturn(pendingBankDetailsCount); ServiceResult<Long> result = service.countPendingBankDetailsApprovals(); assertTrue(result.isSuccess()); assertEquals(pendingBankDetailsCount, result.getSuccess()); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") public boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user) { return isLeadPartner(project.getId(), user.getId()) && isProjectActive(project.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void leadPartnersCanCreateSignedGrantOfferLetter() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource() .withProjectState(ProjectState.SETUP) .build(); setupUserAsLeadPartner(project, user); when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); assertTrue(rules.leadPartnerCanUploadGrantOfferLetter(project, user)); } @Test public void nonLeadPartnersCannotCreateSignedGrantOfferLetter() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setupUserNotAsLeadPartner(project, user); assertFalse(rules.leadPartnerCanUploadGrantOfferLetter(project, user)); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") public boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user) { return isProjectManager(project.getId(), user.getId()) && isProjectActive(project.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void projectManagerCanCreateSignedGrantOfferLetter() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource() .withProjectState(ProjectState.SETUP) .build(); setUpUserAsProjectManager(project, user); when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); assertTrue(rules.projectManagerCanUploadGrantOfferLetter(project, user)); } @Test public void nonProjectManagerCannotCreateSignedGrantOfferLetter() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserNotAsProjectManager(user); assertFalse(rules.projectManagerCanUploadGrantOfferLetter(project, user)); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") public boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user) { return isPartner(project.getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void partnersCanViewGrantOfferLetterDetails() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setupUserAsPartner(project, user); assertTrue(rules.partnersCanViewGrantOfferLetter(project, user)); } @Test public void nonPartnersCannotViewGrantOfferLetterDetails() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setupUserNotAsPartner(project, user); assertFalse(rules.partnersCanViewGrantOfferLetter(project, user)); }
UserPermissionRules { @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") public boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user) { return userToActivate.isExternalUser() && user.hasRole(SUPPORT); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void supportUserCanReactivateExternalUsers() { UserResource externalUser = newUserResource().withRoleGlobal(APPLICANT).build(); UserResource internalUser = newUserResource().withRoleGlobal(IFS_ADMINISTRATOR).build(); allGlobalRoleUsers.forEach(user -> { if (user.hasRole(SUPPORT)) { assertTrue(rules.supportUserCanReactivateExternalUsers(externalUser, user)); assertFalse(rules.supportUserCanReactivateExternalUsers(internalUser, user)); } else { assertFalse(rules.supportUserCanReactivateExternalUsers(externalUser, user)); assertFalse(rules.supportUserCanReactivateExternalUsers(internalUser, user)); } }); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") public boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user) { return isPartner(project.getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void partnersCanDownloadGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setupUserAsPartner(project, user); assertTrue(rules.partnersCanDownloadGrantOfferLetter(project, user)); } @Test public void nonPartnersCannotDownloadGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setupUserNotAsPartner(project, user); assertFalse(rules.partnersCanDownloadGrantOfferLetter(project, user)); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") public boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user) { return isInternalAdmin(user); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void compAdminsCanDownloadGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserAsCompAdmin(project, user); assertTrue(rules.internalUsersCanDownloadGrantOfferLetter(project, user)); } @Test public void nonCompAdminsCannotDownloadGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserNotAsCompAdmin(project, user); assertFalse(rules.internalUsersCanDownloadGrantOfferLetter(project, user)); } @Test public void projectFinanceCanDownloadGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserAsProjectFinanceUser(project, user); assertTrue(rules.internalUsersCanDownloadGrantOfferLetter(project, user)); } @Test public void nonProjectFinanceCannotDownloadGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserNotAsProjectFinanceUser(project, user); assertFalse(rules.internalUsersCanDownloadGrantOfferLetter(project, user)); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") public boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user) { return isInternalAdmin(user); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void compAdminsCanViewGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserAsCompAdmin(project, user); assertTrue(rules.internalUsersCanViewGrantOfferLetter(project, user)); } @Test public void nonCompAdminsCannotViewGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserNotAsCompAdmin(project, user); assertFalse(rules.internalUsersCanViewGrantOfferLetter(project, user)); } @Test public void projectFinanceCanViewGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserAsProjectFinanceUser(project, user); assertTrue(rules.internalUsersCanViewGrantOfferLetter(project, user)); } @Test public void nonProjectFinanceCannotViewGrantOfferLetterDocuments() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserNotAsProjectFinanceUser(project, user); assertFalse(rules.internalUsersCanViewGrantOfferLetter(project, user)); }
UserPermissionRules { @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") public boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user) { return userToUpdate.getId().equals(user.getId()); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void usersCanAgreeSiteTermsAndConditionsForThemselves() { allGlobalRoleUsers.forEach(user -> allGlobalRoleUsers.forEach(otherUser -> { if (user.equals(otherUser)) { assertTrue(rules.usersCanAgreeSiteTermsAndConditions(otherUser, user)); } else { assertFalse(rules.usersCanAgreeSiteTermsAndConditions(otherUser, user)); } })); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") public boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user) { return isProjectManager(projectCompositeId.id(), user.getId()) && isProjectActive(projectCompositeId.id()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void projectManagerCanSubmitOfferLetter() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource() .withProjectState(ProjectState.SETUP) .build(); setUpUserAsProjectManager(project, user); when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); assertTrue(rules.projectManagerSubmitGrantOfferLetter(ProjectCompositeId.id(project.getId()), user)); } @Test public void nonProjectManagerCannotSubmitOfferLetter() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserNotAsProjectManager(user); assertFalse(rules.projectManagerSubmitGrantOfferLetter(ProjectCompositeId.id(project.getId()), user)); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") public boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user) { return isInternal(user) && isProjectActive(project.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void compAdminsCanApproveSignedGrantOfferLetters() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource() .withProjectState(ProjectState.SETUP) .build(); setUpUserAsCompAdmin(project, user); when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); assertTrue(rules.internalUsersCanApproveOrRejectSignedGrantOfferLetter(project, user)); } @Test public void nonCompAdminsCannotApproveSignedGrantOfferLetters() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setUpUserNotAsCompAdmin(project, user); assertFalse(rules.internalUsersCanApproveOrRejectSignedGrantOfferLetter(project, user)); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") public boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user) { return isLeadPartner(project.getId(), user.getId()) && isProjectActive(project.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void leadPartnerCanDeleteSignedGrantOfferLetter() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource() .withProjectState(ProjectState.SETUP) .build(); setupUserAsLeadPartner(project, user); when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); assertTrue(rules.leadPartnerCanDeleteSignedGrantOfferLetter(project, user)); } @Test public void nonLeadPartnerCanDeleteSignedGrantOfferLetter() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setupUserNotAsLeadPartner(project, user); assertFalse(rules.leadPartnerCanDeleteSignedGrantOfferLetter(project, user)); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") public boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user) { return isInternal(user) && isProjectActive(project.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void projectFinanceUserCanSendGrantOfferLetter() { ProjectResource project = newProjectResource() .withProjectState(ProjectState.SETUP) .build(); when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); assertTrue(rules.internalUserCanSendGrantOfferLetter(project, projectFinanceUser())); } @Test public void compAdminsUserCanSendGrantOfferLetter() { ProjectResource project = newProjectResource() .withProjectState(ProjectState.SETUP) .build(); when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); assertTrue(rules.internalUserCanSendGrantOfferLetter(project, compAdminUser())); } @Test public void partnerUserCannotSendGrantOfferLetter() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setupUserAsPartner(project, user); assertFalse(rules.internalUserCanSendGrantOfferLetter(project, user)); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") public boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user) { return isInternalAdmin(user); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void internalUserCanViewSendGrantOfferLetterStatus() { ProjectResource project = newProjectResource().build(); allGlobalRoleUsers.forEach(user -> { if (user.equals(projectFinanceUser()) || user.equals(compAdminUser())) { assertTrue(rules.internalAdminUserCanViewSendGrantOfferLetterStatus(project, user)); } else { assertFalse(rules.internalAdminUserCanViewSendGrantOfferLetterStatus(project, user)); } }); }
UserPermissionRules { @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") public boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user) { return roleCommand.getTargetRole().equals(APPLICANT) && user.getId().equals(roleCommand.getUserId()) && user.hasRole(ASSESSOR); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void assessorCanRequestApplicantRole() { UserResource otherAssessor = newUserResource().withRolesGlobal(singletonList(ASSESSOR)).build(); assertFalse(rules.assessorCanRequestApplicantRole(new GrantRoleCommand(assessorUser().getId(), APPLICANT), compAdminUser())); assertFalse(rules.assessorCanRequestApplicantRole(new GrantRoleCommand(otherAssessor.getId(), APPLICANT), assessorUser())); assertFalse(rules.assessorCanRequestApplicantRole(new GrantRoleCommand(assessorUser().getId(), IFS_ADMINISTRATOR), assessorUser())); assertTrue(rules.assessorCanRequestApplicantRole(new GrantRoleCommand(assessorUser().getId(), APPLICANT), assessorUser())); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") public boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user) { return isPartner(project.getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void partnersCanViewSendGrantOfferLetterStatus() { ProjectResource project = newProjectResource().build(); UserResource user = newUserResource().build(); setupUserAsPartner(project, user); assertTrue(rules.externalUserCanViewSendGrantOfferLetterStatus(project, user)); } @Test public void nonPartnersCannotViewSendGrantOfferLetterStatus() { ProjectResource project = newProjectResource().build(); allGlobalRoleUsers.forEach(user2 -> assertFalse(rules.externalUserCanViewSendGrantOfferLetterStatus(project, user2))); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") public boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user) { return isSupport(user); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void supportUserCanViewSendGrantOfferLetterStatus() { ProjectResource project = newProjectResource().build(); allGlobalRoleUsers.forEach(user -> { if (user.equals(supportUser())) { assertTrue(rules.supportUserCanViewSendGrantOfferLetterStatus(project, user)); } else { assertFalse(rules.supportUserCanViewSendGrantOfferLetterStatus(project, user)); } }); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") public boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user) { Application application = applicationRepository.findById(project.getApplication()).get(); return userIsStakeholderInCompetition(application.getCompetition().getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void onlyStakeholdersAssignedToCompetitionCanViewSendGrantOfferLetterStatus() { when(stakeholderRepository.existsByCompetitionIdAndUserId(competition.getId(), stakeholderUserResourceOnCompetition.getId())).thenReturn(true); assertTrue(rules.stakeholdersCanViewSendGrantOfferLetterStatus(projectResource1, stakeholderUserResourceOnCompetition)); assertFalse(rules.stakeholdersCanViewSendGrantOfferLetterStatus(projectResource1, stakeholderUser())); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") public boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user) { return isSupport(user); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void supportUsersCanDownloadGrantOfferLetter() { ProjectResource project = newProjectResource().build(); allGlobalRoleUsers.forEach(user -> { if (user.equals(supportUser())) { assertTrue(rules.supportUsersCanDownloadGrantOfferLetter(project, user)); } else { assertFalse(rules.supportUsersCanDownloadGrantOfferLetter(project, user)); } }); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") public boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user) { Application application = applicationRepository.findById(project.getApplication()).get(); return userIsInnovationLeadOnCompetition(application.getCompetition().getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void onlyInnovationLeadUsersAssignedToCompetitionCanDownloadGrantOfferLetter() { assertTrue(rules.innovationLeadUsersCanDownloadGrantOfferLetter(projectResource1, innovationLeadUserResourceOnProject1)); assertFalse(rules.innovationLeadUsersCanDownloadGrantOfferLetter(projectResource1, innovationLeadUser())); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") public boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user) { Application application = applicationRepository.findById(project.getApplication()).get(); return userIsStakeholderInCompetition(application.getCompetition().getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void onlyStakeholdersAssignedToCompetitionCanDownloadGrantOfferLetter() { when(stakeholderRepository.existsByCompetitionIdAndUserId(competition.getId(), stakeholderUserResourceOnCompetition.getId())).thenReturn(true); assertTrue(rules.stakeholdersCanDownloadGrantOfferLetter(projectResource1, stakeholderUserResourceOnCompetition)); assertFalse(rules.stakeholdersCanDownloadGrantOfferLetter(projectResource1, stakeholderUser())); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") public boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user) { Application application = applicationRepository.findById(project.getApplication()).get(); return userIsInnovationLeadOnCompetition(application.getCompetition().getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void onlyInnovationLeadUsersAssignedToCompetitionCanViewGrantOfferLetter() { assertTrue(rules.innovationLeadUsersCanViewGrantOfferLetter(projectResource1, innovationLeadUserResourceOnProject1)); assertFalse(rules.innovationLeadUsersCanViewGrantOfferLetter(projectResource1, innovationLeadUser())); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") public boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user) { Application application = applicationRepository.findById(project.getApplication()).get(); return userIsStakeholderInCompetition(application.getCompetition().getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void onlyStakeholdersAssignedToCompetitionCanViewGrantOfferLetter() { when(stakeholderRepository.existsByCompetitionIdAndUserId(competition.getId(), stakeholderUserResourceOnCompetition.getId())).thenReturn(true); assertTrue(rules.stakeholdersCanViewGrantOfferLetter(projectResource1, stakeholderUserResourceOnCompetition)); assertFalse(rules.stakeholdersCanViewGrantOfferLetter(projectResource1, stakeholderUser())); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") public boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user) { return isMonitoringOfficer(project.getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void monitoringOfficersCanViewGrantOfferLetterOnTheirProjects() { when(projectMonitoringOfficerRepository.existsByProjectIdAndUserId(projectResource1.getId(), monitoringOfficerUser().getId())).thenReturn(true); assertTrue(rules.monitoringOfficerCanViewGrantOfferLetter(projectResource1, monitoringOfficerUser())); }
UserPermissionRules { @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") public boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user) { return roleCommand.getTargetRole().equals(APPLICANT) && user.getId().equals(roleCommand.getUserId()) && user.hasRole(STAKEHOLDER); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void stakeholderCanRequestApplicantRole() { UserResource otherStakeholder = newUserResource().withRolesGlobal(singletonList(STAKEHOLDER)).build(); assertFalse(rules.stakeholderCanRequestApplicantRole(new GrantRoleCommand(stakeholderUser().getId(), APPLICANT), compAdminUser())); assertFalse(rules.stakeholderCanRequestApplicantRole(new GrantRoleCommand(otherStakeholder.getId(), APPLICANT), stakeholderUser())); assertFalse(rules.stakeholderCanRequestApplicantRole(new GrantRoleCommand(stakeholderUser().getId(), IFS_ADMINISTRATOR), assessorUser())); assertTrue(rules.stakeholderCanRequestApplicantRole(new GrantRoleCommand(stakeholderUser().getId(), APPLICANT), stakeholderUser())); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") public boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user) { return isMonitoringOfficer(project.getId(), user.getId()); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void monitoringOfficersCanViewSendGrantOfferLetterOnTheirProjects() { when(projectMonitoringOfficerRepository.existsByProjectIdAndUserId(projectResource1.getId(), monitoringOfficerUser().getId())).thenReturn(true); assertTrue(rules.monitoringOfficerCanViewSendGrantOfferLetterStatus(projectResource1, monitoringOfficerUser())); }
GrantOfferLetterPermissionRules extends BasePermissionRules { @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") public boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user) { return isSupport(user); } @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Partners can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Competitions team & Project Finance can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Support users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Innovation lead users can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DOWNLOAD_GRANT_OFFER", description = "Stakeholders can download grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanDownloadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Partners can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean partnersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Competitions team & Project Finance can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean internalUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Support users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract)") boolean supportUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Innovation lead users can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean innovationLeadUsersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Stakeholders can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean stakeholdersCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER", description = "Monitoring officer can view grant offer documents (Unsigned grant offer, signed grant offer, Additional contract), of projects from competition assigned to them") boolean monitoringOfficerCanViewGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean leadPartnerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "UPLOAD_SIGNED_GRANT_OFFER", description = "Project manager or Lead partner can upload signed grant offer letter") boolean projectManagerCanUploadGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "DELETE_SIGNED_GRANT_OFFER", description = "Lead partner can delete signed grant offer letter") boolean leadPartnerCanDeleteSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "SUBMIT_GRANT_OFFER_LETTER", description = "Project manager can submit the grant offer letter, or get details to do so with DocuSign") boolean projectManagerSubmitGrantOfferLetter(ProjectCompositeId projectCompositeId, UserResource user); @PermissionRule( value = "SEND_GRANT_OFFER_LETTER", description = "Internal users can send the Grant Offer Letter notification") boolean internalUserCanSendGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "APPROVE_SIGNED_GRANT_OFFER_LETTER", description = "Internal users can approve the signed Grant Offer Letter") boolean internalUsersCanApproveOrRejectSignedGrantOfferLetter(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Internal users can view the send status of Grant Offer Letter for a project") boolean internalAdminUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Monitoring officers can view the send status of Grant Offer Letter for a project") boolean monitoringOfficerCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Support users can view the send status of Grant Offer Letter for a project") boolean supportUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Innovation lead users can view the send status of Grant Offer Letter for a project from competition assigned to them") boolean innovationLeadUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Stakeholders view the send status of Grant Offer Letter for a project from competition assigned to them") boolean stakeholdersCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); @PermissionRule( value = "VIEW_GRANT_OFFER_LETTER_SEND_STATUS", description = "Partners can view the send status of Grant Offer Letter for a project") boolean externalUserCanViewSendGrantOfferLetterStatus(ProjectResource project, UserResource user); }
@Test public void supportUsersCanViewGrantOfferLetter() { ProjectResource project = newProjectResource().build(); allGlobalRoleUsers.forEach(user -> { if (user.equals(supportUser())) { assertTrue(rules.supportUsersCanViewGrantOfferLetter(project, user)); } else { assertFalse(rules.supportUsersCanViewGrantOfferLetter(project, user)); } }); }
GrantOfferLetterController { @GetMapping("/{projectId}/signed-grant-offer") public @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId) throws IOException { return fileControllerUtils.handleFileDownload(() -> grantOfferLetterService.getSignedGrantOfferLetterFileAndContents(projectId)); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void getGrantOfferLetterFileContents() throws Exception { Function<GrantOfferLetterService, ServiceResult<FileAndContents>> serviceCallToUpload = (service) -> service.getGrantOfferLetterFileAndContents(projectId); assertGetFileContents("/project/{projectId}/grant-offer", new Object[] {projectId}, emptyMap(), grantOfferLetterService, serviceCallToUpload). andDo(documentFileGetContentsMethod("project/{method-name}")); }
GrantOfferLetterController { @GetMapping("/{projectId}/additional-contract") public @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId) throws IOException { return fileControllerUtils.handleFileDownload(() -> grantOfferLetterService.getAdditionalContractFileAndContents(projectId)); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void getAdditionalContractFileContents() throws Exception { Function<GrantOfferLetterService, ServiceResult<FileAndContents>> serviceCallToUpload = (service) -> service.getAdditionalContractFileAndContents(projectId); assertGetFileContents("/project/{projectId}/additional-contract", new Object[] {projectId}, emptyMap(), grantOfferLetterService, serviceCallToUpload). andDo(documentFileGetContentsMethod("project/{method-name}")); }
GrantOfferLetterController { @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") public RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId) throws IOException { return grantOfferLetterService.getGrantOfferLetterFileEntryDetails(projectId).toGetResponse(); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void getGrantOfferLetterFileEntryDetails() throws Exception { Function<GrantOfferLetterService, ServiceResult<FileEntryResource>> serviceCallToUpload = (service) -> service.getSignedGrantOfferLetterFileEntryDetails(projectId); assertGetFileDetails("/project/{projectId}/signed-grant-offer/details", new Object[] {projectId}, emptyMap(), grantOfferLetterService, serviceCallToUpload). andDo(documentFileGetDetailsMethod("project/{method-name}")); }
GrantOfferLetterController { @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") public RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId) throws IOException { return grantOfferLetterService.getAdditionalContractFileEntryDetails(projectId).toGetResponse(); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void getAdditionalContractFileEntryDetails() throws Exception { Function<GrantOfferLetterService, ServiceResult<FileEntryResource>> serviceCallToUpload = (service) -> service.getAdditionalContractFileEntryDetails(projectId); assertGetFileDetails("/project/{projectId}/additional-contract/details", new Object[] {projectId}, emptyMap(), grantOfferLetterService, serviceCallToUpload). andDo(documentFileGetDetailsMethod("project/{method-name}")); }
GrantOfferLetterController { @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") public RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request) { return fileControllerUtils.handleFileUpload(contentType, contentLength, originalFilename, fileValidator, validMediaTypesForProjectSetupGrantOfferLetter, maxFilesizeBytesForProjectSetupGrantOfferLetter, request, (fileAttributes, inputStreamSupplier) -> grantOfferLetterService.createAdditionalContractFileEntry(projectId, fileAttributes.toFileEntryResource(), inputStreamSupplier) ); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void addAdditionalContractFile() throws Exception { BiFunction<GrantOfferLetterService, FileEntryResource, ServiceResult<FileEntryResource>> serviceCallToUpload = (service, fileToUpload) -> service.createAdditionalContractFileEntry(eq(projectId), eq(fileToUpload), fileUploadInputStreamExpectations()); assertFileUploadProcess("/project/" + projectId + "/additional-contract/", fileValidator, mediaTypes, grantOfferLetterService, serviceCallToUpload). andDo(documentFileUploadMethod("project/{method-name}")); }
GrantOfferLetterController { @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") public RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId) { return grantOfferLetterService.removeGrantOfferLetterFileEntry(projectId).toDeleteResponse(); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void removeGrantOfferLetterFile() throws Exception { when(grantOfferLetterService.removeGrantOfferLetterFileEntry(projectId)).thenReturn(serviceSuccess()); mockMvc.perform(delete("/project/{projectId}/grant-offer", projectId)). andExpect(status().isNoContent()). andDo(document("project/{method-name}")); }
GrantOfferLetterController { @DeleteMapping(value = "/{projectId}/grant-offer/reset") public RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId) { return grantOfferLetterService.resetGrantOfferLetter(projectId).toDeleteResponse(); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void resetGrantOfferLetter() throws Exception { when(grantOfferLetterService.resetGrantOfferLetter(projectId)).thenReturn(serviceSuccess()); mockMvc.perform(delete("/project/{projectId}/grant-offer/reset", projectId)). andExpect(status().isNoContent()). andDo(document("project/{method-name}")); }
GrantOfferLetterController { @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") public RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId) { return grantOfferLetterService.removeSignedGrantOfferLetterFileEntry(projectId).toDeleteResponse(); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void removeSignedGrantOfferLetterFile() throws Exception { when(grantOfferLetterService.removeSignedGrantOfferLetterFileEntry(projectId)).thenReturn(serviceSuccess()); mockMvc.perform(delete("/project/{projectId}/signed-grant-offer-letter", projectId)). andExpect(status().isNoContent()). andDo(document("project/{method-name}")); }
UserPermissionRules { @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") public boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user) { return roleCommand.getTargetRole().equals(APPLICANT) && user.getId().equals(roleCommand.getUserId()) && user.hasRole(MONITORING_OFFICER); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void monitoringOfficerCanRequestApplicantRole() { UserResource otherMonitoringOfficer = newUserResource().withRolesGlobal(singletonList(MONITORING_OFFICER)).build(); assertFalse(rules.monitoringOfficerCanRequestApplicantRole(new GrantRoleCommand(monitoringOfficerUser().getId(), APPLICANT), compAdminUser())); assertFalse(rules.monitoringOfficerCanRequestApplicantRole(new GrantRoleCommand(otherMonitoringOfficer.getId(), APPLICANT), monitoringOfficerUser())); assertFalse(rules.monitoringOfficerCanRequestApplicantRole(new GrantRoleCommand(monitoringOfficerUser().getId(), IFS_ADMINISTRATOR), assessorUser())); assertTrue(rules.monitoringOfficerCanRequestApplicantRole(new GrantRoleCommand(monitoringOfficerUser().getId(), APPLICANT), monitoringOfficerUser())); }
SilEmailService implements EmailService { @Override public ServiceResult<List<EmailAddress>> sendEmail(EmailAddress from, List<EmailAddress> to, String subject, String plainTextBodyContent, String htmlBodyContent) { SilEmailAddress fromEmail = new SilEmailAddress(from.getName(), from.getEmailAddress()); List<SilEmailAddress> toEmails = simpleMap(to, recipient -> new SilEmailAddress(recipient.getName(), recipient.getEmailAddress())); SilEmailBody plainTextBody = new SilEmailBody("text/plain", plainTextBodyContent); SilEmailBody htmlBody = new SilEmailBody("text/html", htmlBodyContent); if (toEmails != null) { for (SilEmailAddress silEmailAddress : toEmails) { LOG.info("About to send email to: " + (silEmailAddress != null ? silEmailAddress.getEmail() : " no email address ") + " with subject " + subject); } } else { LOG.error("toEmails is null"); } ServiceResult<List<EmailAddress>> emailsSentResult = endpoint.sendEmail(new SilEmailMessage(fromEmail, toEmails, subject, plainTextBody, htmlBody)).andOnSuccessReturn(successfullySent -> to); if (toEmails != null) { for (SilEmailAddress silEmailAddress : toEmails) { LOG.info("Email sent to: " + (silEmailAddress != null ? silEmailAddress.getEmail() : " no email address ") + " with subject " + subject); } } else { LOG.error("toEmails is null"); } return emailsSentResult; } @Override ServiceResult<List<EmailAddress>> sendEmail(EmailAddress from, List<EmailAddress> to, String subject, String plainTextBodyContent, String htmlBodyContent); }
@Test public void testSendEmail() { EmailAddress from = newEmailAddressResource().with(name("From User")).withEmail("[email protected]").build(); List<EmailAddress> to = newEmailAddressResource().with(names("To User 1", "To User 2")).withEmail("[email protected]", "[email protected]").build(2); SilEmailAddress silEmailFrom = new SilEmailAddress("From User", "[email protected]"); SilEmailAddress silEmailTo1 = new SilEmailAddress("To User 1", "[email protected]"); SilEmailAddress silEmailTo2 = new SilEmailAddress("To User 2", "[email protected]"); SilEmailBody silEmailBody = new SilEmailBody("text/plain", "Some plain text"); SilEmailBody silEmailBody2 = new SilEmailBody("text/html", "Some HTML"); SilEmailMessage expectedMessageToSend = new SilEmailMessage(silEmailFrom, asList(silEmailTo1, silEmailTo2), "A subject", silEmailBody, silEmailBody2); when(endpointMock.sendEmail(expectedMessageToSend)).thenReturn(serviceSuccess(expectedMessageToSend)); ServiceResult<List<EmailAddress>> emailResult = service.sendEmail(from, to, "A subject", "Some plain text", "Some HTML"); assertTrue(emailResult.isSuccess()); assertEquals(to, emailResult.getSuccess()); verify(endpointMock).sendEmail(expectedMessageToSend); } @Test public void testSendEmailButEndpointFails() { EmailAddress from = newEmailAddressResource().with(name("From User")).withEmail("[email protected]").build(); List<EmailAddress> to = newEmailAddressResource().with(names("To User 1", "To User 2")).withEmail("[email protected]", "[email protected]").build(2); SilEmailAddress silEmailFrom = new SilEmailAddress("From User", "[email protected]"); SilEmailAddress silEmailTo1 = new SilEmailAddress("To User 1", "[email protected]"); SilEmailAddress silEmailTo2 = new SilEmailAddress("To User 2", "[email protected]"); SilEmailBody silEmailBody = new SilEmailBody("text/plain", "Some plain text"); SilEmailBody silEmailBody2 = new SilEmailBody("text/html", "Some HTML"); SilEmailMessage expectedMessageToSend = new SilEmailMessage(silEmailFrom, asList(silEmailTo1, silEmailTo2), "A subject", silEmailBody, silEmailBody2); when(endpointMock.sendEmail(expectedMessageToSend)).thenReturn(serviceFailure(internalServerErrorError())); ServiceResult<List<EmailAddress>> emailResult = service.sendEmail(from, to, "A subject", "Some plain text", "Some HTML"); assertTrue(emailResult.isFailure()); assertTrue(emailResult.getFailure().is(internalServerErrorError())); }
GrantOfferLetterController { @PostMapping("/{projectId}/signed-grant-offer-letter/approval") public RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource) { return grantOfferLetterService.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource).toPostResponse(); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void approveOrRejectSignedGrantOfferLetter() throws Exception { GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.APPROVED, null); when(grantOfferLetterService.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource)).thenReturn(serviceSuccess()); mockMvc.perform(post("/project/{projectId}/signed-grant-offer-letter/approval", projectId) .contentType(APPLICATION_JSON) .content(toJson(grantOfferLetterApprovalResource))) .andExpect(status().isOk()) .andReturn(); verify(grantOfferLetterService).approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); }
GrantOfferLetterController { @GetMapping("/{projectId}/grant-offer-letter/current-state") public RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId) { return grantOfferLetterService.getGrantOfferLetterState(projectId).toGetResponse(); } @GetMapping("/{projectId}/signed-grant-offer") @ResponseBody ResponseEntity<Object> getGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/grant-offer") @ResponseBody ResponseEntity<Object> getGeneratedGrantOfferLetterFileContents( @PathVariable("projectId") long projectId); @GetMapping("/{projectId}/additional-contract") @ResponseBody ResponseEntity<Object> getAdditionalContractFileContents( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/signed-grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/grant-offer/details", produces = "application/json") RestResult<FileEntryResource> getGrantOfferLetterFileEntryDetails( @PathVariable("projectId") long projectId); @GetMapping(value = "/{projectId}/additional-contract/details", produces = "application/json") RestResult<FileEntryResource> getAdditionalContractFileEntryDetails( @PathVariable("projectId") long projectId); @PostMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<FileEntryResource> addSignedGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<FileEntryResource> addGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @DeleteMapping(value = "/{projectId}/grant-offer", produces = "application/json") RestResult<Void> removeGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<Void> removeAdditionalContractFile(@PathVariable(value = "projectId") long projectId); @DeleteMapping(value = "/{projectId}/signed-grant-offer-letter", produces = "application/json") RestResult<Void> removeSignedGrantOfferLetterFile(@PathVariable(value = "projectId") long projectId); @PostMapping(value = "/{projectId}/additional-contract", produces = "application/json") RestResult<FileEntryResource> addAdditionalContractFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PutMapping(value = "/{projectId}/signed-grant-offer", produces = "application/json") RestResult<Void> updateGrantOfferLetterFile( @RequestHeader(value = "Content-Type", required = false) String contentType, @RequestHeader(value = "Content-Length", required = false) String contentLength, @PathVariable(value = "projectId") long projectId, @RequestParam(value = "filename", required = false) String originalFilename, HttpServletRequest request); @PostMapping("/{projectId}/grant-offer/submit") RestResult<Void> submitGrantOfferLetter(@PathVariable("projectId") long projectId); @PostMapping("/{projectId}/grant-offer/send") RestResult<Void> sendGrantOfferLetter(@PathVariable("projectId") final Long projectId); @PostMapping("/{projectId}/signed-grant-offer-letter/approval") RestResult<Void> approveOrRejectSignedGrantOfferLetter(@PathVariable("projectId") final Long projectId, @RequestBody final GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @GetMapping("/{projectId}/grant-offer-letter/current-state") RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(@PathVariable("projectId") final Long projectId); @GetMapping("/{projectId}/grant-offer-letter/docusign-url") RestResult<StringResource> getDocusignUrl( @PathVariable long projectId); @PostMapping("/{projectId}/grant-offer-letter/docusign-import-document") RestResult<Void> importSignedOfferLetter( @PathVariable long projectId); @DeleteMapping(value = "/{projectId}/grant-offer/reset") RestResult<Void> resetGrantOfferLetter( @PathVariable long projectId); }
@Test public void getGrantOfferLetterState() throws Exception { GrantOfferLetterStateResource stateInformation = stateInformationForNonPartnersView(GrantOfferLetterState.APPROVED, GOL_SIGNED); when(grantOfferLetterService.getGrantOfferLetterState(projectId)).thenReturn(serviceSuccess(stateInformation)); mockMvc.perform(get("/project/{projectId}/grant-offer-letter/current-state", 123L) .header("IFS_AUTH_TOKEN", "123abc")) .andExpect(status().isOk()) .andExpect(content().json(toJson(stateInformation))) .andDo(document("project/grant-offer-letter/current-state/{method-name}")) .andReturn(); verify(grantOfferLetterService).getGrantOfferLetterState(projectId); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier) { return getProject(projectId). andOnSuccess(project -> fileService.createFile(fileEntryResource, inputStreamSupplier). andOnSuccessReturn(fileDetails -> linkGrantOfferLetterFileToProject(project, fileDetails, true))); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void createSignedGrantOfferLetterFileEntry() { assertCreateFile( project::getSignedGrantOfferLetter, (fileToCreate, inputStreamSupplier) -> service.createSignedGrantOfferLetterFileEntry(123L, fileToCreate, inputStreamSupplier)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier) { return getProject(projectId). andOnSuccess(project -> fileService.createFile(fileEntryResource, inputStreamSupplier). andOnSuccessReturn(fileDetails -> linkGrantOfferLetterFileToProject(project, fileDetails, false))); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void createGrantOfferLetterFileEntry() { assertCreateFile( project::getGrantOfferLetter, (fileToCreate, inputStreamSupplier) -> service.createGrantOfferLetterFileEntry(123L, fileToCreate, inputStreamSupplier)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier) { return getProject(projectId). andOnSuccess(project -> fileService.createFile(fileEntryResource, inputStreamSupplier). andOnSuccessReturn(fileDetails -> linkAdditionalContractFileToProject(project, fileDetails))); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void createAdditionalContractFileEntry() { assertCreateFile( project::getAdditionalContractFile, (fileToCreate, inputStreamSupplier) -> service.createAdditionalContractFileEntry(123L, fileToCreate, inputStreamSupplier)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override public ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId) { return getProject(projectId).andOnSuccess(project -> { FileEntry fileEntry = project.getAdditionalContractFile(); if (fileEntry == null) { return serviceFailure(notFoundError(FileEntry.class)); } return serviceSuccess(fileEntryMapper.mapToResource(fileEntry)); }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void getAdditionalContractFileEntryDetails() { assertGetFileDetails( project::setAdditionalContractFile, () -> service.getAdditionalContractFileEntryDetails(123L)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override public ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId) { return getProject(projectId).andOnSuccess(project -> { FileEntry fileEntry = project.getGrantOfferLetter(); if (fileEntry == null) { return serviceFailure(notFoundError(FileEntry.class)); } return serviceSuccess(fileEntryMapper.mapToResource(fileEntry)); }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void getGrantOfferLetterFileEntryDetails() { assertGetFileDetails( project::setGrantOfferLetter, () -> service.getGrantOfferLetterFileEntryDetails(123L)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override public ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId) { return getProject(projectId).andOnSuccess(project -> { FileEntry fileEntry = project.getSignedGrantOfferLetter(); if (fileEntry == null) { return serviceFailure(notFoundError(FileEntry.class)); } return serviceSuccess(fileEntryMapper.mapToResource(fileEntry)); }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void getSignedGrantOfferLetterFileEntryDetails() { assertGetFileDetails( project::setSignedGrantOfferLetter, () -> service.getSignedGrantOfferLetterFileEntryDetails(123L)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override public ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId) { return getProject(projectId).andOnSuccess(project -> { FileEntry fileEntry = project.getAdditionalContractFile(); return getFileAndContentsResult(fileEntry); }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void getAdditionalContractFileContents() { assertGetFileContents( project::setAdditionalContractFile, () -> service.getAdditionalContractFileAndContents(123L)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override public ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId) { return getProject(projectId).andOnSuccess(project -> { FileEntry fileEntry = project.getGrantOfferLetter(); return getFileAndContentsResult(fileEntry); }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void getGrantOfferLetterFileContents() { assertGetFileContents( project::setGrantOfferLetter, () -> service.getGrantOfferLetterFileAndContents(123L)); }
UserPermissionRules { @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") public boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user) { return hasPermissionToGrantRole(user) && roleCommand.getTargetRole().equals(MONITORING_OFFICER); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void correctRolesCanGrantMonitoringOfficerRole() { GrantRoleCommand grantMonitoringOfficerRole = new GrantRoleCommand(assessorUser().getId(), MONITORING_OFFICER); assertTrue(rules.isGrantingMonitoringOfficerRoleAndHasPermission(grantMonitoringOfficerRole, compAdminUser())); assertTrue(rules.isGrantingMonitoringOfficerRoleAndHasPermission(grantMonitoringOfficerRole, projectFinanceUser())); assertTrue(rules.isGrantingMonitoringOfficerRoleAndHasPermission(grantMonitoringOfficerRole, ifsAdminUser())); assertFalse(rules.isGrantingMonitoringOfficerRoleAndHasPermission(grantMonitoringOfficerRole, assessorUser())); } @Test public void usersAllowedToGrantMonitoringOfficerRoleCannotGrantOtherRoles() { GrantRoleCommand grantInnovationLeadRole = new GrantRoleCommand(assessorUser().getId(), INNOVATION_LEAD); assertFalse(rules.isGrantingMonitoringOfficerRoleAndHasPermission(grantInnovationLeadRole, compAdminUser())); assertFalse(rules.isGrantingMonitoringOfficerRoleAndHasPermission(grantInnovationLeadRole, projectFinanceUser())); assertFalse(rules.isGrantingMonitoringOfficerRoleAndHasPermission(grantInnovationLeadRole, ifsAdminUser())); assertFalse(rules.isGrantingMonitoringOfficerRoleAndHasPermission(grantInnovationLeadRole, assessorUser())); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override public ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId) { return getProject(projectId).andOnSuccess(project -> { FileEntry fileEntry = project.getSignedGrantOfferLetter(); return getFileAndContentsResult(fileEntry); }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void getSignedGrantOfferLetterFileContents() { assertGetFileContents( project::setSignedGrantOfferLetter, () -> service.getSignedGrantOfferLetterFileAndContents(123L)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier) { return getProject(projectId).andOnSuccess(this::validateProjectIsActive). andOnSuccess(project -> { if (golWorkflowHandler.isSent(project)) { return fileService.updateFile(fileEntryResource, inputStreamSupplier). andOnSuccessReturnVoid(fileDetails -> linkGrantOfferLetterFileToProject(project, fileDetails, true)); } else { return serviceFailure(CommonFailureKeys.GRANT_OFFER_LETTER_MUST_BE_SENT_BEFORE_UPLOADING_SIGNED_COPY); } }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void updateSignedGrantOfferLetterFileEntry() { when(golWorkflowHandler.isSent(any())).thenReturn(true); when(projectWorkflowHandler.getState(project)).thenReturn(SETUP); assertUpdateFile( project::getSignedGrantOfferLetter, (fileToUpdate, inputStreamSupplier) -> service.updateSignedGrantOfferLetterFile(123L, fileToUpdate, inputStreamSupplier)); } @Test public void updateSignedGrantOfferLetterFileEntryProjectLive() { FileEntryResource fileToUpdate = newFileEntryResource().build(); Supplier<InputStream> inputStreamSupplier = () -> null; when(projectWorkflowHandler.getState(any())).thenReturn(ProjectState.LIVE); when(golWorkflowHandler.isSent(any())).thenReturn(false); ServiceResult<Void> result = service.updateSignedGrantOfferLetterFile(123L, fileToUpdate, inputStreamSupplier); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_ALREADY_COMPLETE)); } @Test public void updateSignedGrantOfferLetterFileEntryGolNotSent() { FileEntryResource fileToUpdate = newFileEntryResource().build(); Supplier<InputStream> inputStreamSupplier = () -> null; when(projectWorkflowHandler.getState(any())).thenReturn(SETUP); when(golWorkflowHandler.isSent(any())).thenReturn(false); ServiceResult<Void> result = service.updateSignedGrantOfferLetterFile(123L, fileToUpdate, inputStreamSupplier); assertTrue(result.isFailure()); assertEquals(result.getErrors().get(0).getErrorKey(), CommonFailureKeys.GRANT_OFFER_LETTER_MUST_BE_SENT_BEFORE_UPLOADING_SIGNED_COPY.toString()); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<Void> submitGrantOfferLetter(Long projectId) { return getProject(projectId).andOnSuccess(project -> { if (project.getSignedGrantOfferLetter() == null) { return serviceFailure(CommonFailureKeys.SIGNED_GRANT_OFFER_LETTER_MUST_BE_UPLOADED_BEFORE_SUBMIT); } if (!golWorkflowHandler.sign(project)) { return serviceFailure(CommonFailureKeys.GRANT_OFFER_LETTER_CANNOT_SET_SIGNED_STATE); } project.setOfferSubmittedDate(ZonedDateTime.now()); return serviceSuccess(); }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void submitGrantOfferLetterFailureNoSignedGolFile() { ServiceResult<Void> result = service.submitGrantOfferLetter(projectId); assertTrue(result.getFailure().is(CommonFailureKeys.SIGNED_GRANT_OFFER_LETTER_MUST_BE_UPLOADED_BEFORE_SUBMIT)); Assert.assertThat(project.getOfferSubmittedDate(), nullValue()); } @Test public void submitGrantOfferLetterFailureCannotReachSignedState() { project.setSignedGrantOfferLetter(mock(FileEntry.class)); when(golWorkflowHandler.sign(any())).thenReturn(false); ServiceResult<Void> result = service.submitGrantOfferLetter(projectId); assertTrue(result.getFailure().is(CommonFailureKeys.GRANT_OFFER_LETTER_CANNOT_SET_SIGNED_STATE)); Assert.assertThat(project.getOfferSubmittedDate(), nullValue()); } @Test public void submitGrantOfferLetterSuccess() { project.setSignedGrantOfferLetter(mock(FileEntry.class)); when(golWorkflowHandler.sign(any())).thenReturn(true); ServiceResult<Void> result = service.submitGrantOfferLetter(projectId); assertTrue(result.isSuccess()); Assert.assertThat(project.getOfferSubmittedDate(), notNullValue()); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId) { return getProject(projectId). andOnSuccess(project -> validateProjectIsActive(project). andOnSuccess(() -> validateRemoveGrantOfferLetter(project)). andOnSuccess(() -> removeGrantOfferLetterFileFromProject(project)). andOnSuccess(fileEntry -> fileService.deleteFileIgnoreNotFound(fileEntry.getId())). andOnSuccessReturnVoid()); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void removeGrantOfferLetterFileEntry() { UserResource internalUserResource = newUserResource().build(); User internalUser = newUser().withId(internalUserResource.getId()).build(); setLoggedInUser(internalUserResource); FileEntry existingGOLFile = newFileEntry().build(); project.setGrantOfferLetter(existingGOLFile); when(userRepository.findById(internalUserResource.getId())).thenReturn(Optional.of(internalUser)); when(golWorkflowHandler.removeGrantOfferLetter(project, internalUser)).thenReturn(true); when(projectWorkflowHandler.getState(project)).thenReturn(SETUP); when(fileServiceMock.deleteFileIgnoreNotFound(existingGOLFile.getId())).thenReturn(serviceSuccess(existingGOLFile)); ServiceResult<Void> result = service.removeGrantOfferLetterFileEntry(123L); assertTrue(result.isSuccess()); assertNull(project.getGrantOfferLetter()); verify(golWorkflowHandler).removeGrantOfferLetter(project, internalUser); verify(fileServiceMock).deleteFileIgnoreNotFound(existingGOLFile.getId()); } @Test public void removeGrantOfferLetterFileEntryProjectLive() { UserResource internalUserResource = newUserResource().build(); User internalUser = newUser().withId(internalUserResource.getId()).build(); setLoggedInUser(internalUserResource); FileEntry existingGOLFile = newFileEntry().build(); project.setGrantOfferLetter(existingGOLFile); when(userRepository.findById(internalUserResource.getId())).thenReturn(Optional.of(internalUser)); when(golWorkflowHandler.removeGrantOfferLetter(project, internalUser)).thenReturn(true); when(projectWorkflowHandler.getState(project)).thenReturn(ProjectState.LIVE); when(fileServiceMock.deleteFileIgnoreNotFound(existingGOLFile.getId())).thenReturn(serviceSuccess(existingGOLFile)); ServiceResult<Void> result = service.removeGrantOfferLetterFileEntry(123L); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_ALREADY_COMPLETE)); } @Test public void removeGrantOfferLetterFileEntryButWorkflowRejected() { UserResource internalUserResource = newUserResource().build(); User internalUser = newUser().withId(internalUserResource.getId()).build(); setLoggedInUser(internalUserResource); FileEntry existingGOLFile = newFileEntry().build(); project.setGrantOfferLetter(existingGOLFile); when(userRepository.findById(internalUserResource.getId())).thenReturn(Optional.of(internalUser)); when(projectWorkflowHandler.getState(project)).thenReturn(SETUP); when(golWorkflowHandler.removeGrantOfferLetter(project, internalUser)).thenReturn(false); ServiceResult<Void> result = service.removeGrantOfferLetterFileEntry(123L); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(CommonFailureKeys.GRANT_OFFER_LETTER_CANNOT_BE_REMOVED)); assertEquals(existingGOLFile, project.getGrantOfferLetter()); verify(golWorkflowHandler).removeGrantOfferLetter(project, internalUser); verify(fileServiceMock, never()).deleteFile(existingGOLFile.getId()); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId) { return getProject(projectId). andOnSuccess(this::validateProjectIsActive). andOnSuccess(project -> getCurrentlyLoggedInUser(). andOnSuccess(user -> removeSignedGrantOfferLetterIfAllowed(project, user). andOnSuccessReturnVoid())); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void removeSignedGrantOfferLetterFileEntry() { UserResource externalUser = newUserResource().build(); setLoggedInUser(externalUser); FileEntry existingSignedGOLFile = newFileEntry().build(); project.setSignedGrantOfferLetter(existingSignedGOLFile); when(userRepository.findById(externalUser.getId())).thenReturn(Optional.of(user)); when(projectWorkflowHandler.getState(project)).thenReturn(SETUP); when(fileServiceMock.deleteFileIgnoreNotFound(existingSignedGOLFile.getId())).thenReturn(serviceSuccess(existingSignedGOLFile)); when(golWorkflowHandler.removeSignedGrantOfferLetter(project, user)).thenReturn(true); ServiceResult<Void> result = service.removeSignedGrantOfferLetterFileEntry(123L); assertTrue(result.isSuccess()); assertNull(project.getSignedGrantOfferLetter()); verify(golWorkflowHandler).removeSignedGrantOfferLetter(project, user); verify(fileServiceMock).deleteFileIgnoreNotFound(existingSignedGOLFile.getId()); } @Test public void removeSignedGrantOfferLetterFileEntryProjectLive() { UserResource internalUserResource = newUserResource().build(); User internalUser = newUser().withId(internalUserResource.getId()).build(); setLoggedInUser(internalUserResource); FileEntry existingSignedGOLFile = newFileEntry().build(); project.setSignedGrantOfferLetter(existingSignedGOLFile); when(userRepository.findById(internalUserResource.getId())).thenReturn(Optional.of(internalUser)); when(projectWorkflowHandler.getState(project)).thenReturn(ProjectState.LIVE); when(fileServiceMock.deleteFileIgnoreNotFound(existingSignedGOLFile.getId())).thenReturn(serviceSuccess(existingSignedGOLFile)); ServiceResult<Void> result = service.removeSignedGrantOfferLetterFileEntry(123L); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(PROJECT_SETUP_ALREADY_COMPLETE)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<Void> resetGrantOfferLetter(Long projectId) { Project project = getProject(projectId).getSuccess(); if (project.getGrantOfferLetter() != null) { fileService.deleteFileIgnoreNotFound(project.getGrantOfferLetter().getId()); project.setGrantOfferLetter(null); } if (project.getAdditionalContractFile() != null) { fileService.deleteFileIgnoreNotFound(project.getAdditionalContractFile().getId()); project.setAdditionalContractFile(null); } golWorkflowHandler.grantOfferLetterReset(project, getCurrentlyLoggedInUser().getSuccess()); return serviceSuccess(); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void resetGrantOfferLetter() { UserResource externalUser = newUserResource().build(); setLoggedInUser(externalUser); FileEntry existingSignedGOLFile = newFileEntry().build(); project.setSignedGrantOfferLetter(existingSignedGOLFile); when(userRepository.findById(externalUser.getId())).thenReturn(Optional.of(user)); when(fileServiceMock.deleteFileIgnoreNotFound(existingSignedGOLFile.getId())).thenReturn(serviceSuccess(existingSignedGOLFile)); when(golWorkflowHandler.grantOfferLetterReset(project, user)).thenReturn(true); ServiceResult<Void> result = service.resetGrantOfferLetter(123L); assertTrue(result.isSuccess()); assertNull(project.getGrantOfferLetter()); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<Void> sendGrantOfferLetter(Long projectId) { return getProject(projectId).andOnSuccess(project -> { if (project.getGrantOfferLetter() == null) { return serviceFailure(CommonFailureKeys.GRANT_OFFER_LETTER_MUST_BE_AVAILABLE_BEFORE_SEND); } User projectManager = getExistingProjectManager(project).get().getUser(); if (project.isUseDocusignForGrantOfferLetter()) { return sendGrantOfferLetterSuccess(project).andOnSuccess(() -> docusignService.send(docusignRequest(projectManager, project)) .andOnSuccessReturnVoid((project::setSignedGolDocusignDocument))); } else { NotificationTarget pmTarget = createProjectManagerNotificationTarget(projectManager); Map<String, Object> notificationArguments = new HashMap<>(); notificationArguments.put("dashboardUrl", webBaseUrl); notificationArguments.put("applicationId", project.getApplication().getId()); String title = project.getApplication().getCompetition().isProcurement() ? "contract" : "grant offer letter"; String shortTitle = project.getApplication().getCompetition().isProcurement() ? "contract" : "letter"; notificationArguments.put("title", title); notificationArguments.put("shortTitle", shortTitle); return sendGrantOfferLetterSuccess(project).andOnSuccess(() -> { Notification notification = new Notification(systemNotificationSource, singletonList(pmTarget), NotificationsGol.GRANT_OFFER_LETTER_PROJECT_MANAGER, notificationArguments); return notificationService.sendNotificationWithFlush(notification, EMAIL); }); } }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void sendGrantOfferLetterNoGol() { List<ProjectUser> pu = newProjectUser().withRole(PROJECT_MANAGER).withUser(user).withOrganisation(nonAcademicUnfunded).withInvite(newProjectUserInvite().build()).build(1); Project p = newProject() .withProjectUsers(pu) .withPartnerOrganisations(newPartnerOrganisation() .withOrganisation(nonAcademicUnfunded) .build(1)) .withGrantOfferLetter(null) .build(); when(projectRepository.findById(projectId)).thenReturn(Optional.of(p)); when(notificationService.sendNotification(any(), eq(EMAIL))).thenReturn(serviceSuccess()); ServiceResult<Void> result = service.sendGrantOfferLetter(projectId); assertTrue(result.isFailure()); } @Test public void sendGrantOfferLetterSendFails() { List<ProjectUser> pu = newProjectUser() .withRole(PROJECT_MANAGER) .withUser(user) .withOrganisation(nonAcademicUnfunded) .withInvite(newProjectUserInvite() .build()) .build(1); Competition competition = newCompetition() .withName("Competition 1") .withFundingType(FundingType.GRANT) .build(); Application application = newApplication() .withName("Application 1") .withCompetition(competition) .build(); FileEntry golFile = newFileEntry() .withMediaType("application/pdf") .withFilesizeBytes(10) .build(); Project project = newProject() .withProjectUsers(pu) .withPartnerOrganisations(newPartnerOrganisation() .withOrganisation(nonAcademicUnfunded) .build(1)).withGrantOfferLetter(golFile) .withApplication(application) .build(); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); User projectManagerUser = pu.get(0).getUser(); NotificationTarget to = new UserNotificationTarget(projectManagerUser.getName(), projectManagerUser.getEmail()); Map<String, Object> expectedNotificationArguments = asMap( "dashboardUrl", "https: "applicationId", application.getId(), "title", "grant offer letter", "shortTitle", "letter" ); Notification notification = new Notification(systemNotificationSource, to, GRANT_OFFER_LETTER_PROJECT_MANAGER, expectedNotificationArguments); when(notificationService.sendNotificationWithFlush(notification, EMAIL)).thenReturn(serviceFailure(NOTIFICATIONS_UNABLE_TO_SEND_MULTIPLE)); User user = newUser().build(); setLoggedInUser(newUserResource().withId(user.getId()).build()); when(userRepository.findById(user.getId())).thenReturn(Optional.of(user)); when(golWorkflowHandler.grantOfferLetterSent(project, user)).thenReturn(true); ServiceResult<Void> result = service.sendGrantOfferLetter(projectId); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(NOTIFICATIONS_UNABLE_TO_SEND_MULTIPLE)); } @Test public void sendGrantOfferLetterNoProject() { when(projectRepository.findById(projectId)).thenReturn(Optional.empty()); ServiceResult<Void> result = service.sendGrantOfferLetter(projectId); assertTrue(result.isFailure()); } @Test public void sendGrantOfferLetterSuccessDocusign() { FileEntry golFile = newFileEntry().withFilesizeBytes(10).withMediaType("application/pdf").build(); List<ProjectUser> pu = newProjectUser().withRole(PROJECT_MANAGER).withUser(user).withOrganisation(nonAcademicUnfunded).withInvite(newProjectUserInvite().build()).build(1); Competition competition = newCompetition() .withName("Competition 1") .build(); Application application = newApplication() .withName("Application 1") .withCompetition(competition) .build(); Project p = newProject() .withProjectUsers(pu) .withPartnerOrganisations(newPartnerOrganisation() .withOrganisation(nonAcademicUnfunded) .build(1)) .withGrantOfferLetter(golFile) .withApplication(application) .withUseDocusignForGrantOfferLetter(true) .build(); when(projectRepository.findById(p.getId())).thenReturn(Optional.of(p)); User projectManagerUser = pu.get(0).getUser(); DocusignDocument document = new DocusignDocument(projectManagerUser.getId(), DocusignType.SIGNED_GRANT_OFFER_LETTER); when(golWorkflowHandler.grantOfferLetterSent(p, user)).thenReturn(true); when(docusignService.send(any())).thenReturn(serviceSuccess(document)); User user = UserBuilder.newUser().build(); setLoggedInUser(newUserResource().withId(user.getId()).build()); when(userRepository.findById(user.getId())).thenReturn(Optional.of(user)); when(golWorkflowHandler.grantOfferLetterSent(p, user)).thenReturn(true); final Supplier<InputStream> contentSupplier = () -> null; FileEntryResource fileEntryResource = new FileEntryResource(); when(fileServiceMock.getFileByFileEntryId(golFile.getId())).thenReturn(ServiceResult.serviceSuccess(contentSupplier)); when(fileEntryMapperMock.mapToResource(golFile)).thenReturn(fileEntryResource); ServiceResult<Void> result = service.sendGrantOfferLetter(p.getId()); assertTrue(result.isSuccess()); verify(golWorkflowHandler).grantOfferLetterSent(p, user); verify(docusignService).send(any()); } @Test public void sendGrantOfferLetterFailure() { FileEntry golFile = newFileEntry().withFilesizeBytes(10).withMediaType("application/pdf").build(); List<ProjectUser> pu = newProjectUser().withRole(PROJECT_MANAGER).withUser(user).withOrganisation(nonAcademicUnfunded).withInvite(newProjectUserInvite().build()).build(1); Competition competition = newCompetition() .withName("Competition 1") .build(); Application application = newApplication() .withName("Application 1") .withCompetition(competition) .build(); Project project = newProject() .withProjectUsers(pu) .withPartnerOrganisations(newPartnerOrganisation() .withOrganisation(nonAcademicUnfunded) .build(1)).withGrantOfferLetter(golFile) .withApplication(application) .build(); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); User user = UserBuilder.newUser().build(); setLoggedInUser(newUserResource().withId(user.getId()).build()); when(userRepository.findById(user.getId())).thenReturn(Optional.of(user)); when(golWorkflowHandler.grantOfferLetterSent(project, user)).thenReturn(false); ServiceResult<Void> result = service.sendGrantOfferLetter(projectId); assertTrue(result.isFailure()); verify(golWorkflowHandler).grantOfferLetterSent(project, user); verify(notificationService, never()).sendNotificationWithFlush(any(Notification.class), eq(EMAIL)); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { private ServiceResult<Void> sendGrantOfferLetterSuccess(Project project) { return getCurrentlyLoggedInUser().andOnSuccess(user -> { if (golWorkflowHandler.grantOfferLetterSent(project, user)) { return serviceSuccess(); } else { LOG.error(String.format(GOL_STATE_ERROR, project.getId())); return serviceFailure(CommonFailureKeys.GENERAL_UNEXPECTED_ERROR); } }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void sendGrantOfferLetterSuccess() { FileEntry golFile = newFileEntry().withFilesizeBytes(10).withMediaType("application/pdf").build(); List<ProjectUser> pu = newProjectUser().withRole(PROJECT_MANAGER).withUser(user).withOrganisation(nonAcademicUnfunded).withInvite(newProjectUserInvite().build()).build(1); Competition competition = newCompetition() .withName("Competition 1") .withFundingType(FundingType.GRANT) .build(); Application application = newApplication() .withName("Application 1") .withCompetition(competition) .build(); Project p = newProject() .withProjectUsers(pu) .withPartnerOrganisations(newPartnerOrganisation() .withOrganisation(nonAcademicUnfunded) .build(1)) .withGrantOfferLetter(golFile) .withApplication(application) .build(); when(projectRepository.findById(projectId)).thenReturn(Optional.of(p)); User projectManagerUser = pu.get(0).getUser(); NotificationTarget to = new UserNotificationTarget(projectManagerUser.getName(), projectManagerUser.getEmail()); Map<String, Object> expectedNotificationArguments = asMap( "dashboardUrl", "https: "applicationId", application.getId(), "title", "grant offer letter", "shortTitle", "letter" ); Notification notification = new Notification(systemNotificationSource, to, GRANT_OFFER_LETTER_PROJECT_MANAGER, expectedNotificationArguments); when(notificationService.sendNotificationWithFlush(notification, EMAIL)).thenReturn(serviceSuccess()); User user = UserBuilder.newUser().build(); setLoggedInUser(newUserResource().withId(user.getId()).build()); when(userRepository.findById(user.getId())).thenReturn(Optional.of(user)); when(golWorkflowHandler.grantOfferLetterSent(p, user)).thenReturn(true); ServiceResult<Void> result = service.sendGrantOfferLetter(projectId); assertTrue(result.isSuccess()); verify(golWorkflowHandler).grantOfferLetterSent(p, user); verify(notificationService).sendNotificationWithFlush(notification, EMAIL); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource) { return validateApprovalOrRejection(grantOfferLetterApprovalResource).andOnSuccess(() -> getProject(projectId).andOnSuccess(project -> { if (golWorkflowHandler.isReadyToApprove(project)) { if (ApprovalType.APPROVED.equals(grantOfferLetterApprovalResource.getApprovalType()) && !isOnHold(project)) { return approveGOL(project) .andOnSuccess(() -> moveProjectToLiveState(project)); } else if (ApprovalType.REJECTED.equals(grantOfferLetterApprovalResource.getApprovalType())) { return rejectGOL(project, grantOfferLetterApprovalResource.getRejectionReason()); } } return serviceFailure(CommonFailureKeys.GRANT_OFFER_LETTER_NOT_READY_TO_APPROVE); })); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void approveOrRejectSignedGrantOfferLetterRejectionSuccess() { User u = newUser().withFirstName("A").withLastName("B").withEmailAddress("[email protected]").build(); setLoggedInUser(newUserResource().withId(u.getId()).build()); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); when(golWorkflowHandler.isReadyToApprove(project)).thenReturn(true); when(userRepository.findById(u.getId())).thenReturn(Optional.of(u)); when(golWorkflowHandler.grantOfferLetterRejected(project, u)).thenReturn(true); String rejectionReason = "No signature"; GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.REJECTED, rejectionReason); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); verify(projectRepository).findById(projectId); verify(golWorkflowHandler).isReadyToApprove(project); verify(golWorkflowHandler).grantOfferLetterRejected(project, u); verify(golWorkflowHandler, never()).grantOfferLetterApproved(project, u); verify(projectWorkflowHandler, never()).grantOfferLetterApproved(any(), any()); verify(notificationService, never()).sendNotificationWithFlush(any(Notification.class), eq(EMAIL)); assertNull(project.getOfferSubmittedDate()); assertEquals(project.getGrantOfferLetterRejectionReason(), rejectionReason); assertTrue(result.isSuccess()); } @Test public void approveOrRejectSignedGrantOfferLetterWhenGOLRejectionFailure() { User u = newUser().withFirstName("A").withLastName("B").withEmailAddress("[email protected]").build(); setLoggedInUser(newUserResource().withId(u.getId()).build()); NotificationTarget to = new UserNotificationTarget("A B", "[email protected]"); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); when(golWorkflowHandler.isReadyToApprove(project)).thenReturn(true); when(userRepository.findById(u.getId())).thenReturn(Optional.of(u)); when(golWorkflowHandler.grantOfferLetterRejected(project, u)).thenReturn(false); GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.REJECTED, "No signature"); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); verify(projectRepository).findById(projectId); verify(golWorkflowHandler).isReadyToApprove(project); verify(golWorkflowHandler).grantOfferLetterRejected(project, u); verify(golWorkflowHandler, never()).grantOfferLetterApproved(project, u); verify(projectWorkflowHandler, never()).grantOfferLetterApproved(any(), any()); verify(notificationService, never()).sendNotificationWithFlush(any(Notification.class), eq(EMAIL)); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(CommonFailureKeys.GENERAL_UNEXPECTED_ERROR)); } @Test public void approveOrRejectSignedGrantOfferLetterApprovalSuccess() { User user = newUser() .withFirstName("A") .withLastName("B") .withEmailAddress("[email protected]") .build(); setLoggedInUser(newUserResource() .withId(user.getId()) .build()); Organisation organisation1 = newOrganisation().build(); Organisation organisation2 = newOrganisation().build(); ProjectUser projectManager = newProjectUser() .withRole(PROJECT_MANAGER) .withUser(user) .withOrganisation(organisation1) .build(); ProjectUser financeContactOrg1 = newProjectUser() .withRole(PROJECT_FINANCE_CONTACT) .withUser(newUser().build()) .withOrganisation(organisation1) .build(); ProjectUser financeContactOrg2 = newProjectUser() .withRole(PROJECT_FINANCE_CONTACT) .withUser(newUser().build()) .withOrganisation(organisation2) .build(); List<ProjectUser> projectUsers = asList(projectManager, financeContactOrg1, financeContactOrg2); Competition competition = newCompetition() .withName("Competition 1") .withFundingType(FundingType.GRANT) .build(); Application application = newApplication() .withName("Application 1") .withCompetition(competition) .build(); Project project = newProject() .withId(projectId) .withProjectUsers(projectUsers) .withPartnerOrganisations(newPartnerOrganisation() .withOrganisation(organisation1, organisation2) .build(2) ) .withApplication(application) .withProjectProcess(newProjectProcess() .withActivityState(SETUP) .build()) .withTargetStartDate(LocalDate.now()) .build(); List<NotificationTarget> to = asList( new UserNotificationTarget(projectManager.getUser().getName(), projectManager.getUser().getEmail()), new UserNotificationTarget(financeContactOrg1.getUser().getName(), financeContactOrg1.getUser().getEmail()), new UserNotificationTarget(financeContactOrg2.getUser().getName(), financeContactOrg2.getUser().getEmail()) ); Map<String, Object> expectedNotificationArguments = asMap( "applicationId", project.getApplication().getId(), "projectName", project.getName(), "projectStartDate", LocalDate.now().format(DateTimeFormatter.ofPattern("d MMMM yyyy")), "projectSetupUrl", webBaseUrl + "/project-setup/project/" + project.getId(), "title", "grant offer letter", "titleUpper", "Grant offer letter" ); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); when(golWorkflowHandler.isReadyToApprove(project)).thenReturn(true); when(userRepository.findById(user.getId())).thenReturn(Optional.of(user)); when(golWorkflowHandler.grantOfferLetterApproved(project, user)).thenReturn(true); when(projectWorkflowHandler.grantOfferLetterApproved(project, project.getProjectUsersWithRole(PROJECT_MANAGER).get(0))).thenReturn(true); Notification notification = new Notification(systemNotificationSource, to, PROJECT_LIVE, expectedNotificationArguments); when(notificationService.sendNotificationWithFlush(notification, EMAIL)).thenReturn(serviceSuccess()); GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.APPROVED, null); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); assertTrue(result.isSuccess()); verify(projectRepository, atLeast(2)).findById(projectId); verify(golWorkflowHandler).isReadyToApprove(project); verify(golWorkflowHandler).grantOfferLetterApproved(project, user); verify(projectWorkflowHandler).grantOfferLetterApproved(project, project.getProjectUsersWithRole(PROJECT_MANAGER).get(0)); verify(notificationService).sendNotificationWithFlush(notification, EMAIL); } @Test public void approveOrRejectSignedGrantOfferLetterEnsureDuplicateEmailsAreNotSent() { User user = newUser() .withFirstName("A") .withLastName("B") .withEmailAddress("[email protected]") .build(); setLoggedInUser(newUserResource() .withId(user.getId()) .build()); List<ProjectUser> projectUsers = newProjectUser() .withRole(PROJECT_MANAGER, PROJECT_FINANCE_CONTACT) .withUser(user).withOrganisation(nonAcademicUnfunded) .withInvite(newProjectUserInvite() .build()) .build(2); Competition competition = newCompetition() .withName("Competition 1") .withFundingType(FundingType.GRANT) .build(); Application application = newApplication() .withName("Application 1") .withCompetition(competition) .build(); Project project = newProject() .withId(projectId) .withProjectUsers(projectUsers) .withPartnerOrganisations(newPartnerOrganisation() .withOrganisation(nonAcademicUnfunded) .build(1)) .withApplication(application) .withProjectProcess(newProjectProcess() .withActivityState(SETUP) .build()) .withTargetStartDate(LocalDate.now()) .build(); NotificationTarget to = new UserNotificationTarget("A B", "[email protected]"); Map<String, Object> expectedNotificationArguments = asMap( "applicationId", project.getApplication().getId(), "projectName", project.getName(), "projectStartDate", LocalDate.now().format(DateTimeFormatter.ofPattern("d MMMM yyyy")), "projectSetupUrl", webBaseUrl + "/project-setup/project/" + project.getId(), "title", "grant offer letter", "titleUpper", "Grant offer letter" ); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); when(golWorkflowHandler.isReadyToApprove(project)).thenReturn(true); when(userRepository.findById(user.getId())).thenReturn(Optional.of(user)); when(golWorkflowHandler.grantOfferLetterApproved(project, user)).thenReturn(true); when(projectWorkflowHandler.grantOfferLetterApproved(project, project.getProjectUsersWithRole(PROJECT_MANAGER).get(0))). thenReturn(true); Notification notification = new Notification(systemNotificationSource, to, PROJECT_LIVE, expectedNotificationArguments); when(notificationService.sendNotificationWithFlush(notification, EMAIL)).thenReturn(serviceSuccess()); GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.APPROVED, null); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); assertTrue(result.isSuccess()); verify(projectRepository, atLeast(2)).findById(projectId); verify(golWorkflowHandler).isReadyToApprove(project); verify(golWorkflowHandler).grantOfferLetterApproved(project, user); verify(projectWorkflowHandler).grantOfferLetterApproved(project, project.getProjectUsersWithRole(PROJECT_MANAGER).get(0)); verify(notificationService).sendNotificationWithFlush(notification, EMAIL); } @Test public void approveOrRejectSignedGrantOfferLetterWhenProjectGOLApprovalFailure() { User u = newUser().withFirstName("A").withLastName("B").withEmailAddress("[email protected]").build(); setLoggedInUser(newUserResource().withId(u.getId()).build()); List<ProjectUser> pu = newProjectUser().withRole(PROJECT_MANAGER).withUser(u).withOrganisation(nonAcademicUnfunded).withInvite(newProjectUserInvite().build()).build(1); Project project = newProject() .withId(projectId) .withProjectUsers(pu) .withPartnerOrganisations(newPartnerOrganisation().withOrganisation(nonAcademicUnfunded).build(1)) .withProjectProcess(newProjectProcess() .withActivityState(SETUP) .build()) .build(); FileEntry golFile = newFileEntry().withFilesizeBytes(10).withMediaType("application/pdf").build(); project.setGrantOfferLetter(golFile); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); when(golWorkflowHandler.isReadyToApprove(project)).thenReturn(true); when(userRepository.findById(u.getId())).thenReturn(Optional.of(u)); when(golWorkflowHandler.grantOfferLetterApproved(project, u)).thenReturn(true); when(projectWorkflowHandler.grantOfferLetterApproved(project, project.getProjectUsersWithRole(PROJECT_MANAGER).get(0))).thenReturn(false); GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.APPROVED, null); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); verify(projectRepository).findById(projectId); verify(golWorkflowHandler).isReadyToApprove(project); verify(golWorkflowHandler).grantOfferLetterApproved(project, u); verify(projectWorkflowHandler).grantOfferLetterApproved(project, project.getProjectUsersWithRole(PROJECT_MANAGER).get(0)); verify(notificationService, never()).sendNotificationWithFlush(any(Notification.class), eq(EMAIL)); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(CommonFailureKeys.GENERAL_UNEXPECTED_ERROR)); } @Test public void approveOrRejectSignedGrantOfferLetterWhenGOLApprovalFailure() { User u = newUser().withFirstName("A").withLastName("B").withEmailAddress("[email protected]").build(); setLoggedInUser(newUserResource().withId(u.getId()).build()); FileEntry golFile = newFileEntry().withFilesizeBytes(10).withMediaType("application/pdf").build(); project.setGrantOfferLetter(golFile); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); when(golWorkflowHandler.isReadyToApprove(project)).thenReturn(true); when(userRepository.findById(u.getId())).thenReturn(Optional.of(u)); when(golWorkflowHandler.grantOfferLetterApproved(project, u)).thenReturn(false); GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.APPROVED, null); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); verify(projectRepository).findById(projectId); verify(golWorkflowHandler).isReadyToApprove(project); verify(golWorkflowHandler).grantOfferLetterApproved(project, u); verify(projectWorkflowHandler, never()).grantOfferLetterApproved(any(), any()); verify(notificationService, never()).sendNotificationWithFlush(any(Notification.class), eq(EMAIL)); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(CommonFailureKeys.GENERAL_UNEXPECTED_ERROR)); } @Test public void approveOrRejectSignedGrantOfferLetterWhenGOLNotReadyToApprove() { FileEntry golFile = newFileEntry().withFilesizeBytes(10).withMediaType("application/pdf").build(); project.setGrantOfferLetter(golFile); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); when(golWorkflowHandler.isReadyToApprove(project)).thenReturn(false); GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.APPROVED, null); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); verify(projectRepository).findById(projectId); verify(golWorkflowHandler).isReadyToApprove(project); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(CommonFailureKeys.GRANT_OFFER_LETTER_NOT_READY_TO_APPROVE)); } @Test public void approveOrRejectSignedGrantOfferLetterWhenGOLRejectedButRejectionReasonIsAllWhitespaces() { GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.REJECTED, " "); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(CommonFailureKeys.GENERAL_INVALID_ARGUMENT)); } @Test public void approveOrRejectSignedGrantOfferLetterWhenGOLRejectedButRejectionReasonIsEmpty() { GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.REJECTED, ""); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(CommonFailureKeys.GENERAL_INVALID_ARGUMENT)); } @Test public void approveOrRejectSignedGrantOfferLetterWhenGOLRejectedButNoRejectionReason() { GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.REJECTED, null); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(CommonFailureKeys.GENERAL_INVALID_ARGUMENT)); } @Test public void aproveOrRejectSignedGrantOfferLetterWhenGOLNeitherApprovedNorRejected() { GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(null, null); ServiceResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(CommonFailureKeys.GENERAL_INVALID_ARGUMENT)); }
UserPermissionRules { @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") public boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user) { return usersToView.getContent().stream().allMatch(u -> u.hasAnyRoles(ASSESSOR_ROLES)) && user.hasAnyRoles(COMP_ADMIN, PROJECT_FINANCE); } @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "An internal user can invite a monitoring officer and create the pending user associated.") boolean compAdminProjectFinanceCanCreateMonitoringOfficer(UserCreationResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "CREATE", description = "A System Registration User can create new Users on behalf of non-logged in users") boolean systemRegistrationUserCanCreateUsers(UserRegistrationResource userToCreate, UserResource user); @PermissionRule(value = "VERIFY", description = "A System Registration User can send a new User a verification link by e-mail") boolean systemRegistrationUserCanSendUserVerificationEmail(UserResource userToSendVerificationEmail, UserResource user); @PermissionRule(value = "READ", description = "Any user can view themselves") boolean anyUserCanViewThemselves(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Internal users can view everyone") boolean internalUsersCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can view users in competitions they are assigned to") boolean stakeholdersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can view users in competitions they are assigned to") boolean competitionFinanceUsersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can view users in projects they are assigned to") boolean monitoringOfficersCanViewUsersInCompetitionsTheyAreAssignedTo(UserResource userToView, UserResource user); @PermissionRule(value = "READ_USER_ORGANISATION", description = "Internal support users can view all users and associated organisations") boolean internalUsersCanViewUserOrganisation(UserOrganisationResource userToView, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "IFS admins can update all users email addresses") boolean ifsAdminCanUpdateAllEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "Support users can update external users email addresses ") boolean supportCanUpdateExternalUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE_USER_EMAIL", description = "System Maintenance update all users email addresses") boolean systemMaintenanceUserCanUpdateUsersEmailAddresses(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ_INTERNAL", description = "Administrators can view internal users") boolean internalUsersCanViewEveryone(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Support users and administrators can view external users") boolean supportUsersCanViewExternalUsers(ManageUserPageResource userToView, UserResource user); @PermissionRule(value = "READ", description = "The System Registration user can view everyone") boolean systemRegistrationUserCanViewEveryone(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Comp admins and project finance can view assessors") boolean compAdminAndProjectFinanceCanViewAssessors(UserPageResource usersToView, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewOtherConsortiumMembers(UserResource userToView, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewConsortiumUsersOnApplicationsTheyAreAssessing(UserResource userToView, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "A User should be able to change their own password") boolean usersCanChangeTheirOwnPassword(UserResource userToUpdate, UserResource user); @PermissionRule(value = "CHANGE_PASSWORD", description = "The System Registration user should be able to change passwords on behalf of other Users") boolean systemRegistrationUserCanChangePasswordsForUsers(UserResource userToUpdate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A System Registration User can activate Users") boolean systemRegistrationUserCanActivateUsers(UserResource userToCreate, UserResource user); @PermissionRule(value = "UPDATE", description = "A User can update their own profile") boolean usersCanUpdateTheirOwnProfiles(UserResource userToUpdate, UserResource user); @PermissionRule(value = "UPDATE", description = "An admin user can update user details to assign monitoring officers") boolean adminsCanUpdateUserDetails(UserResource userToUpdate, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile skills") boolean usersCanViewTheirOwnProfileSkills(ProfileSkillsResource profileSkills, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own profile agreement") boolean usersCanViewTheirOwnProfileAgreement(ProfileAgreementResource profileAgreementResource, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own affiliations") boolean usersCanViewTheirOwnAffiliations(AffiliationResource affiliation, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A user can read their own profile") boolean usersCanViewTheirOwnProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ_USER_PROFILE", description = "A ifs admin user can read any user's profile") boolean ifsAdminCanViewAnyUsersProfile(UserProfileResource profileDetails, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as Comp Admin and Exec can read the user's profile status") boolean usersAndCompAdminCanViewProfileStatus(UserProfileStatusResource profileStatus, UserResource user); @PermissionRule(value = "READ", description = "A user can read their own role") boolean usersCanViewTheirOwnProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Consortium members (Lead Applicants and Collaborators) can view the process role of others in their Consortium Teams on their various Applications") boolean consortiumMembersCanViewTheProcessRolesOfOtherConsortiumMembers(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Project managers and partners can view the process role for the same organisation") boolean projectPartnersCanViewTheProcessRolesWithinSameApplication(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "The user, as well as internal users can read the user's process role") boolean usersAndInternalUsersCanViewProcessRole(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "READ", description = "Assessors can view the process roles of members of individual Consortiums on the various Applications that they are assessing") boolean assessorsCanViewTheProcessRolesOfConsortiumUsersOnApplicationsTheyAreAssessing(ProcessRoleResource processRole, UserResource user); @PermissionRule(value = "CHECK_USER_APPLICATION", description = "The user can check if they have an application for the competition") boolean userCanCheckTheyHaveApplicationForCompetition(UserResource userToCheck, UserResource user); @PermissionRule(value = "EDIT_INTERNAL_USER", description = "Only an IFS Administrator can edit an internal user") boolean ifsAdminCanEditInternalUser(final UserResource userToEdit, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "IFS Administrator can deactivate Users") boolean ifsAdminCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "A Support user can deactivate external Users") boolean supportUserCanDeactivateExternalUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "DEACTIVATE", description = "System Maintenance can deactivate Users") boolean systemMaintenanceUserCanDeactivateUsers(UserResource userToDeactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "IFS Administrator can reactivate Users") boolean ifsAdminCanReactivateUsers(UserResource userToReactivate, UserResource user); @PermissionRule(value = "ACTIVATE", description = "A Support user can reactivate external Users") boolean supportUserCanReactivateExternalUsers(UserResource userToActivate, UserResource user); @PermissionRule(value = "AGREE_TERMS", description = "A user can accept the site terms and conditions") boolean usersCanAgreeSiteTermsAndConditions(UserResource userToUpdate, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An assessor can request applicant role") boolean assessorCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant monitoring officer role") boolean isGrantingMonitoringOfficerRoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An admin user can grant a KTA role") boolean isGrantingKTARoleAndHasPermission(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An stakeholder can request applicant role") boolean stakeholderCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "GRANT_ROLE", description = "An monitoring officer can request applicant role") boolean monitoringOfficerCanRequestApplicantRole(GrantRoleCommand roleCommand, UserResource user); @PermissionRule(value = "CAN_VIEW_OWN_DASHBOARD", description = "User is requesting own dashboard") boolean isViewingOwnDashboard(UserResource userToView, UserResource user); }
@Test public void compAdminAndProjectFinanceCanViewAssessors() { UserPageResource userPageResourceWithOnlyAssessors = new UserPageResource(); userPageResourceWithOnlyAssessors.setContent(newUserResource().withRoleGlobal(ASSESSOR).build(1)); UserPageResource userPageResourceWithNonAssessors = new UserPageResource(); userPageResourceWithNonAssessors.setContent(newUserResource().withRolesGlobal(singletonList(ASSESSOR), singletonList(APPLICANT)).build(2)); allGlobalRoleUsers.forEach(u -> { if (u.hasAnyRoles(COMP_ADMIN, PROJECT_FINANCE)) { assertTrue(rules.compAdminAndProjectFinanceCanViewAssessors(userPageResourceWithOnlyAssessors, u)); assertFalse(rules.compAdminAndProjectFinanceCanViewAssessors(userPageResourceWithNonAssessors, u)); } else { assertFalse(rules.compAdminAndProjectFinanceCanViewAssessors(userPageResourceWithOnlyAssessors, u)); assertFalse(rules.compAdminAndProjectFinanceCanViewAssessors(userPageResourceWithNonAssessors, u)); } } ); }
RoleProfileStatusPermissionRoles { @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "Comp admin, project finance or support can retrieve a users status") public boolean adminsAndSupportCanRetrieveUserRoleProfile(UserResource userToCheck, UserResource user) { return isInternalAdmin(user) || isSupport(user); } @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "Comp admin, project finance or support can retrieve a users status") boolean adminsAndSupportCanRetrieveUserRoleProfile(UserResource userToCheck, UserResource user); @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "Assessors can retrieve their own status") boolean usersCanRetrieveTheirOwnUserRoleProfile(UserResource userToCheck, UserResource user); @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "kta can retrieve a users status") boolean ktaCanRetrieveUserRoleProfile(UserResource userToCheck, UserResource user); }
@Test public void internalUsersCanRetrieveRoleProfiles() { UserResource otherUser = newUserResource().build(); allGlobalRoleUsers.forEach(user -> { if (isInternalAdmin(user) || isSupport(user)) { assertTrue(rules.adminsAndSupportCanRetrieveUserRoleProfile(otherUser, user)); } else { assertFalse(rules.adminsAndSupportCanRetrieveUserRoleProfile(otherUser, user)); } }); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override public ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId) { return getProject(projectId).andOnSuccess( golWorkflowHandler::getExtendedState); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void getGrantOfferLetterStateWhenProjectDoesNotExist() { when(projectRepository.findById(projectId)).thenReturn(Optional.empty()); ServiceResult<GrantOfferLetterStateResource> result = service.getGrantOfferLetterState(projectId); assertTrue(result.isFailure()); assertTrue(result.getFailure().is(notFoundError(Project.class, projectId))); } @Test public void getGrantOfferLetterState() { GrantOfferLetterStateResource state = GrantOfferLetterStateResource.stateInformationForPartnersView(SENT, GrantOfferLetterEvent.GOL_SENT); when(golWorkflowHandler.getExtendedState(project)).thenReturn(serviceSuccess(state)); ServiceResult<GrantOfferLetterStateResource> retrievedState = service.getGrantOfferLetterState(project.getId()); assertSame(state, retrievedState.getSuccess()); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override public ServiceResult<StringResource> getDocusignUrl(long projectId) { return getProject(projectId).andOnSuccessReturn(project -> { User projectManager = getExistingProjectManager(project).get().getUser(); return new StringResource(docusignService.getDocusignUrl(project.getSignedGolDocusignDocument().getEnvelopeId(), projectManager.getId(), projectManager.getName(), projectManager.getEmail(), String.format("/project-setup/project/%d/offer", projectId))); }); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void getDocusignUrl() { List<ProjectUser> pu = newProjectUser().withRole(PROJECT_MANAGER).withUser(user).withOrganisation(nonAcademicUnfunded).withInvite(newProjectUserInvite().build()).build(1); Competition competition = newCompetition() .withName("Competition 1") .build(); Application application = newApplication() .withName("Application 1") .withCompetition(competition) .build(); Project p = newProject() .withProjectUsers(pu) .withPartnerOrganisations(newPartnerOrganisation() .withOrganisation(nonAcademicUnfunded) .build(1)) .withApplication(application) .withUseDocusignForGrantOfferLetter(true) .build(); when(projectRepository.findById(p.getId())).thenReturn(Optional.of(p)); DocusignDocument docusignDocument = new DocusignDocument(user.getId(), DocusignType.SIGNED_GRANT_OFFER_LETTER); docusignDocument.setEnvelopeId("Envelope"); p.setSignedGolDocusignDocument(docusignDocument); when(docusignService.getDocusignUrl("Envelope", user.getId(), user.getName(), user.getEmail(), String.format("/project-setup/project/%d/offer", p.getId()))) .thenReturn("redirectToDocusign"); ServiceResult<StringResource> result = service.getDocusignUrl(p.getId()); assertTrue(result.isSuccess()); assertEquals(result.getSuccess().getContent(), "redirectToDocusign"); }
GrantOfferLetterServiceImpl extends BaseTransactionalService implements GrantOfferLetterService { @Override @Transactional public ServiceResult<Void> importGrantOfferLetter(long projectId) { return getProject(projectId).andOnSuccess(project -> docusignService.importDocument(project.getSignedGolDocusignDocument().getEnvelopeId())); } @Override ServiceResult<FileAndContents> getSignedGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getGrantOfferLetterFileAndContents(Long projectId); @Override ServiceResult<FileAndContents> getAdditionalContractFileAndContents(Long projectId); @Override ServiceResult<FileEntryResource> getSignedGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getGrantOfferLetterFileEntryDetails(Long projectId); @Override ServiceResult<FileEntryResource> getAdditionalContractFileEntryDetails(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createSignedGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<FileEntryResource> createGrantOfferLetterFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> removeGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeAdditionalContractFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> removeSignedGrantOfferLetterFileEntry(Long projectId); @Override @Transactional ServiceResult<Void> resetGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<FileEntryResource> createAdditionalContractFileEntry(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> updateSignedGrantOfferLetterFile(Long projectId, FileEntryResource fileEntryResource, Supplier<InputStream> inputStreamSupplier); @Override @Transactional ServiceResult<Void> submitGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> sendGrantOfferLetter(Long projectId); @Override @Transactional ServiceResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override ServiceResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override ServiceResult<StringResource> getDocusignUrl(long projectId); @Override @Transactional ServiceResult<Void> importGrantOfferLetter(long projectId); }
@Test public void importGrantOfferLetter() { List<ProjectUser> pu = newProjectUser().withRole(PROJECT_MANAGER).withUser(user).withOrganisation(nonAcademicUnfunded).withInvite(newProjectUserInvite().build()).build(1); Competition competition = newCompetition() .withName("Competition 1") .build(); Application application = newApplication() .withName("Application 1") .withCompetition(competition) .build(); Project p = newProject() .withProjectUsers(pu) .withPartnerOrganisations(newPartnerOrganisation() .withOrganisation(nonAcademicUnfunded) .build(1)) .withApplication(application) .withUseDocusignForGrantOfferLetter(true) .build(); when(projectRepository.findById(p.getId())).thenReturn(Optional.of(p)); DocusignDocument docusignDocument = new DocusignDocument(user.getId(), DocusignType.SIGNED_GRANT_OFFER_LETTER); docusignDocument.setEnvelopeId("Envelope"); p.setSignedGolDocusignDocument(docusignDocument); when(docusignService.importDocument("Envelope")).thenReturn(serviceSuccess()); service.importGrantOfferLetter(p.getId()); verify(docusignService).importDocument("Envelope"); }
ProjectPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") public boolean partnersOnProjectCanView(ProjectResource project, UserResource user) { return project != null && isPartner(project.getId(), user.getId()); } @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") boolean partnersOnProjectCanView(ProjectResource project, UserResource user); @PermissionRule(value = "READ", description = "Internal users can see project resources") boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see project resources") boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can see project resources") boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user); @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Innovation leads on project competition can view finance reviewer.") boolean innovationLeadAssignedCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Stakeholders can view finance reviewer.") boolean stakeholderCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user); }
@Test public void partnersOnProjectCanView() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); setupUserAsPartner(project, user); assertTrue(rules.partnersOnProjectCanView(project, user)); } @Test public void partnersOnProjectCanViewButUserNotPartner() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); when(projectUserRepository.findByProjectIdAndUserIdAndRole(project.getId(), user.getId(), PROJECT_PARTNER)).thenReturn(emptyList()); assertFalse(rules.partnersOnProjectCanView(project, user)); }
ProjectPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ", description = "Internal users can see project resources") public boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user) { return isInternal(user); } @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") boolean partnersOnProjectCanView(ProjectResource project, UserResource user); @PermissionRule(value = "READ", description = "Internal users can see project resources") boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see project resources") boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can see project resources") boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user); @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Innovation leads on project competition can view finance reviewer.") boolean innovationLeadAssignedCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Stakeholders can view finance reviewer.") boolean stakeholderCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user); }
@Test public void internalUsersCanViewProjects() { ProjectResource project = newProjectResource().build(); allGlobalRoleUsers.forEach(user -> { if (allInternalUsers.contains(user)) { assertTrue(rules.internalUsersCanViewProjects(project, user)); } else { assertFalse(rules.internalUsersCanViewProjects(project, user)); } }); }
ProjectPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ", description = "Stakeholders can see project resources") public boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user) { return userIsStakeholderInCompetition(project.getCompetition(), user.getId()); } @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") boolean partnersOnProjectCanView(ProjectResource project, UserResource user); @PermissionRule(value = "READ", description = "Internal users can see project resources") boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see project resources") boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can see project resources") boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user); @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Innovation leads on project competition can view finance reviewer.") boolean innovationLeadAssignedCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Stakeholders can view finance reviewer.") boolean stakeholderCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user); }
@Test public void stakeholdersCanViewProjects() { User stakeholderUserOnCompetition = newUser().withRoles(singleton(STAKEHOLDER)).build(); UserResource stakeholderUserResourceOnCompetition = newUserResource().withId(stakeholderUserOnCompetition.getId()).withRolesGlobal(singletonList(STAKEHOLDER)).build(); Competition competition = newCompetition().build(); ProjectResource project = newProjectResource() .withCompetition(competition.getId()) .build(); when(stakeholderRepository.existsByCompetitionIdAndUserId(competition.getId(), stakeholderUserResourceOnCompetition.getId())).thenReturn(true); assertTrue(rules.stakeholdersCanViewProjects(project, stakeholderUserResourceOnCompetition)); allInternalUsers.forEach(user -> assertFalse(rules.stakeholdersCanViewProjects(newProjectResource().build(), user))); }
ProjectPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ", description = "Competition finance users can see project resources") public boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user) { return userIsExternalFinanceInCompetition(project.getCompetition(), user.getId()); } @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") boolean partnersOnProjectCanView(ProjectResource project, UserResource user); @PermissionRule(value = "READ", description = "Internal users can see project resources") boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see project resources") boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can see project resources") boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user); @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Innovation leads on project competition can view finance reviewer.") boolean innovationLeadAssignedCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Stakeholders can view finance reviewer.") boolean stakeholderCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user); }
@Test public void competitionFinanceUsersCanViewProjects() { User competitionFinanceUserOnCompetition = newUser().withRoles(singleton(EXTERNAL_FINANCE)).build(); UserResource competitionFinanceUserResourceOnCompetition = newUserResource().withId(competitionFinanceUserOnCompetition.getId()).withRolesGlobal(singletonList(STAKEHOLDER)).build(); Competition competition = newCompetition().build(); ProjectResource project = newProjectResource() .withCompetition(competition.getId()) .build(); when(externalFinanceRepository.existsByCompetitionIdAndUserId(competition.getId(), competitionFinanceUserOnCompetition.getId())).thenReturn(true); assertTrue(rules.competitionFinanceUsersCanViewProjects(project, competitionFinanceUserResourceOnCompetition)); allInternalUsers.forEach(user -> assertFalse(rules.competitionFinanceUsersCanViewProjects(newProjectResource().build(), user))); }
ProjectPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") public boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user) { return project != null && isMonitoringOfficer(project.getId(), user.getId()); } @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") boolean partnersOnProjectCanView(ProjectResource project, UserResource user); @PermissionRule(value = "READ", description = "Internal users can see project resources") boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see project resources") boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can see project resources") boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user); @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Innovation leads on project competition can view finance reviewer.") boolean innovationLeadAssignedCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Stakeholders can view finance reviewer.") boolean stakeholderCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user); }
@Test public void monitoringOfficerOnProjectCanView() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); setupUserAsMonitoringOfficer(project, user); assertTrue(rules.monitoringOfficerOnProjectCanView(project, user)); } @Test public void monitoringOfficerOnProjectCanViewWhenNotMonitoringOfficer() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); setupUserNotAsMonitoringOfficer(project, user); assertFalse(rules.monitoringOfficerOnProjectCanView(project, user)); }
RoleProfileStatusPermissionRoles { @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "kta can retrieve a users status") public boolean ktaCanRetrieveUserRoleProfile(UserResource userToCheck, UserResource user) { return isKta(user); } @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "Comp admin, project finance or support can retrieve a users status") boolean adminsAndSupportCanRetrieveUserRoleProfile(UserResource userToCheck, UserResource user); @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "Assessors can retrieve their own status") boolean usersCanRetrieveTheirOwnUserRoleProfile(UserResource userToCheck, UserResource user); @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "kta can retrieve a users status") boolean ktaCanRetrieveUserRoleProfile(UserResource userToCheck, UserResource user); }
@Test public void ktaCanRetrieveRoleProfiles() { UserResource otherUser = newUserResource().build(); allGlobalRoleUsers.forEach(user -> { if (isKta(user)) { assertTrue(rules.ktaCanRetrieveUserRoleProfile(otherUser, user)); } else { assertFalse(rules.ktaCanRetrieveUserRoleProfile(otherUser, user)); } }); }
ProjectPermissionRules extends BasePermissionRules { @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") public boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user) { return isSystemRegistrationUser(user) && isProjectActive(project.getId()); } @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") boolean partnersOnProjectCanView(ProjectResource project, UserResource user); @PermissionRule(value = "READ", description = "Internal users can see project resources") boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see project resources") boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can see project resources") boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user); @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Innovation leads on project competition can view finance reviewer.") boolean innovationLeadAssignedCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Stakeholders can view finance reviewer.") boolean stakeholderCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user); }
@Test public void systemRegistrarCanAddPartnersToProject() { ProjectResource project = newProjectResource().build(); ProjectProcess projectProcess = newProjectProcess().withActivityState(ProjectState.SETUP).build(); when(projectProcessRepository.findOneByTargetId(project.getId())).thenReturn(projectProcess); allGlobalRoleUsers.forEach(user -> { if (systemRegistrationUser().equals(user)) { assertTrue(rules.systemRegistrarCanAddPartnersToProject(project, user)); } else { assertFalse(rules.systemRegistrarCanAddPartnersToProject(project, user)); } }); }
ProjectPermissionRules extends BasePermissionRules { @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") public boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user) { return isProjectFinanceUser(user); } @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") boolean partnersOnProjectCanView(ProjectResource project, UserResource user); @PermissionRule(value = "READ", description = "Internal users can see project resources") boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see project resources") boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can see project resources") boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user); @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Innovation leads on project competition can view finance reviewer.") boolean innovationLeadAssignedCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Stakeholders can view finance reviewer.") boolean stakeholderCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user); }
@Test public void projectFinanceCanViewFinanceReviewer() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); setUpUserAsProjectFinanceUser(project, user); assertTrue(rules.projectFinanceCanViewFinanceReviewer(project, user)); } @Test public void nonProjectFinanceCannotViewFinanceReviewer() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); setUpUserNotAsProjectFinanceUser(project, user); assertFalse(rules.projectFinanceCanViewFinanceReviewer(project, user)); }
ProjectPermissionRules extends BasePermissionRules { @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") public boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user) { return isCompAdmin(user); } @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") boolean partnersOnProjectCanView(ProjectResource project, UserResource user); @PermissionRule(value = "READ", description = "Internal users can see project resources") boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see project resources") boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can see project resources") boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user); @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Innovation leads on project competition can view finance reviewer.") boolean innovationLeadAssignedCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Stakeholders can view finance reviewer.") boolean stakeholderCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user); }
@Test public void compAdminCanViewFinanceReviewer() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); setUpUserAsCompAdmin(project, user); assertTrue(rules.compAdminCanViewFinanceReviewer(project, user)); } @Test public void nonCompAdminCannotViewFinanceReviewer() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); setUpUserNotAsCompAdmin(project, user); assertFalse(rules.compAdminCanViewFinanceReviewer(project, user)); }
ProjectPermissionRules extends BasePermissionRules { @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") public boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user) { return isSupport(user); } @PermissionRule(value = "READ", description = "A user can see projects that they are partners on") boolean partnersOnProjectCanView(ProjectResource project, UserResource user); @PermissionRule(value = "READ", description = "Internal users can see project resources") boolean internalUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see project resources") boolean stakeholdersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "Competition finance users can see project resources") boolean competitionFinanceUsersCanViewProjects(final ProjectResource project, final UserResource user); @PermissionRule(value = "READ", description = "A monitoring officer can see projects that they are assigned to") boolean monitoringOfficerOnProjectCanView(final ProjectResource project, final UserResource user); @PermissionRule(value = "ADD_PARTNER", description = "The System Registration user can add a partner to a project") boolean systemRegistrarCanAddPartnersToProject(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Innovation leads on project competition can view finance reviewer.") boolean innovationLeadAssignedCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Stakeholders can view finance reviewer.") boolean stakeholderCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Project finance users can view finance reviewer.") boolean projectFinanceCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Comp admin users can view finance reviewer.") boolean compAdminCanViewFinanceReviewer(final ProjectResource project, final UserResource user); @PermissionRule(value = "VIEW_FINANCE_REVIEWER", description = "Support users can view finance reviewer.") boolean supportCanViewFinanceReviewer(final ProjectResource project, final UserResource user); }
@Test public void supportCanViewFinanceReviewer() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); setUpUserAsSupport(project, user); assertTrue(rules.supportCanViewFinanceReviewer(project, user)); } @Test public void nonSupportCannotViewFinanceReviewer() { UserResource user = newUserResource().build(); ProjectResource project = newProjectResource().build(); setUpUserNotAsSupport(project, user); assertFalse(rules.supportCanViewFinanceReviewer(project, user)); }
PartnerOrganisationPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ", description = "A partner can see a list of all partner organisations on their project") public boolean partnersOnProjectCanView(final PartnerOrganisationResource partnerOrganisation, final UserResource user) { return isPartner(partnerOrganisation.getProject(), user.getId()); } @PermissionRule(value = "READ", description = "A partner can see a list of all partner organisations on their project") boolean partnersOnProjectCanView(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Internal users can see partner organisations for any project") boolean internalUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see partner organisations on projects in competitions they are assigned to") boolean stakeholdersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Competition finances users can see partner organisations on projects in competitions they are assigned to") boolean competitionFinanceUsersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can see partner organisations on a project they are assigned to") boolean monitoringOfficersUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Partners can read their own progress when setting up their organisation") boolean partnersCanReadTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Internal users can read partner progress in project setup") boolean internalUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Stakeholders can read partner progress in project setup in competitions they are assigned to") boolean stakeholdersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Competition finance users can read partner progress in project setup in competitions they are assigned to") boolean competitionFinanceUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "UPDATE_PENDING_PARTNER_PROGRESS", description = "Partners can update their own progress when setting up their organisation") boolean partnersCanUpdateTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "REMOVE_PARTNER_ORGANISATION", description = "Internal users can remove partner organisations for any project") boolean internalUsersCanRemovePartnerOrganisations(final PartnerOrganisationResource partnerOrganisation, final UserResource user); }
@Test public void partnersCanView() { UserResource user = newUserResource().withRolesGlobal(singletonList(COMP_ADMIN)).build(); Project project = newProject().build(); ProjectUser projectUser = newProjectUser().withProject(project).build(); when(projectUserRepository.findByProjectIdAndUserIdAndRoleIsIn(project.getId(), user.getId(), PROJECT_USER_ROLES.stream().collect(Collectors.toList()))).thenReturn(singletonList(projectUser)); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource().withProject(project.getId()).build(); assertTrue(rules.partnersOnProjectCanView(partnerOrg, user)); } @Test public void nonPartnersCannotView() { UserResource user = newUserResource().withRolesGlobal(singletonList(COMP_ADMIN)).build(); Project project = newProject().build(); when(projectUserRepository.findByProjectIdAndUserIdAndRoleIsIn(project.getId(), user.getId(), PROJECT_USER_ROLES.stream().collect(Collectors.toList()))).thenReturn(emptyList()); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource().withProject(project.getId()).build(); assertFalse(rules.partnersOnProjectCanView(partnerOrg, user)); }
RoleProfileStatusPermissionRoles { @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "Assessors can retrieve their own status") public boolean usersCanRetrieveTheirOwnUserRoleProfile(UserResource userToCheck, UserResource user) { return userToCheck.equals(user); } @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "Comp admin, project finance or support can retrieve a users status") boolean adminsAndSupportCanRetrieveUserRoleProfile(UserResource userToCheck, UserResource user); @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "Assessors can retrieve their own status") boolean usersCanRetrieveTheirOwnUserRoleProfile(UserResource userToCheck, UserResource user); @PermissionRule(value = "RETRIEVE_USER_ROLE_PROFILE", description = "kta can retrieve a users status") boolean ktaCanRetrieveUserRoleProfile(UserResource userToCheck, UserResource user); }
@Test public void usersCanRetrieveTheirOwnRoleProfiles() { UserResource user = newUserResource().build(); assertTrue(rules.usersCanRetrieveTheirOwnUserRoleProfile(user, user)); }
PartnerOrganisationPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ", description = "Internal users can see partner organisations for any project") public boolean internalUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user) { return isInternal(user); } @PermissionRule(value = "READ", description = "A partner can see a list of all partner organisations on their project") boolean partnersOnProjectCanView(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Internal users can see partner organisations for any project") boolean internalUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see partner organisations on projects in competitions they are assigned to") boolean stakeholdersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Competition finances users can see partner organisations on projects in competitions they are assigned to") boolean competitionFinanceUsersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can see partner organisations on a project they are assigned to") boolean monitoringOfficersUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Partners can read their own progress when setting up their organisation") boolean partnersCanReadTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Internal users can read partner progress in project setup") boolean internalUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Stakeholders can read partner progress in project setup in competitions they are assigned to") boolean stakeholdersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Competition finance users can read partner progress in project setup in competitions they are assigned to") boolean competitionFinanceUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "UPDATE_PENDING_PARTNER_PROGRESS", description = "Partners can update their own progress when setting up their organisation") boolean partnersCanUpdateTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "REMOVE_PARTNER_ORGANISATION", description = "Internal users can remove partner organisations for any project") boolean internalUsersCanRemovePartnerOrganisations(final PartnerOrganisationResource partnerOrganisation, final UserResource user); }
@Test public void internalUserCanView() { UserResource user = newUserResource().withRolesGlobal(singletonList(COMP_ADMIN)).build(); Project project = newProject().build(); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource().withProject(project.getId()).build(); assertTrue(rules.internalUsersCanView(partnerOrg, user)); } @Test public void externalUsersCannotView() { UserResource user = newUserResource().withRolesGlobal(singletonList(PARTNER)).build(); Project project = newProject().build(); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource().withProject(project.getId()).build(); assertFalse(rules.internalUsersCanView(partnerOrg, user)); }
PartnerOrganisationPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ", description = "Monitoring officers can see partner organisations on a project they are assigned to") public boolean monitoringOfficersUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user) { return isMonitoringOfficer(partnerOrganisation.getProject(), user.getId()); } @PermissionRule(value = "READ", description = "A partner can see a list of all partner organisations on their project") boolean partnersOnProjectCanView(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Internal users can see partner organisations for any project") boolean internalUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see partner organisations on projects in competitions they are assigned to") boolean stakeholdersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Competition finances users can see partner organisations on projects in competitions they are assigned to") boolean competitionFinanceUsersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can see partner organisations on a project they are assigned to") boolean monitoringOfficersUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Partners can read their own progress when setting up their organisation") boolean partnersCanReadTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Internal users can read partner progress in project setup") boolean internalUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Stakeholders can read partner progress in project setup in competitions they are assigned to") boolean stakeholdersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Competition finance users can read partner progress in project setup in competitions they are assigned to") boolean competitionFinanceUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "UPDATE_PENDING_PARTNER_PROGRESS", description = "Partners can update their own progress when setting up their organisation") boolean partnersCanUpdateTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "REMOVE_PARTNER_ORGANISATION", description = "Internal users can remove partner organisations for any project") boolean internalUsersCanRemovePartnerOrganisations(final PartnerOrganisationResource partnerOrganisation, final UserResource user); }
@Test public void monitoringOfficerCanView() { UserResource user = newUserResource().withRolesGlobal(singletonList(MONITORING_OFFICER)).build(); Project project = newProject().build(); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource().withProject(project.getId()).build(); when(projectMonitoringOfficerRepository.existsByProjectIdAndUserId(project.getId(), user.getId())).thenReturn(true); assertTrue(rules.monitoringOfficersUsersCanView(partnerOrg, user)); }
PartnerOrganisationPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ", description = "Competition finances users can see partner organisations on projects in competitions they are assigned to") public boolean competitionFinanceUsersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user) { return userIsExternalFinanceOnCompetitionForProject(partnerOrganisation.getProject(), user.getId()); } @PermissionRule(value = "READ", description = "A partner can see a list of all partner organisations on their project") boolean partnersOnProjectCanView(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Internal users can see partner organisations for any project") boolean internalUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see partner organisations on projects in competitions they are assigned to") boolean stakeholdersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Competition finances users can see partner organisations on projects in competitions they are assigned to") boolean competitionFinanceUsersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can see partner organisations on a project they are assigned to") boolean monitoringOfficersUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Partners can read their own progress when setting up their organisation") boolean partnersCanReadTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Internal users can read partner progress in project setup") boolean internalUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Stakeholders can read partner progress in project setup in competitions they are assigned to") boolean stakeholdersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Competition finance users can read partner progress in project setup in competitions they are assigned to") boolean competitionFinanceUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "UPDATE_PENDING_PARTNER_PROGRESS", description = "Partners can update their own progress when setting up their organisation") boolean partnersCanUpdateTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "REMOVE_PARTNER_ORGANISATION", description = "Internal users can remove partner organisations for any project") boolean internalUsersCanRemovePartnerOrganisations(final PartnerOrganisationResource partnerOrganisation, final UserResource user); }
@Test public void externalFinanceUserCanView() { long projectId = 1L; Competition competition = newCompetition().build(); Organisation organisation = newOrganisation().build(); UserResource user = newUserResource().withRolesGlobal(singletonList(EXTERNAL_FINANCE)).build(); Project project = newProject().withId(projectId).withApplication(newApplication() .withCompetition(competition).build()).build(); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource().withOrganisation(organisation.getId()).withProject(projectId).build(); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); when(externalFinanceRepository.existsByCompetitionIdAndUserId(competition.getId(), user.getId())).thenReturn(true); assertTrue(rules.competitionFinanceUsersCanViewProjects(partnerOrg, user)); }
PartnerOrganisationPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Partners can read their own progress when setting up their organisation") public boolean partnersCanReadTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user) { return partnerBelongsToOrganisation(partnerOrganisation.getProject(), user.getId(), partnerOrganisation.getOrganisation()); } @PermissionRule(value = "READ", description = "A partner can see a list of all partner organisations on their project") boolean partnersOnProjectCanView(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Internal users can see partner organisations for any project") boolean internalUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see partner organisations on projects in competitions they are assigned to") boolean stakeholdersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Competition finances users can see partner organisations on projects in competitions they are assigned to") boolean competitionFinanceUsersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can see partner organisations on a project they are assigned to") boolean monitoringOfficersUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Partners can read their own progress when setting up their organisation") boolean partnersCanReadTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Internal users can read partner progress in project setup") boolean internalUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Stakeholders can read partner progress in project setup in competitions they are assigned to") boolean stakeholdersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Competition finance users can read partner progress in project setup in competitions they are assigned to") boolean competitionFinanceUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "UPDATE_PENDING_PARTNER_PROGRESS", description = "Partners can update their own progress when setting up their organisation") boolean partnersCanUpdateTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "REMOVE_PARTNER_ORGANISATION", description = "Internal users can remove partner organisations for any project") boolean internalUsersCanRemovePartnerOrganisations(final PartnerOrganisationResource partnerOrganisation, final UserResource user); }
@Test public void partnersCannotViewOtherPendingPartnerProgress() { long projectId = 1L; long organisationId = 2L; UserResource user = newUserResource().build(); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource() .withProject(projectId) .withOrganisation(organisationId) .build(); when(projectUserRepository.findFirstByProjectIdAndUserIdAndOrganisationIdAndRoleIn(projectId, user.getId(), organisationId, PROJECT_USER_ROLES.stream().collect(Collectors.toList()))).thenReturn(null); assertFalse(rules.partnersCanReadTheirOwnPendingPartnerProgress(partnerOrg, user)); } @Test public void partnersCanViewTheirOwnPendingPartnerProgress() { long projectId = 1L; long organisationId = 2L; UserResource user = newUserResource().build(); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource() .withProject(projectId) .withOrganisation(organisationId) .build(); ProjectUser projectUser = newProjectUser() .build(); when(projectUserRepository.findFirstByProjectIdAndUserIdAndOrganisationIdAndRoleIn(projectId, user.getId(), organisationId, PROJECT_USER_ROLES.stream().collect(Collectors.toList()))).thenReturn(projectUser); assertTrue(rules.partnersCanReadTheirOwnPendingPartnerProgress(partnerOrg, user)); }
PartnerOrganisationPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Internal users can read partner progress in project setup") public boolean internalUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user) { return isInternal(user); } @PermissionRule(value = "READ", description = "A partner can see a list of all partner organisations on their project") boolean partnersOnProjectCanView(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Internal users can see partner organisations for any project") boolean internalUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see partner organisations on projects in competitions they are assigned to") boolean stakeholdersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Competition finances users can see partner organisations on projects in competitions they are assigned to") boolean competitionFinanceUsersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can see partner organisations on a project they are assigned to") boolean monitoringOfficersUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Partners can read their own progress when setting up their organisation") boolean partnersCanReadTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Internal users can read partner progress in project setup") boolean internalUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Stakeholders can read partner progress in project setup in competitions they are assigned to") boolean stakeholdersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Competition finance users can read partner progress in project setup in competitions they are assigned to") boolean competitionFinanceUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "UPDATE_PENDING_PARTNER_PROGRESS", description = "Partners can update their own progress when setting up their organisation") boolean partnersCanUpdateTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "REMOVE_PARTNER_ORGANISATION", description = "Internal users can remove partner organisations for any project") boolean internalUsersCanRemovePartnerOrganisations(final PartnerOrganisationResource partnerOrganisation, final UserResource user); }
@Test public void internalUsersCanViewPendingPartnerProgress() { long projectId = 1L; long organisationId = 2L; UserResource user = newUserResource().build(); user.isInternalUser(); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource() .withProject(projectId) .withOrganisation(organisationId) .build(); assertFalse(rules.internalUsersCanReadPendingPartnerProgress(partnerOrg, user)); }
PartnerOrganisationPermissionRules extends BasePermissionRules { @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Competition finance users can read partner progress in project setup in competitions they are assigned to") public boolean competitionFinanceUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user) { return userIsExternalFinanceOnCompetitionForProject(partnerOrganisation.getProject(), user.getId()); } @PermissionRule(value = "READ", description = "A partner can see a list of all partner organisations on their project") boolean partnersOnProjectCanView(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Internal users can see partner organisations for any project") boolean internalUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ", description = "Stakeholders can see partner organisations on projects in competitions they are assigned to") boolean stakeholdersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Competition finances users can see partner organisations on projects in competitions they are assigned to") boolean competitionFinanceUsersCanViewProjects(PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ", description = "Monitoring officers can see partner organisations on a project they are assigned to") boolean monitoringOfficersUsersCanView(PartnerOrganisationResource partnerOrganisation, UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Partners can read their own progress when setting up their organisation") boolean partnersCanReadTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Internal users can read partner progress in project setup") boolean internalUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Stakeholders can read partner progress in project setup in competitions they are assigned to") boolean stakeholdersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "READ_PENDING_PARTNER_PROGRESS", description = "Competition finance users can read partner progress in project setup in competitions they are assigned to") boolean competitionFinanceUsersCanReadPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "UPDATE_PENDING_PARTNER_PROGRESS", description = "Partners can update their own progress when setting up their organisation") boolean partnersCanUpdateTheirOwnPendingPartnerProgress(final PartnerOrganisationResource partnerOrganisation, final UserResource user); @PermissionRule(value = "REMOVE_PARTNER_ORGANISATION", description = "Internal users can remove partner organisations for any project") boolean internalUsersCanRemovePartnerOrganisations(final PartnerOrganisationResource partnerOrganisation, final UserResource user); }
@Test public void externalFinanceUsersCanViewPendingPartnerProgress() { long projectId = 1L; long organisationId = 2L; Competition competition = newCompetition().build(); UserResource user = newUserResource().withRoleGlobal(EXTERNAL_FINANCE).build(); Project project = newProject().withId(projectId).withApplication(newApplication() .withCompetition(competition).build()).build(); PartnerOrganisationResource partnerOrg = newPartnerOrganisationResource().withOrganisation(organisationId).withProject(project.getId()).build(); when(projectRepository.findById(projectId)).thenReturn(Optional.of(project)); when(externalFinanceRepository.existsByCompetitionIdAndUserId(competition.getId(), user.getId())).thenReturn(true); assertTrue(rules.competitionFinanceUsersCanReadPendingPartnerProgress(partnerOrg, user)); }