Add an endpoint filtering the elements a user can access - #267
Conversation
The existing /elements/authorized answers all-or-nothing: a single forbidden element denies the whole request. Resolving the permissions of several independent elements therefore took one call each. The new /elements/permission returns which of the given elements the user may access, leaving out the forbidden and the unknown ones. The user groups are resolved once for the whole batch instead of once per element. Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| @GetMapping(value = "/elements/permission", produces = MediaType.APPLICATION_JSON_VALUE) |
There was a problem hiding this comment.
@GetMapping(value = "/elements/accessible", produces = MediaType.APPLICATION_JSON_VALUE)
| } | ||
|
|
||
| @GetMapping(value = "/elements/permission", produces = MediaType.APPLICATION_JSON_VALUE) | ||
| @Operation(summary = "Get, among the given elements, the ones the user can access with the given permission") |
There was a problem hiding this comment.
Filter the given elements to the ones the user has the given permission on
| @GetMapping(value = "/elements/permission", produces = MediaType.APPLICATION_JSON_VALUE) | ||
| @Operation(summary = "Get, among the given elements, the ones the user can access with the given permission") | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "200", description = "The uuids of the accessible elements"), |
There was a problem hiding this comment.
The uuids of the given elements the user has the permission on
| return hasElementPermission(userId, uuid, permissionType, () -> getUserGroupIds(userId)); | ||
| } | ||
|
|
||
| private boolean hasElementPermission(String userId, UUID uuid, PermissionType permissionType, Supplier<List<UUID>> userGroupIds) { |
|
|
||
| //Finally check group permission | ||
| return userAdminService.getUserGroups(userId) | ||
| return userGroupIds.get() |
There was a problem hiding this comment.
userGroupIdsSupplier.get()



The user groups are now resolved once for the whole batch rather than once per element. The unitary path is unchanged.
Consumed by gridsuite/explore-server#209.