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)));
}
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);
}
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);
}
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);
}
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);
}
Aggregations