Search in sources :

Example 1 with UserGroup

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

the class GroupsController method updateUserRole.

/**
 * Update a user's role on a group
 *
 * @param groupId
 *            The ID of the group
 * @param userId
 *            The ID of the user
 * @param groupRole
 *            The role to set
 * @param locale
 *            Locale of the logged in user
 *
 * @return message indicating update result
 */
@RequestMapping(path = "/{groupId}/members/editrole/{userId}", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateUserRole(@PathVariable final Long groupId, @PathVariable final Long userId, @RequestParam final String groupRole, final Locale locale) {
    final UserGroup group = userGroupService.read(groupId);
    final User user = userService.read(userId);
    final UserGroupRole userGroupRole = UserGroupRole.fromString(groupRole);
    final String roleName = messageSource.getMessage("group.users.role." + groupRole, new Object[] {}, locale);
    try {
        userGroupService.changeUserGroupRole(user, group, userGroupRole);
        return ImmutableMap.of("success", messageSource.getMessage("group.members.edit.role.success", new Object[] { user.getLabel(), roleName }, locale));
    } catch (final UserGroupWithoutOwnerException e) {
        return ImmutableMap.of("failure", messageSource.getMessage("group.members.edit.role.failure", new Object[] { user.getLabel(), roleName }, locale));
    }
}
Also used : UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 2 with UserGroup

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

the class GroupsController method getGroupUsers.

/**
 * List the members in the group.
 *
 * @param params
 *            the datatables parameters to search for.
 * @param userGroupId
 *            the group ID to get members for.
 * @return the datatables-formatted response with filtered users.
 */
@RequestMapping("/{userGroupId}/ajax/list")
@ResponseBody
public DataTablesResponse getGroupUsers(@DataTablesRequest DataTablesParams params, @PathVariable Long userGroupId) {
    final UserGroup group = userGroupService.read(userGroupId);
    final Page<UserGroupJoin> page = userGroupService.filterUsersByUsername(params.getSearchValue(), group, params.getCurrentPage(), params.getLength(), params.getSort());
    List<DataTablesResponseModel> members = page.getContent().stream().map(DTGroupMember::new).collect(Collectors.toList());
    return new DataTablesResponse(params, page, members);
}
Also used : DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 3 with UserGroup

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

the class GroupsController method addUserToGroup.

/**
 * Add a new user to the group.
 *
 * @param userGroupId
 *            the group to add to.
 * @param userId
 *            the new member.
 * @param groupRole
 *            the role this user should have.
 * @param locale
 *            the locale of the browser.
 * @return a message indicating success.
 */
@RequestMapping(path = "/{userGroupId}/members", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> addUserToGroup(@PathVariable final Long userGroupId, @RequestParam final Long userId, @RequestParam String groupRole, Locale locale) {
    final User user = userService.read(userId);
    final UserGroup group = userGroupService.read(userGroupId);
    final UserGroupRole role = UserGroupRole.valueOf(groupRole);
    userGroupService.addUserToGroup(user, group, role);
    return ImmutableMap.of("result", messageSource.getMessage("group.users.add.notification.success", new Object[] { user.getLabel() }, locale));
}
Also used : UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) User(ca.corefacility.bioinformatics.irida.model.user.User) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 4 with UserGroup

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

the class GroupsController method getEditPage.

/**
 * Get the group editing page.
 *
 * @param userGroupId
 *            the group id to edit.
 * @param model
 *            the model to write attributes to.
 * @return the route to the editing page.
 */
@RequestMapping(path = "/{userGroupId}/edit")
public String getEditPage(@PathVariable final Long userGroupId, final Model model) {
    final UserGroup group = userGroupService.read(userGroupId);
    model.addAttribute("group", group);
    model.addAttribute("given_name", group.getName());
    model.addAttribute("given_description", group.getDescription());
    return GROUPS_EDIT;
}
Also used : DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 5 with UserGroup

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

the class ProjectMembersController method getRemoveUserGroupModal.

/**
 * Get a string to tell the user which group they're going to delete.
 *
 * @param memberId
 *            the user group that's about to be deleted.
 * @param model
 *            Model for rendering the view
 * @return Name of the user group removal modal
 */
@RequestMapping(path = "/settings/removeUserGroupModal", method = RequestMethod.POST)
public String getRemoveUserGroupModal(@RequestParam final Long memberId, final Model model) {
    final UserGroup userGroup = userGroupService.read(memberId);
    model.addAttribute("member", userGroup);
    return REMOVE_USER_MODAL;
}
Also used : UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

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