use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class ProjectMembersController method addProjectGroupMember.
/**
* Add a group to a project
*
* @param projectId
* The ID of the project
* @param memberId
* The ID of the user
* @param projectRole
* The role for the user on the project
* @param locale
* the reported locale of the browser
* @return map for showing success message.
*/
@RequestMapping(value = "/{projectId}/settings/groups", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> addProjectGroupMember(@PathVariable Long projectId, @RequestParam Long memberId, @RequestParam String projectRole, Locale locale) {
logger.trace("Adding user " + memberId + " to project " + projectId);
final Project project = projectService.read(projectId);
final UserGroup userGroup = userGroupService.read(memberId);
final ProjectRole role = ProjectRole.fromString(projectRole);
projectService.addUserGroupToProject(project, userGroup, role);
return ImmutableMap.of("result", messageSource.getMessage("project.members.add.success", new Object[] { userGroup.getLabel(), project.getLabel() }, locale));
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class ProjectMembersController method removeUserGroup.
/**
* Remove a user group from a project
*
* @param projectId The project to remove from
* @param userId The user to remove
* @param locale Locale of the logged in user
* @return Success or error message
*/
@RequestMapping(path = "{projectId}/settings/groups/{userId}", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> removeUserGroup(@PathVariable final Long projectId, @PathVariable final Long userId, final Locale locale) {
final Project project = projectService.read(projectId);
final UserGroup userGroup = userGroupService.read(userId);
try {
projectService.removeUserGroupFromProject(project, userGroup);
return ImmutableMap.of("success", messageSource.getMessage("project.members.edit.remove.success", new Object[] { userGroup.getLabel() }, locale));
} catch (final ProjectWithoutOwnerException e) {
return ImmutableMap.of("failure", messageSource.getMessage("project.members.edit.remove.nomanager", new Object[] { userGroup.getLabel() }, locale));
}
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class UpdateUserGroupPermission method customPermissionAllowed.
/**
* {@inheritDoc}
*/
@Override
public boolean customPermissionAllowed(final Authentication authentication, final UserGroup g) {
logger.trace("Checking if [" + authentication + "] can modify [" + g + "]");
final User user = userRepository.loadUserByUsername(authentication.getName());
final Optional<UserGroupJoin> userInGroup = userGroupJoinRepository.findUsersInGroup(g).stream().filter(j -> j.getSubject().equals(user)).findAny();
if (userInGroup.isPresent()) {
final UserGroupJoin j = userInGroup.get();
if (j.getRole().equals(UserGroupRole.GROUP_OWNER)) {
logger.trace("User [" + user + "] is GROUP_OWNER in group [" + g + "], access is GRANTED.");
return true;
} else {
logger.trace("User [" + user + "] is *not* GROUP_OWNER in group [" + g + "], access is DENIED.");
return false;
}
} else {
logger.trace("User [" + user + "] is not in group [" + g + "], access is DENIED.");
return false;
}
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class UserGroupServiceImplIT method testRemoveUserFromGroupNoOwner.
@Test(expected = UserGroupWithoutOwnerException.class)
@WithMockUser(username = "differentUser", roles = "USER")
public void testRemoveUserFromGroupNoOwner() throws UserGroupWithoutOwnerException {
final UserGroup ug = userGroupService.read(1L);
final User u = userService.read(2L);
userGroupService.removeUserFromGroup(u, ug);
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class UserGroupServiceImplIT method testChangeRoleUserFromGroupNoOwner.
@Test(expected = UserGroupWithoutOwnerException.class)
@WithMockUser(username = "differentUser", roles = "USER")
public void testChangeRoleUserFromGroupNoOwner() throws UserGroupWithoutOwnerException {
final UserGroup ug = userGroupService.read(1L);
final User u = userService.read(2L);
userGroupService.changeUserGroupRole(u, ug, UserGroupRole.GROUP_MEMBER);
}
Aggregations