RM-7062 fix for failing tests

This commit is contained in:
Sara Aspery
2019-12-20 02:20:13 +00:00
parent 105da8eecf
commit b35dcb14a3

View File

@@ -67,7 +67,6 @@ import org.alfresco.repo.audit.AuditComponent;
import org.alfresco.repo.audit.model.AuditApplication; import org.alfresco.repo.audit.model.AuditApplication;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
@@ -1871,31 +1870,13 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
return true; return true;
} }
// get hold nodeRef, if any, from audit event properties checkPermissionIfHoldInProperties(beforeProperties);
NodeRef holdNodeRef = beforeProperties != null ? (NodeRef) beforeProperties.get(PROPERTY_HOLD_NODEREF) : null; checkPermissionIfHoldInProperties(afterProperties);
if (holdNodeRef != null)
{
if (!AccessStatus.ALLOWED.equals(
permissionService.hasPermission(holdNodeRef, PermissionService.READ)))
{
beforeProperties.replace(PROPERTY_HOLD_NAME, I18NUtil.getMessage(HOLD_PERMISSION_DENIED_MSG));
}
// remove hold node ref from view
beforeProperties.remove(PROPERTY_HOLD_NODEREF);
} }
holdNodeRef = afterProperties != null ? (NodeRef) afterProperties.get(PROPERTY_HOLD_NODEREF) : null; // remove any hold node refs from view
if (holdNodeRef != null) removeHoldNodeRefIfPresent(beforeProperties);
{ removeHoldNodeRefIfPresent(afterProperties);
if (!AccessStatus.ALLOWED.equals(
permissionService.hasPermission(holdNodeRef, PermissionService.READ)))
{
afterProperties.replace(PROPERTY_HOLD_NAME, I18NUtil.getMessage(HOLD_PERMISSION_DENIED_MSG));
}
// remove hold node ref from view
afterProperties.remove(PROPERTY_HOLD_NODEREF);
}
}
// TODO: Refactor this to use the builder pattern // TODO: Refactor this to use the builder pattern
RecordsManagementAuditEntry entry = new RecordsManagementAuditEntry( RecordsManagementAuditEntry entry = new RecordsManagementAuditEntry(
@@ -1931,78 +1912,33 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
} }
/** /**
* Helper method to extract the hold name, if any, from the given event properties * Helper method to check permission on the hold, 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 * @param eventProperties event properties
*/ */
private void buildHoldNamesToHide(Map<String, Boolean> holdNamesToHide, Map<QName, Serializable> eventProperties) private void checkPermissionIfHoldInProperties(Map<QName, Serializable> eventProperties)
{ {
// get hold name, if any, from audit event properties NodeRef holdNodeRef = eventProperties != null ? (NodeRef) eventProperties.get(PROPERTY_HOLD_NODEREF) : null;
String holdName = eventProperties != null ? (String) eventProperties.get(PROPERTY_HOLD_NAME) : null; if (holdNodeRef != null)
if (holdName != null)
{ {
// assume hold name should be hidden if (!AccessStatus.ALLOWED.equals(
holdNamesToHide.putIfAbsent(holdName, true); permissionService.hasPermission(holdNodeRef, PermissionService.READ)))
{
eventProperties.replace(PROPERTY_HOLD_NAME, I18NUtil.getMessage(HOLD_PERMISSION_DENIED_MSG));
}
} }
} }
/** /**
* Helper method to get the file plan * Helper method to remove the hold node ref, if any, from the given event properties
* @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<NodeRef> 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 * @param eventProperties event properties
* @param holdNamesToHide map of hold names and their hide name status
* @param replacementText text to replace hidden hold name
*/ */
private void replaceHoldNameIfRequired(Map<QName, Serializable> eventProperties, private void removeHoldNodeRefIfPresent(Map<QName, Serializable> eventProperties)
Map<String, Boolean> holdNamesToHide, String replacementText)
{ {
// get hold name, if any, from audit event properties if (eventProperties != null)
String holdName = eventProperties != null ? (String) eventProperties.get(PROPERTY_HOLD_NAME) : null;
if (holdName != null)
{ {
if (holdNamesToHide.get(holdName)) eventProperties.remove(PROPERTY_HOLD_NODEREF);
{
eventProperties.replace(PROPERTY_HOLD_NAME, replacementText);
} }
} }
}
/**
* 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(NodeRef filePlan, String holdName)
{
return AuthenticationUtil.runAsSystem(() -> {
//NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
return holdService.getHold(filePlan, holdName);
});
}
/** /**
* Helper method to write the audit entry to file * Helper method to write the audit entry to file