Search in sources :

Example 1 with EnvironmentPermission

use of io.gravitee.rest.api.model.permissions.EnvironmentPermission in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentResource method getEnvironmentPermissions.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/permissions")
@ApiOperation(value = "Get permissions on environment")
@ApiResponses({ @ApiResponse(code = 200, message = "Current user permissions on environement", response = char[].class, responseContainer = "Map"), @ApiResponse(code = 500, message = "Internal server error") })
public Response getEnvironmentPermissions() {
    Map<String, char[]> permissions = new HashMap<>();
    if (isAuthenticated()) {
        final String username = getAuthenticatedUser();
        final EnvironmentEntity environmentEntity = environmentService.findById(envId);
        if (isAdmin()) {
            final char[] rights = new char[] { CREATE.getId(), READ.getId(), UPDATE.getId(), DELETE.getId() };
            for (EnvironmentPermission perm : EnvironmentPermission.values()) {
                permissions.put(perm.getName(), rights);
            }
        } else {
            permissions = membershipService.getUserMemberPermissions(environmentEntity, username);
        }
    }
    return Response.ok(permissions).build();
}
Also used : HashMap(java.util.HashMap) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) EnvironmentPermission(io.gravitee.rest.api.model.permissions.EnvironmentPermission)

Aggregations

EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)1 EnvironmentPermission (io.gravitee.rest.api.model.permissions.EnvironmentPermission)1 HashMap (java.util.HashMap)1