Search in sources :

Example 36 with Join

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

the class ReadSequencingObjectPermissionTest method testRejectPermission.

@Test
public void testRejectPermission() {
    Project p = new Project();
    Sample s = new Sample();
    List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
    projectSampleList.add(new ProjectSampleJoin(p, s, true));
    SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
    SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
    when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
    when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
    when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
    when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertFalse("permission was granted.", permission.isAllowed(auth, 1L));
    verify(sequencingObjectRepository).findOne(1L);
    verify(psjRepository).getProjectForSample(s);
    verify(ssoRepository).getSampleForSequencingObject(sf);
    verify(readProjectPermission).isAllowed(any(), eq(p));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) 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) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 37 with Join

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

the class ReadSequencingObjectPermissionTest method testGrantPermission.

@Test
public void testGrantPermission() {
    Project p = new Project();
    Sample s = new Sample();
    List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
    projectSampleList.add(new ProjectSampleJoin(p, s, true));
    SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
    SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
    when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
    when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
    when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
    when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertTrue("permission was not granted.", permission.isAllowed(auth, 1L));
    verify(sequencingObjectRepository).findOne(1L);
    verify(psjRepository).getProjectForSample(s);
    verify(ssoRepository).getSampleForSequencingObject(sf);
    verify(readProjectPermission).isAllowed(any(), eq(p));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) 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) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 38 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join 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 39 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join 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 40 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join 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)

Aggregations

Join (ca.corefacility.bioinformatics.irida.model.joins.Join)65 Project (ca.corefacility.bioinformatics.irida.model.project.Project)60 Test (org.junit.Test)40 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)35 User (ca.corefacility.bioinformatics.irida.model.user.User)35 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)34 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)26 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)23 ArrayList (java.util.ArrayList)20 WithMockUser (org.springframework.security.test.context.support.WithMockUser)20 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)16 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)14 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)13 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)13 List (java.util.List)12 Set (java.util.Set)12 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 ProjectSampleJoinRepository (ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository)10 ProjectService (ca.corefacility.bioinformatics.irida.service.ProjectService)10