@GetMapping(GROUP_END_POINT + "/{groupName}/role") @ApiOperation(value = "Get group roles", response = Collection.class) @ResponseBody public Collection<RoleResponse> getGroupRoles( @PathVariable(value = "groupName") String groupName) { checkGroupPermission(groupName, VIEW); Iterable<Role> roles = groupService.getGroup(groupName).getRoles(); Collection<Role> roleCollection = new ArrayList<>(); roles.forEach(roleCollection::add); return roleCollection.stream().map(RoleResponse::fromEntity).collect(Collectors.toList()); }
@GetMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Get group members", response = Collection.class) @ResponseBody public Collection<GroupMemberResponse> getMembers( @PathVariable(value = "groupName") String groupName) { checkGroupPermission(groupName, VIEW_MEMBERSHIP); Iterable<Role> roles = groupService.getGroup(groupName).getRoles(); return roleMembershipService .getMemberships(Lists.newArrayList(roles)) .stream() .map(GroupMemberResponse::fromEntity) .collect(Collectors.toList()); }
@PutMapping(GROUP_MEMBER_END_POINT + "/{memberName}") @ApiOperation(value = "Change membership role", response = ResponseEntity.class) @Transactional @ResponseStatus(HttpStatus.OK) @ApiResponses({ @ApiResponse(code = 200, message = "Updated membership role", response = ResponseEntity.class) }) public void updateMember( @PathVariable(value = "groupName") String groupName, @PathVariable(value = "memberName") String memberName, @RequestBody UpdateGroupMemberCommand groupMember) { checkGroupPermission(groupName, UPDATE_MEMBERSHIP); final Group group = groupService.getGroup(groupName); final User member = userService.getUser(memberName); final Role newRole = roleService.getRole(groupMember.getRoleName()); groupService.updateMemberRole(group, member, newRole); }
@DeleteMapping(GROUP_MEMBER_END_POINT + "/{memberName}") @ApiOperation(value = "Remove member from group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 204, message = "Member removed from group", response = ResponseEntity.class) }) public ResponseEntity removeMember( @PathVariable(value = "groupName") String groupName, @PathVariable(value = "memberName") String memberName) { checkGroupPermission(groupName, REMOVE_MEMBERSHIP); final Group group = groupService.getGroup(groupName); final User member = userService.getUser(memberName); groupService.removeMember(group, member); return ResponseEntity.noContent().build(); }
@PostMapping(GROUP_MEMBER_END_POINT) @ApiOperation(value = "Add member to group", response = ResponseEntity.class) @Transactional @ApiResponses({ @ApiResponse(code = 201, message = "Member added to group", response = ResponseEntity.class) }) public ResponseEntity addMember( @PathVariable(value = "groupName") String groupName, @RequestBody AddGroupMemberCommand addMemberCommand) { checkGroupPermission(groupName, ADD_MEMBERSHIP); final Group group = groupService.getGroup(groupName); final String username = addMemberCommand.getUsername(); final String roleName = addMemberCommand.getRoleName(); final Role role = roleService.getRole(roleName); final User user = userService.getUser(username); groupService.addMember(group, user, role); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{group}/member/{member}") .buildAndExpand(groupName, username) .toUri(); return ResponseEntity.created(location).build(); }