Search in sources :

Example 16 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class UpdateUserGroupPermissionTest method testRejectNotInGroup.

@Test
public void testRejectNotInGroup() {
    final String username = "user";
    final User u = new User();
    final User u2 = new User();
    final UserGroup ug = new UserGroup("group");
    u.setUsername(username);
    when(userRepository.loadUserByUsername(username)).thenReturn(u);
    when(userRepository.findOne(1L)).thenReturn(u);
    when(userGroupRepository.findOne(1L)).thenReturn(ug);
    when(userGroupJoinRepository.findUsersInGroup(ug)).thenReturn(ImmutableList.of(new UserGroupJoin(u2, ug, UserGroupRole.GROUP_OWNER)));
    final Authentication auth = new UsernamePasswordAuthenticationToken(username, "password1");
    assertFalse("permission should not be granted.", updateUserPermission.isAllowed(auth, 1L));
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) Authentication(org.springframework.security.core.Authentication) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Test(org.junit.Test)

Example 17 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class ProjectServiceImplIT method testRemoveUserGroupOnProject.

@Test(expected = ProjectWithoutOwnerException.class)
@WithMockUser(username = "groupuser", roles = "USER")
public void testRemoveUserGroupOnProject() throws ProjectWithoutOwnerException {
    final UserGroup userGroup = userGroupService.read(1L);
    final Project project = projectService.read(9L);
    projectService.removeUserGroupFromProject(project, userGroup);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 18 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class ProjectServiceImplIT method testUpdateUserGroupRoleOnProject.

@Test(expected = ProjectWithoutOwnerException.class)
@WithMockUser(username = "groupuser", roles = "USER")
public void testUpdateUserGroupRoleOnProject() throws ProjectWithoutOwnerException {
    final UserGroup userGroup = userGroupService.read(1L);
    final Project project = projectService.read(9L);
    projectService.updateUserGroupProjectRole(project, userGroup, ProjectRole.PROJECT_USER);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 19 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class ProjectServiceImplTest method testGetProjectsForUser.

@Test
public void testGetProjectsForUser() {
    final User u = new User();
    final Project p1 = new Project("p1");
    final Project p2 = new Project("p2");
    final UserGroup ug = new UserGroup("group");
    final ProjectUserJoin puj = new ProjectUserJoin(p1, u, ProjectRole.PROJECT_OWNER);
    final UserGroupProjectJoin ugpj = new UserGroupProjectJoin(p2, ug, ProjectRole.PROJECT_OWNER);
    when(pujRepository.getProjectsForUser(u)).thenReturn(ImmutableList.of(puj));
    when(ugpjRepository.findProjectsByUser(u)).thenReturn(ImmutableList.of(ugpj));
    final List<Join<Project, User>> projects = projectService.getProjectsForUser(u);
    assertEquals("User should be in 2 projects.", 2, projects.size());
    assertTrue("Should have found user project join.", projects.stream().anyMatch(p -> p.getSubject().equals(p1)));
    assertTrue("Should have found group project join.", projects.stream().anyMatch(p -> p.getSubject().equals(p2)));
}
Also used : ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) ProjectSampleJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository) ConstraintViolationImpl(org.hibernate.validator.internal.engine.ConstraintViolationImpl) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Path(java.nio.file.Path) ConstraintViolation(javax.validation.ConstraintViolation) ReferenceFileRepository(ca.corefacility.bioinformatics.irida.repositories.referencefile.ReferenceFileRepository) UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) Set(java.util.Set) Validator(javax.validation.Validator) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) SampleSequencingObjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.sample.SampleSequencingObjectJoinRepository) Matchers.any(org.mockito.Matchers.any) ProjectUserJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectUserJoinRepository) List(java.util.List) Specification(org.springframework.data.jpa.domain.Specification) Assert.assertFalse(org.junit.Assert.assertFalse) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectAnalysisSubmissionJoinRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.ProjectAnalysisSubmissionJoinRepository) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) PageImpl(org.springframework.data.domain.PageImpl) Mockito.mock(org.mockito.Mockito.mock) ProjectServiceImpl(ca.corefacility.bioinformatics.irida.service.impl.ProjectServiceImpl) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SampleRepository(ca.corefacility.bioinformatics.irida.repositories.sample.SampleRepository) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UserGroupProjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.UserGroupProjectJoinRepository) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ProjectReferenceFileJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectReferenceFileJoinRepository) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) RelatedProjectRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.RelatedProjectRepository) ProjectRepository(ca.corefacility.bioinformatics.irida.repositories.ProjectRepository) Before(org.junit.Before) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Mockito.when(org.mockito.Mockito.when) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Mockito.verify(org.mockito.Mockito.verify) ConstraintViolationException(javax.validation.ConstraintViolationException) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) Assert.assertEquals(org.junit.Assert.assertEquals) 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) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) 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) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Test(org.junit.Test)

Example 20 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class UserGroupServiceImplIT method testCreateAndEditGroup.

@Test
@WithMockUser(username = "differentUser", roles = "USER")
public void testCreateAndEditGroup() {
    final UserGroup ug = new UserGroup("new group");
    final User u = userService.read(2L);
    final User u2 = userService.read(3L);
    userGroupService.create(ug);
    // now we should check that we're part of the group:
    final Collection<UserGroupJoin> groupUsers = userGroupService.getUsersForGroup(ug);
    assertTrue("Should be in the group after creating it.", groupUsers.stream().anyMatch(j -> j.getSubject().equals(u)));
    // and then also check that we can edit the group
    ug.setName("not new group");
    userGroupService.update(ug);
    // and add users to the group
    userGroupService.addUserToGroup(u2, ug, UserGroupRole.GROUP_MEMBER);
}
Also used : UserGroupWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) AnnotationConfigContextLoader(org.springframework.test.context.support.AnnotationConfigContextLoader) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) DependencyInjectionTestExecutionListener(org.springframework.test.context.support.DependencyInjectionTestExecutionListener) WithSecurityContextTestExcecutionListener(org.springframework.security.test.context.support.WithSecurityContextTestExcecutionListener) Collection(java.util.Collection) UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) Assert.assertTrue(org.junit.Assert.assertTrue) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) Test(org.junit.Test) IridaApiServicesConfig(ca.corefacility.bioinformatics.irida.config.services.IridaApiServicesConfig) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) UserGroupService(ca.corefacility.bioinformatics.irida.service.user.UserGroupService) DbUnitTestExecutionListener(com.github.springtestdbunit.DbUnitTestExecutionListener) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) ContextConfiguration(org.springframework.test.context.ContextConfiguration) User(ca.corefacility.bioinformatics.irida.model.user.User) IridaApiJdbcDataSourceConfig(ca.corefacility.bioinformatics.irida.config.data.IridaApiJdbcDataSourceConfig) WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)30 User (ca.corefacility.bioinformatics.irida.model.user.User)18 DTUserGroup (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup)12 UserGroupJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin)11 Test (org.junit.Test)10 Project (ca.corefacility.bioinformatics.irida.model.project.Project)9 UserGroupRole (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole)7 Authentication (org.springframework.security.core.Authentication)7 UserGroupWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException)6 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)5 ConstraintViolation (javax.validation.ConstraintViolation)5 ConstraintViolationException (javax.validation.ConstraintViolationException)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)5 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)5 WithMockUser (org.springframework.security.test.context.support.WithMockUser)5 DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)4 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)4