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