diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-audit-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-audit-context.xml index 0d0d0f2457..1a1b993d1a 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-audit-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-audit-context.xml @@ -59,7 +59,6 @@ - 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 812d2e7a3c..69d7631997 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 @@ -1516,12 +1516,11 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean } else if (entry.getEvent().equals("Delete Person") && entry.getNodeRef() != null) { - String userName = null; if (entry.getBeforeProperties() != null) { - userName = (String) entry.getBeforeProperties().get(ContentModel.PROP_USERNAME); + String userName = (String) entry.getBeforeProperties().get(ContentModel.PROP_USERNAME); + json.put("nodeName", userName == null ? "" : userName); } - json.put("nodeName", userName == null ? "" : userName); json.put("deletePerson", true); } else diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/DeletePersonAuditEvent.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/DeletePersonAuditEvent.java index 33e73d335b..9d92e9e41b 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/DeletePersonAuditEvent.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/DeletePersonAuditEvent.java @@ -29,14 +29,12 @@ package org.alfresco.module.org_alfresco_module_rm.audit.event; import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import java.util.Set; import org.alfresco.model.ContentModel; import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy; import org.alfresco.repo.policy.annotation.Behaviour; import org.alfresco.repo.policy.annotation.BehaviourBean; import org.alfresco.repo.policy.annotation.BehaviourKind; -import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.namespace.QName; @@ -50,25 +48,24 @@ import org.alfresco.service.namespace.QName; @BehaviourBean public class DeletePersonAuditEvent extends AuditEvent implements BeforeDeleteNodePolicy { - + /** Node Service*/ private NodeService nodeService; - private DictionaryService dictionaryService; - + /** + * Sets the node service + * + * @param nodeService nodeService to set + */ public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } - public void setDictionaryService(DictionaryService dictionaryService) - { - this.dictionaryService = dictionaryService; - } - /** - * @see org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy#(org.alfresco.service.cmr.repository.ChildAssociationRef) + * Behaviour that will audit cm:person type when the user is deletedF + * @param nodeRef the node to be deleted + * */ - @Override @Behaviour ( @@ -77,21 +74,12 @@ public class DeletePersonAuditEvent extends AuditEvent implements BeforeDeleteNo ) public void beforeDeleteNode(NodeRef nodeRef) { - //get the cm:person properties - Set properties = dictionaryService.getPropertyDefs(ContentModel.TYPE_PERSON).keySet(); - //retrive the properties and the values - Map result = new HashMap<>(); - for (QName property : properties) - { - Serializable values = nodeService.getProperty(nodeRef, property); - if (values != null) - { - result.put(property, values); - } - } + //retrieve the username property to be audited + Map userName = new HashMap<>(); + userName.put(ContentModel.PROP_USERNAME, nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME)); //audit the property values before the delete event - recordsManagementAuditService.auditEvent(nodeRef, getName(), result, null, true, false); + recordsManagementAuditService.auditEvent(nodeRef, getName(), userName, null, true, false); } diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAuditServiceImplTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAuditServiceImplTest.java index 65bc288e2c..73980dbb58 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAuditServiceImplTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAuditServiceImplTest.java @@ -465,7 +465,7 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase * Given I have deleted a user * When I will get the RM audit filter by delete user event * Then there will be an entry for the deleted user - * And the audit entry has the properties specific to cm:person type audited + * And the audit entry has the username property value audited * @throws Exception */ @org.junit.Test @@ -476,7 +476,6 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase final static String DELETE_USER_AUDIT_EVENT = "Delete Person"; String userName = "auditDeleteUser"; NodeRef user; - long nrOfPropertiesAudited; List entry; @Override @@ -484,10 +483,6 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase { // create a user user = createPerson(userName); - // count the cm:person properties with non null values - nrOfPropertiesAudited = dictionaryService.getPropertyDefs(ContentModel.TYPE_PERSON).keySet() - .stream().filter(prop -> nodeService.getProperty(user, prop) != null) - .count(); personService.deletePerson(userName); } @@ -500,7 +495,6 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase // get the audit events for "Delete Person" entry = getAuditTrail(params, 1, ADMIN_USER); - } @Override @@ -509,7 +503,7 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase assertEquals("Delete user event is not audited.", DELETE_USER_AUDIT_EVENT, entry.get(0).getEvent()); assertEquals(user.getId(), entry.get(0).getNodeName()); assertEquals("Unexpected nr of properties audited for cm:person type when deleting a user.", - nrOfPropertiesAudited, entry.get(0).getBeforeProperties().size()); + 1, entry.get(0).getBeforeProperties().size()); assertEquals("Wrong value for username property is audited", userName, entry.get(0).getBeforeProperties().get(ContentModel.PROP_USERNAME)); }