From 2c3a3e3726352481ffbbea0a99abfc82b5728fb2 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Tue, 17 Dec 2019 08:37:15 +0000 Subject: [PATCH] RM-7062 fix integration tests --- .../RecordsManagementAuditServiceImpl.java | 74 ++++++++++++++++--- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java index f78f5f2f8b..dbf57693e6 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java @@ -1871,10 +1871,29 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean } else { - // must have read permission on hold to see hold name in event + // find any hold names in event properties Map holdNamesToHide = new HashMap<>(2); - replaceHoldNameIfRequired(beforeProperties, holdNamesToHide, I18NUtil.getMessage(HOLD_PERMISSION_DENIED_MSG)); - replaceHoldNameIfRequired(afterProperties, holdNamesToHide, I18NUtil.getMessage(HOLD_PERMISSION_DENIED_MSG)); + buildHoldNamesToHide(holdNamesToHide, beforeProperties); + buildHoldNamesToHide(holdNamesToHide, afterProperties); + + // if audit event contains any hold names, check if any hold name should be hidden + if (!holdNamesToHide.isEmpty()) + { + // get file plan + NodeRef filePlan = getFilePlan(nodeRef); + + // check permissions for each hold name + for (String holdName : holdNamesToHide.keySet()) + { + boolean hideHoldName = !AccessStatus.ALLOWED.equals( + permissionService.hasPermission(getHold(filePlan, holdName), PermissionService.READ)); + holdNamesToHide.replace(holdName, hideHoldName); + } + + // hide hold names, if required, in event properties + replaceHoldNameIfRequired(beforeProperties, holdNamesToHide, I18NUtil.getMessage(HOLD_PERMISSION_DENIED_MSG)); + replaceHoldNameIfRequired(afterProperties, holdNamesToHide, I18NUtil.getMessage(HOLD_PERMISSION_DENIED_MSG)); + } } } @@ -1911,6 +1930,46 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean return true; } + /** + * Helper method to extract the hold name, if any, from the given event properties + * @param holdNamesToHide map of hold names and their hide name status. True if hold name is to be hidden. + * @param eventProperties event properties + */ + private void buildHoldNamesToHide(Map holdNamesToHide, Map eventProperties) + { + // get hold name, if any, from audit event properties + String holdName = eventProperties != null ? (String) eventProperties.get(PROPERTY_HOLD_NAME) : null; + if (holdName != null) + { + // assume hold name should be hidden + holdNamesToHide.putIfAbsent(holdName, true); + } + } + + /** + * Helper method to get the file plan + * @param nodeRef node ref for which to get file plan + * @return node ref of file plan + */ + private NodeRef getFilePlan(NodeRef nodeRef) + { + NodeRef filePlan = filePlanService.getFilePlan(nodeRef); + if (filePlan == null) + { + Set filePlans = filePlanService.getFilePlans(); + if (filePlans != null && !filePlans.isEmpty()) + { + filePlan = filePlans.iterator().next(); + } + + if (filePlan == null) + { + filePlan = getDefaultFilePlan(); + } + } + return filePlan; + } + /** * Helper method to replace the hold name, if required, in the given event properties * @param eventProperties event properties @@ -1924,10 +1983,6 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean String holdName = eventProperties != null ? (String) eventProperties.get(PROPERTY_HOLD_NAME) : null; if (holdName != null) { - holdNamesToHide.putIfAbsent(holdName, - !AccessStatus.ALLOWED.equals(permissionService.hasPermission(getHold(holdName), - PermissionService.READ))); - if (holdNamesToHide.get(holdName)) { eventProperties.replace(PROPERTY_HOLD_NAME, replacementText); @@ -1937,13 +1992,14 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean /** * Helper method to get the hold for a given hold name + * @param filePlan file plan * @param holdName hold name * @return node ref of hold */ - private NodeRef getHold(String holdName) + private NodeRef getHold(NodeRef filePlan, String holdName) { return AuthenticationUtil.runAsSystem(() -> { - NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID); + //NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID); return holdService.getHold(filePlan, holdName); }); }