Search in sources :

Example 1 with ProjectUserJoin

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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) DTProjectMember(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProjectMember)

Example 2 with ProjectUserJoin

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());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) List(java.util.List) Date(java.util.Date) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) Test(org.junit.Test)

Example 3 with ProjectUserJoin

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));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Date(java.util.Date) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) Test(org.junit.Test)

Example 4 with ProjectUserJoin

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));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Project(ca.corefacility.bioinformatics.irida.model.project.Project) PageRequest(org.springframework.data.domain.PageRequest) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ArrayList(java.util.ArrayList) Specification(org.springframework.data.jpa.domain.Specification) Test(org.junit.Test)

Example 5 with ProjectUserJoin

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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) Test(org.junit.Test)

Aggregations

ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)34 Project (ca.corefacility.bioinformatics.irida.model.project.Project)26 User (ca.corefacility.bioinformatics.irida.model.user.User)23 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)20 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)12 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)8 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)7 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)7 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 Authentication (org.springframework.security.core.Authentication)6 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)4 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)4 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)4 ProjectWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException)3 ProjectReferenceFileJoin (ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin)3 DTUser (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser)3 List (java.util.List)3 Locale (java.util.Locale)3