Search in sources :

Example 26 with UserGroup

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

the class GroupsController method editGroup.

/**
 * Submit changes to the {@link UserGroup}.
 *
 * @param userGroupId
 *            the group ID to edit.
 * @param name
 *            the new name of the group.
 * @param description
 *            the new description of the group.
 * @param principal
 *            the currently logged in user.
 * @param model
 *            the model to add attributes to.
 * @param locale
 *            the locale of the browser.
 * @return the route to the editing page on validation failure, or the
 *         details page on success.
 */
@RequestMapping(path = "/{userGroupId}/edit", method = RequestMethod.POST)
public String editGroup(@PathVariable final Long userGroupId, @RequestParam final String name, @RequestParam final String description, final Principal principal, final Model model, final Locale locale) {
    logger.debug("Editing group: [" + userGroupId + "]");
    final Map<String, String> errors = new HashMap<>();
    UserGroup group = userGroupService.read(userGroupId);
    try {
        group.setName(name);
        group.setDescription(description);
        userGroupService.update(group);
        return getDetailsPage(userGroupId, principal, model);
    } catch (final ConstraintViolationException e) {
        for (final ConstraintViolation<?> v : e.getConstraintViolations()) {
            errors.put(v.getPropertyPath().toString(), v.getMessage());
        }
    } catch (final EntityExistsException | DataIntegrityViolationException e) {
        errors.put("name", messageSource.getMessage("group.name.exists", null, locale));
    }
    model.addAttribute("errors", errors);
    model.addAttribute("group", userGroupService.read(userGroupId));
    model.addAttribute("given_name", name);
    model.addAttribute("given_description", description);
    return GROUPS_EDIT;
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 27 with UserGroup

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

the class GroupsController method getDeleteGroupText.

/**
 * Get a string to tell the user which group they're going to delete.
 *
 * @param userGroupId
 *            the user group that's about to be deleted.
 * @param model
 *            model for rendering view
 * @return a message indicating which group is going to be deleted.
 */
@RequestMapping(path = "/deleteConfirmModal", method = RequestMethod.POST)
public String getDeleteGroupText(@RequestParam final Long userGroupId, final Model model) {
    final UserGroup group = userGroupService.read(userGroupId);
    model.addAttribute("group", group);
    return GROUPS_REMOVE_MODAL;
}
Also used : DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 28 with UserGroup

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

the class GroupsController method getUsersNotInGroup.

/**
 * Get a list of the users that are not currently members of this group.
 *
 * @param userGroupId
 *            the group ID to use as a negative filter.
 * @param term
 *            a filter on username to filter on.
 * @return the collection of users that match the query.
 */
@RequestMapping("/{userGroupId}/ajax/availablemembers")
@ResponseBody
public Collection<User> getUsersNotInGroup(@PathVariable final Long userGroupId, @RequestParam final String term) {
    final UserGroup group = userGroupService.read(userGroupId);
    logger.debug("Loading users not in group [" + userGroupId + "]");
    final Collection<User> usersNotInGroup = userGroupService.getUsersNotInGroup(group);
    return usersNotInGroup.stream().filter(u -> u.getLabel().toLowerCase().contains(term)).collect(Collectors.toList());
}
Also used : UserGroupWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException) java.util(java.util) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroupSpecification(ca.corefacility.bioinformatics.irida.repositories.specification.UserGroupSpecification) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) Model(org.springframework.ui.Model) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ImmutableList(com.google.common.collect.ImmutableList) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) ConstraintViolation(javax.validation.ConstraintViolation) DTGroupMember(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTGroupMember) MessageSource(org.springframework.context.MessageSource) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Role(ca.corefacility.bioinformatics.irida.model.user.Role) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) PageRequest(org.springframework.data.domain.PageRequest) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) UserGroupService(ca.corefacility.bioinformatics.irida.service.user.UserGroupService) Principal(java.security.Principal) ConstraintViolationException(javax.validation.ConstraintViolationException) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(ca.corefacility.bioinformatics.irida.model.user.User) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) 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 29 with UserGroup

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

the class GroupsController method getGroups.

/**
 * Search/filter/page with datatables for {@link UserGroup}.
 * @param params {@link DataTablesParams} for the current DataTable
 * @param principal Currently logged in user
 * @return {@link DataTablesResponse} for the current table base on the parameters.
 */
@RequestMapping("/ajax/list")
@ResponseBody
public DataTablesResponse getGroups(@DataTablesRequest final DataTablesParams params, final Principal principal) {
    Page<UserGroup> groups = userGroupService.search(UserGroupSpecification.searchUserGroup(params.getSearchValue()), new PageRequest(params.getCurrentPage(), params.getLength(), params.getSort()));
    User currentUser = userService.getUserByUsername(principal.getName());
    List<DataTablesResponseModel> groupsWithOwnership = groups.getContent().stream().map(ug -> new DTUserGroup(ug, isGroupOwner(currentUser, ug), currentUser.getSystemRole().equals(Role.ROLE_ADMIN))).collect(Collectors.toList());
    return new DataTablesResponse(params, groups, groupsWithOwnership);
}
Also used : UserGroupWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException) java.util(java.util) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroupSpecification(ca.corefacility.bioinformatics.irida.repositories.specification.UserGroupSpecification) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) Model(org.springframework.ui.Model) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ImmutableList(com.google.common.collect.ImmutableList) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) ConstraintViolation(javax.validation.ConstraintViolation) DTGroupMember(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTGroupMember) MessageSource(org.springframework.context.MessageSource) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Role(ca.corefacility.bioinformatics.irida.model.user.Role) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) PageRequest(org.springframework.data.domain.PageRequest) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) UserGroupService(ca.corefacility.bioinformatics.irida.service.user.UserGroupService) Principal(java.security.Principal) ConstraintViolationException(javax.validation.ConstraintViolationException) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(ca.corefacility.bioinformatics.irida.model.user.User) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) PageRequest(org.springframework.data.domain.PageRequest) User(ca.corefacility.bioinformatics.irida.model.user.User) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) 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 30 with UserGroup

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

the class GroupsController method deleteGroup.

/**
 * Delete the specified {@link UserGroup}.
 *
 * @param userGroupId
 *            the group to delete.
 * @param locale
 *            the locale of the browser
 * @return a message indicating success.
 */
@RequestMapping(path = "/{userGroupId}", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> deleteGroup(@PathVariable final Long userGroupId, final Locale locale) {
    final UserGroup userGroup = userGroupService.read(userGroupId);
    userGroupService.delete(userGroupId);
    return ImmutableMap.of("result", messageSource.getMessage("group.remove.notification.success", new Object[] { userGroup.getName() }, locale));
}
Also used : DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) 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