use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class GroupMemberResource method addMember.
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add a group member", notes = "User must have the ORGANIZATION_GROUP[UPDATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 200, message = "Member has been added successfully"), @ApiResponse(code = 400, message = "User does not exist"), @ApiResponse(code = 500, message = "Internal server error") })
public void addMember(@PathParam("organizationId") String organizationId, @PathParam("group") String group, @PathParam("member") String userId, @Suspended final AsyncResponse response) {
final io.gravitee.am.identityprovider.api.User authenticatedUser = getAuthenticatedUser();
checkPermission(ReferenceType.ORGANIZATION, organizationId, Permission.ORGANIZATION_GROUP, Acl.UPDATE).andThen(groupService.findById(ReferenceType.ORGANIZATION, organizationId, group).flatMap(group1 -> userService.findById(ReferenceType.ORGANIZATION, organizationId, userId).flatMap(user -> {
if (group1.getMembers() != null && group1.getMembers().contains(userId)) {
return Single.error(new MemberAlreadyExistsException(userId));
}
List<String> groupMembers = group1.getMembers() != null ? new ArrayList(group1.getMembers()) : new ArrayList();
groupMembers.add(userId);
UpdateGroup updateGroup = new UpdateGroup();
updateGroup.setName(group1.getName());
updateGroup.setDescription(group1.getDescription());
updateGroup.setRoles(group1.getRoles());
updateGroup.setMembers(groupMembers);
return groupService.update(ReferenceType.ORGANIZATION, organizationId, group, updateGroup, authenticatedUser);
}))).subscribe(response::resume, response::resume);
}
Aggregations