From c093ea54b77c816d94a23c7af19f97f96baa7d2f Mon Sep 17 00:00:00 2001 From: tpalfy Date: Tue, 5 Mar 2024 17:48:08 +0100 Subject: [PATCH] NIFI-12862 When building FlowAnalysisRuleViolationDTO objects (in StandardNiFiServiceFacade), violating component details will be left blank when user has no read permission for that component. NIFI-12862 Expose subjectComponentType to frontend. Signed-off-by: Pierre Villard This closes #8475. --- .../api/dto/FlowAnalysisRuleViolationDTO.java | 13 ++++++++++ .../nifi/web/StandardNiFiServiceFacade.java | 26 ++++++++++++------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowAnalysisRuleViolationDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowAnalysisRuleViolationDTO.java index 4e1762f42a..0201a0dc24 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowAnalysisRuleViolationDTO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowAnalysisRuleViolationDTO.java @@ -35,6 +35,8 @@ public class FlowAnalysisRuleViolationDTO { private String issueId; private String violationMessage; + private String subjectComponentType; + private PermissionsDTO subjectPermissionDto; private boolean enabled; @@ -129,6 +131,17 @@ public class FlowAnalysisRuleViolationDTO { } + /** + * @return the type of the subject that violated the rule + */ + public String getSubjectComponentType() { + return subjectComponentType; + } + + public void setSubjectComponentType(String subjectComponentType) { + this.subjectComponentType = subjectComponentType; + } + /** * @return true if this result should be in effect, false otherwise */ diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java index 78dbc4caa3..96ec627f61 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java @@ -6478,23 +6478,29 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { .map(ruleViolation -> { FlowAnalysisRuleViolationDTO ruleViolationDto = new FlowAnalysisRuleViolationDTO(); - ruleViolationDto.setEnforcementPolicy(ruleViolation.getEnforcementPolicy().toString()); - ruleViolationDto.setScope(ruleViolation.getScope()); - ruleViolationDto.setRuleId(ruleViolation.getRuleId()); - ruleViolationDto.setIssueId(ruleViolation.getIssueId()); - ruleViolationDto.setViolationMessage(ruleViolation.getViolationMessage()); - String subjectId = ruleViolation.getSubjectId(); String groupId = ruleViolation.getGroupId(); + ruleViolationDto.setScope(ruleViolation.getScope()); ruleViolationDto.setSubjectId(subjectId); - ruleViolationDto.setGroupId(groupId); - ruleViolationDto.setSubjectDisplayName(ruleViolation.getSubjectDisplayName()); - ruleViolationDto.setSubjectPermissionDto(createPermissionDto( + ruleViolationDto.setRuleId(ruleViolation.getRuleId()); + ruleViolationDto.setIssueId(ruleViolation.getIssueId()); + + ruleViolationDto.setSubjectComponentType(ruleViolation.getSubjectComponentType().name()); + ruleViolationDto.setEnforcementPolicy(ruleViolation.getEnforcementPolicy().toString()); + + PermissionsDTO subjectPermissionDto = createPermissionDto( subjectId, ruleViolation.getSubjectComponentType(), groupId - )); + ); + ruleViolationDto.setSubjectPermissionDto(subjectPermissionDto); + + if (subjectPermissionDto.getCanRead()) { + ruleViolationDto.setGroupId(groupId); + ruleViolationDto.setSubjectDisplayName(ruleViolation.getSubjectDisplayName()); + ruleViolationDto.setViolationMessage(ruleViolation.getViolationMessage()); + } return ruleViolationDto; })