use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class UsersControllerTest method testGetUserSpecificPage.
@SuppressWarnings("rawtypes")
@Test
public void testGetUserSpecificPage() {
Principal principal = () -> USER_NAME;
Long userId = 1L;
String roleString = "User";
ExtendedModelMap model = new ExtendedModelMap();
User user = new User(userId, USER_NAME, 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(user);
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(user, model.get("user"));
assertEquals(roleString, model.get("systemRole"));
assertEquals(true, model.get("canEditUser"));
assertEquals(joins.size(), ((List) model.get("projects")).size());
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 ProjectServiceImpl method removeUserFromProject.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@LaunchesProjectEvent(UserRemovedProjectEvent.class)
@PreAuthorize("hasPermission(#project, 'canManageLocalProjectSettings')")
public void removeUserFromProject(Project project, User user) throws ProjectWithoutOwnerException {
ProjectUserJoin projectJoinForUser = pujRepository.getProjectJoinForUser(project, user);
if (!allowRoleChange(projectJoinForUser.getSubject(), projectJoinForUser.getProjectRole())) {
throw new ProjectWithoutOwnerException("Removing this user would leave the project without an owner");
}
pujRepository.delete(projectJoinForUser);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectEventHandlerTest method testDelegateUserRole.
@Test
public void testDelegateUserRole() {
Class<? extends ProjectEvent> clazz = UserRoleSetProjectEvent.class;
Project project = new Project();
User user = new User();
ProjectUserJoin returnValue = new ProjectUserJoin(project, user, ProjectRole.PROJECT_USER);
Object[] args = { project, user, ProjectRole.PROJECT_USER };
MethodEvent methodEvent = new MethodEvent(clazz, returnValue, args);
when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new UserRoleSetProjectEvent(returnValue));
handler.delegate(methodEvent);
ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
verify(eventRepository).save(captor.capture());
ProjectEvent event = captor.getValue();
assertTrue(event instanceof UserRoleSetProjectEvent);
verify(projectRepository).save(any(Project.class));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectTestUtils method getUsersForProject.
public Collection<Join<Project, User>> getUsersForProject(Project project) {
Collection<Join<Project, User>> users = new ArrayList<>();
users.add(new ProjectUserJoin(project, new User("tester1", "test@me.com", "", "Test", "Test2", "234234"), ProjectRole.PROJECT_USER));
users.add(new ProjectUserJoin(project, new User("tester2", "test@me.com", "", "Test", "Test23", "213231"), ProjectRole.PROJECT_OWNER));
return users;
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectTestUtils method mockSidebarInfo.
/**
* Mocks the information found within the project sidebar.
*/
public void mockSidebarInfo() {
Project project = getProject();
Collection<Join<Project, User>> ownerList = new ArrayList<>();
ownerList.add(new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER));
when(userService.getUsersForProjectByRole(any(Project.class), any(ProjectRole.class))).thenReturn(ownerList);
when(projectService.read(PROJECT_ID)).thenReturn(project);
when(userService.getUserByUsername(anyString())).thenReturn(user);
}
Aggregations