Search in sources :

Example 21 with ProjectUserJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.

the class ProjectOwnerPermissionTest method setup.

@SuppressWarnings("unchecked")
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    user.setSystemRole(Role.ROLE_USER);
    user.setUsername("tom");
    permission = new ProjectOwnerPermission(projectRepository, userRepository, pujRepository, ugpjRepository, ugRepository);
    when(projectRepository.findOne(projectId)).thenReturn(project);
    when(userRepository.loadUserByUsername(user.getUsername())).thenReturn(user);
    when(pujRepository.getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER)).thenReturn(Lists.newArrayList(new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER)));
}
Also used : ProjectOwnerPermission(ca.corefacility.bioinformatics.irida.security.permissions.project.ProjectOwnerPermission) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Before(org.junit.Before)

Example 22 with ProjectUserJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.

the class ReadProjectPermissionTest method testRejectPermission.

@Test
public void testRejectPermission() {
    String username = "fbristow";
    User u = new User();
    u.setUsername(username);
    Project p = new Project();
    List<Join<Project, User>> projectUsers = new ArrayList<>();
    projectUsers.add(new ProjectUserJoin(p, new User(), ProjectRole.PROJECT_USER));
    when(userRepository.loadUserByUsername(username)).thenReturn(u);
    when(projectRepository.findOne(1L)).thenReturn(p);
    when(pujRepository.getUsersForProject(p)).thenReturn(projectUsers);
    when(ugpjRepository.findGroupsByProject(p)).thenReturn(ImmutableList.of());
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertFalse("permission was granted.", readProjectPermission.isAllowed(auth, 1L));
    verify(userRepository).loadUserByUsername(username);
    verify(projectRepository).findOne(1L);
    verify(pujRepository).getUsersForProject(p);
    verifyZeroInteractions(ugRepository);
}
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) Authentication(org.springframework.security.core.Authentication) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 23 with ProjectUserJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.

the class ReadSamplePermissionTest method testRejectPermission.

@Test
public void testRejectPermission() {
    String username = "fbristow";
    User u = new User();
    u.setUsername(username);
    Project p = new Project();
    Sample s = new Sample();
    List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
    projectSampleList.add(new ProjectSampleJoin(p, s, true));
    List<Join<Project, User>> projectUsers = new ArrayList<>();
    projectUsers.add(new ProjectUserJoin(p, new User(), ProjectRole.PROJECT_USER));
    when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
    when(sampleRepository.findOne(1L)).thenReturn(s);
    when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertFalse("permission was granted.", readSamplePermission.isAllowed(auth, 1L));
    verify(sampleRepository).findOne(1L);
    verify(psjRepository).getProjectForSample(s);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) 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) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) ArrayList(java.util.ArrayList) 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) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 24 with ProjectUserJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.

the class UsersControllerTest method testGetOtherUsersSpecificPage.

@Test
public void testGetOtherUsersSpecificPage() {
    Principal principal = () -> USER_NAME;
    Long userId = 1L;
    String roleString = "User";
    ExtendedModelMap model = new ExtendedModelMap();
    User puser = new User(userId, USER_NAME, null, null, null, null, null);
    puser.setSystemRole(Role.ROLE_USER);
    User user = new User(userId, "tom", null, null, null, null, null);
    user.setSystemRole(Role.ROLE_USER);
    @SuppressWarnings("unchecked") List<Join<Project, User>> joins = Lists.newArrayList(new ProjectUserJoin(new Project("good project"), user, ProjectRole.PROJECT_USER));
    when(userService.read(userId)).thenReturn(user);
    when(userService.getUserByUsername(USER_NAME)).thenReturn(puser);
    when(messageSource.getMessage(eq("systemrole." + Role.ROLE_USER.getName()), eq(null), any(Locale.class))).thenReturn(roleString);
    when(projectService.getProjectsForUser(user)).thenReturn(joins);
    String userSpecificPage = controller.getUserSpecificPage(userId, true, model, principal);
    assertEquals(USERS_DETAILS_PAGE, userSpecificPage);
    assertEquals(false, model.get("canEditUser"));
    verify(userService).read(userId);
    verify(userService).getUserByUsername(USER_NAME);
    verify(messageSource).getMessage(eq("systemrole." + Role.ROLE_USER.getName()), eq(null), any(Locale.class));
    verify(projectService).getProjectsForUser(user);
}
Also used : Locale(java.util.Locale) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) DTUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Principal(java.security.Principal) Test(org.junit.Test)

Example 25 with ProjectUserJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.

the class ProjectServiceImplTest method testUpdateProjectUserJoin.

@Test
public void testUpdateProjectUserJoin() throws ProjectWithoutOwnerException {
    Project project = new Project("Project 1");
    User user = new User();
    User user2 = 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), new ProjectUserJoin(project, user2, ProjectRole.PROJECT_OWNER));
    when(pujRepository.getProjectJoinForUser(project, user)).thenReturn(oldJoin);
    when(pujRepository.save(oldJoin)).thenReturn(oldJoin);
    when(pujRepository.getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER)).thenReturn(owners);
    Join<Project, User> updateUserProjectRole = projectService.updateUserProjectRole(project, user, projectRole);
    assertNotNull(updateUserProjectRole);
    ProjectUserJoin newJoin = (ProjectUserJoin) updateUserProjectRole;
    assertEquals(projectRole, newJoin.getProjectRole());
    verify(pujRepository).getProjectJoinForUser(project, user);
    verify(pujRepository).getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER);
    verify(pujRepository).save(oldJoin);
}
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