Freedom9339 commented on code in PR #8965:
URL: https://github.com/apache/nifi/pull/8965#discussion_r1975691467


##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerServiceResource.java:
##########
@@ -664,6 +668,206 @@ public Response updateControllerService(
         );
     }
 
+    @GET
+    @Consumes(MediaType.WILDCARD)
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("{id}/move-options")
+    @Operation(
+            summary = "Gets the move options for a controller service",
+            responses = {
+                    @ApiResponse(content = @Content(schema = 
@Schema(implementation = ProcessGroupOptionEntity.class))),
+                    @ApiResponse(responseCode = "400", description = "NiFi was 
unable to complete the request because it was invalid. The request should not 
be retried without modification."),
+                    @ApiResponse(responseCode = "401", description = "Client 
could not be authenticated."),
+                    @ApiResponse(responseCode = "403", description = "Client 
is not authorized to make this request."),
+                    @ApiResponse(responseCode = "404", description = "The 
specified resource could not be found."),
+                    @ApiResponse(responseCode = "409", description = "The 
request was valid but NiFi was not in the appropriate state to process it.")
+            },
+            security = {
+                    @SecurityRequirement(name = "Read - /flow")
+            }
+    )
+    public Response getProcessGroupOptions(
+            @Parameter(description = "The controller service id.")
+            @PathParam("id") final String controllerServiceId) {
+
+        if (controllerServiceId == null) {
+            throw new IllegalArgumentException("Controller service id must be 
specified.");
+        }
+
+        List<ProcessGroupOptionEntity> options = new ArrayList<>();
+        serviceFacade.authorizeAccess(lookup -> {
+            final NiFiUser user = NiFiUserUtils.getNiFiUser();
+
+            final ComponentAuthorizable authorizableControllerService = 
lookup.getControllerService(controllerServiceId);
+            boolean authorized = 
authorizableControllerService.getAuthorizable().isAuthorized(authorizer, 
RequestAction.WRITE, user);
+
+            final ControllerServiceDTO controllerServiceDTO = 
serviceFacade.getControllerService(controllerServiceId, true).getComponent();
+
+            final ProcessGroupAuthorizable authorizableProcessGroupCurrent = 
lookup.getProcessGroup(controllerServiceDTO.getParentGroupId());
+            authorized = authorized && 
authorizableProcessGroupCurrent.getAuthorizable().isAuthorized(authorizer, 
RequestAction.WRITE, user);
+
+            if (authorized) {
+                if 
(authorizableProcessGroupCurrent.getProcessGroup().getParent() != null) {
+                    final ProcessGroupAuthorizable 
authorizableProcessGroupParent = 
lookup.getProcessGroup(authorizableProcessGroupCurrent.getProcessGroup().getParent().getIdentifier());
+                    if 
(authorizableProcessGroupParent.getAuthorizable().isAuthorized(authorizer, 
RequestAction.READ, user)
+                            && 
authorizableProcessGroupParent.getAuthorizable().isAuthorized(authorizer, 
RequestAction.WRITE, user)) {
+                        
options.add(generateProcessGroupOption(controllerServiceDTO, 
authorizableProcessGroupParent, lookup, user));
+                    }
+                }
+
+                
authorizableProcessGroupCurrent.getProcessGroup().getProcessGroups().forEach(processGroup
 -> {
+                    final ProcessGroupAuthorizable authorizableProcessGroup = 
lookup.getProcessGroup(processGroup.getIdentifier());
+                    if 
(authorizableProcessGroup.getAuthorizable().isAuthorized(authorizer, 
RequestAction.READ, user)
+                            && 
authorizableProcessGroup.getAuthorizable().isAuthorized(authorizer, 
RequestAction.WRITE, user)) {
+                        
options.add(generateProcessGroupOption(controllerServiceDTO, 
authorizableProcessGroup, lookup, user));
+                    }
+                });

Review Comment:
   I've added "(Parent)" to the end of the parent process group and added a 
divider between the parent and child options.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to