use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectMembersController method getProjectUserMembers.
/**
* Get a page of users on the project for display in a DataTable.
*
* @param params
* the datatables parameters for this DataTable
* @param projectId
* the id of the project we're looking at
* @return a {@link DataTablesResponseModel} of users on the project
*/
@RequestMapping(value = "/{projectId}/settings/ajax/members")
@ResponseBody
public DataTablesResponse getProjectUserMembers(@DataTablesRequest DataTablesParams params, @PathVariable final Long projectId) {
final Project project = projectService.read(projectId);
final Page<Join<Project, User>> usersForProject = userService.searchUsersForProject(project, params.getSearchValue(), params.getCurrentPage(), params.getLength(), params.getSort());
List<DataTablesResponseModel> modelList = new ArrayList<>();
for (Join<Project, User> join : usersForProject) {
modelList.add(new DTProjectMember((ProjectUserJoin) join));
}
return new DataTablesResponse(params, usersForProject, modelList);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectEventEmailScheduedTaskImplTest method testEmailUserPartialSubscriptoinTasks.
@SuppressWarnings("unchecked")
@Test
public void testEmailUserPartialSubscriptoinTasks() {
User tom = new User("tom", null, null, null, null, null);
Project p = new Project("testproject");
Project p2 = new Project("testproject2");
List<User> users = Lists.newArrayList(tom);
ProjectUserJoin join = new ProjectUserJoin(p, tom, ProjectRole.PROJECT_OWNER);
join.setEmailSubscription(true);
ProjectUserJoin notSubscribed = new ProjectUserJoin(p2, tom, ProjectRole.PROJECT_OWNER);
List<ProjectEvent> events = Lists.newArrayList(new UserRoleSetProjectEvent(join), new UserRoleSetProjectEvent(notSubscribed));
when(userService.getUsersWithEmailSubscriptions()).thenReturn(users);
when(eventService.getEventsForUserAfterDate(eq(tom), any(Date.class))).thenReturn(events);
when(projectService.getProjectsForUser(tom)).thenReturn(Lists.newArrayList(join, notSubscribed));
task.emailUserTasks();
verify(userService).getUsersWithEmailSubscriptions();
verify(eventService).getEventsForUserAfterDate(eq(tom), any(Date.class));
@SuppressWarnings("rawtypes") ArgumentCaptor<List> eventCaptor = ArgumentCaptor.forClass(List.class);
verify(emailController).sendSubscriptionUpdateEmail(eq(tom), eventCaptor.capture());
List<ProjectEvent> sentEvents = eventCaptor.getValue();
assertEquals("should send 1 event", 1, sentEvents.size());
ProjectEvent sentEvent = sentEvents.iterator().next();
assertEquals("should have sent from subscribed project", p, sentEvent.getProject());
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectEventEmailScheduedTaskImplTest method testEmailUserTasks.
@SuppressWarnings("unchecked")
@Test
public void testEmailUserTasks() {
Date priorDateFromCronString = ProjectEventEmailScheduledTaskImpl.getPriorDateFromCronString(task.getScheduledCronString());
User tom = new User("tom", null, null, null, null, null);
Project p = new Project("testproject");
List<User> users = Lists.newArrayList(tom);
ProjectUserJoin join = new ProjectUserJoin(p, tom, ProjectRole.PROJECT_OWNER);
join.setEmailSubscription(true);
List<ProjectEvent> events = Lists.newArrayList(new UserRoleSetProjectEvent(join));
when(userService.getUsersWithEmailSubscriptions()).thenReturn(users);
when(eventService.getEventsForUserAfterDate(eq(tom), any(Date.class))).thenReturn(events);
when(projectService.getProjectsForUser(tom)).thenReturn(Lists.newArrayList(join));
Date now = new Date();
task.emailUserTasks();
verify(userService).getUsersWithEmailSubscriptions();
ArgumentCaptor<Date> dateCaptor = ArgumentCaptor.forClass(Date.class);
verify(eventService).getEventsForUserAfterDate(eq(tom), dateCaptor.capture());
verify(emailController).sendSubscriptionUpdateEmail(tom, events);
Date testedDate = dateCaptor.getValue();
assertTrue("date should be before current time", now.after(testedDate));
assertTrue("date should be equal to or before scheduled time", priorDateFromCronString.before(testedDate) || priorDateFromCronString.equals(testedDate));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectServiceImplTest method testUserHasProjectRole.
@SuppressWarnings("unchecked")
@Test
public void testUserHasProjectRole() {
Project p = project();
User u = new User();
List<ProjectUserJoin> joins = new ArrayList<>();
joins.add(new ProjectUserJoin(p, u, ProjectRole.PROJECT_OWNER));
Page<ProjectUserJoin> page = new PageImpl<>(joins);
when(pujRepository.findAll(any(Specification.class), any(PageRequest.class))).thenReturn(page);
assertTrue("User has ownership of project.", projectService.userHasProjectRole(u, p, ProjectRole.PROJECT_OWNER));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectServiceImplTest method testUpdateProjectUserJoinIllegalChange.
@Test(expected = ProjectWithoutOwnerException.class)
public void testUpdateProjectUserJoinIllegalChange() throws ProjectWithoutOwnerException {
Project project = new Project("Project 1");
User user = new User();
ProjectRole projectRole = ProjectRole.PROJECT_USER;
ProjectUserJoin oldJoin = new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER);
@SuppressWarnings("unchecked") List<Join<Project, User>> owners = Lists.newArrayList(new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER));
when(pujRepository.getProjectJoinForUser(project, user)).thenReturn(oldJoin);
when(pujRepository.getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER)).thenReturn(owners);
projectService.updateUserProjectRole(project, user, projectRole);
}
Aggregations