RM-7027 Audit delete hold

This commit is contained in:
Sara Aspery
2019-11-06 16:33:38 +00:00
parent caac83aa68
commit a4afc023be
7 changed files with 232 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ rm.audit.moveTo=Move to
rm.audit.copyTo=Copy to
rm.audit.fileTo=File to
rm.audit.createHold=Create Hold
rm.audit.deleteHold=Delete Hold
rm.audit.audit-start=Audit Start
rm.audit.audit-stop=Audit Stop
rm.audit.audit-clear=Audit Clear

View File

@@ -1024,6 +1024,7 @@
</bean>
<bean id="deleteHold" class="org.alfresco.module.org_alfresco_module_rm.action.impl.DeleteHoldAction" parent="rmAction">
<property name="auditable" value="false"/>
<property name="auditedImmediately" value="true"/>
</bean>

View File

@@ -133,4 +133,9 @@
<property name="label" value="rm.audit.createHold"/>
</bean>
<bean id="audit-event.deleteHold" parent="audit-event" class="org.alfresco.module.org_alfresco_module_rm.audit.event.DeleteHoldAuditEvent">
<property name="nodeService" ref="nodeService" />
<property name="name" value="Delete Hold"/>
<property name="label" value="rm.audit.deleteHold"/>
</bean>
</beans>

View File

@@ -0,0 +1,80 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2019 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.module.org_alfresco_module_rm.audit.event;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.hold.HoldServicePolicies;
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.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.EVERY_EVENT;
/**
* Delete hold audit event.
*
* @author Sara Aspery
* @since 3.3
*/
@BehaviourBean
public class DeleteHoldAuditEvent extends AuditEvent implements HoldServicePolicies.BeforeDeleteHoldPolicy
{
/** Node Service */
private NodeService nodeService;
/**
* Sets the node service
*
* @param nodeService nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.hold.HoldServicePolicies.BeforeDeleteHoldPolicy#beforeDeleteHold(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
@Behaviour
(
kind = BehaviourKind.CLASS,
type = "rma:hold",
notificationFrequency = EVERY_EVENT
)
public void beforeDeleteHold(NodeRef holdNodeRef)
{
Map<QName, Serializable> auditProperties = HoldUtils.makePropertiesMap(holdNodeRef, nodeService);
recordsManagementAuditService.auditEvent(holdNodeRef, getName(), auditProperties, null, true, false);
}
}

View File

@@ -574,6 +574,55 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase
});
}
/**
* Given I have created a hold
* When I delete the hold and get the RM audit filter by delete hold event
* Then there will be an entry for the deleted hold, including the hold name
*/
@org.junit.Test
public void testAuditForDeleteHold()
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
final static String DELETE_HOLD_AUDIT_EVENT = "Delete Hold";
String holdName = "Hold " + GUID.generate();
NodeRef hold;
Map<QName, Serializable> auditEventProperties;
@Override
public void given()
{
rmAuditService.clearAuditLog(filePlan);
hold = createHold(holdName, "Reason " + GUID.generate());
}
@Override
public void when()
{
deleteHold(hold);
auditEventProperties = getAuditEntry(DELETE_HOLD_AUDIT_EVENT).getBeforeProperties();
}
@Override
public void then()
{
// check delete hold audit event includes the hold name
assertEquals("Delete Hold event does not include hold name.", holdName,
auditEventProperties.get(HOLD_NAME));
}
@Override
public void after()
{
// Stop and delete all entries
rmAuditService.stopAuditLog(filePlan);
rmAuditService.clearAuditLog(filePlan);
}
});
}
/**
* Given I have created a hold
* When I will get the RM audit filter by create hold event

View File

@@ -720,6 +720,15 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
return holdService.createHold(filePlan, holdName, holdReason, generate());
}
/**
* Util method to delete a hold.
* @param nodeRef hold node reference
*/
protected void deleteHold(NodeRef nodeRef)
{
holdService.deleteHold(nodeRef);
}
/**
* Setup multi hierarchy test data
*/

View File

@@ -0,0 +1,87 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2019 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.module.org_alfresco_module_rm.audit.event;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.util.GUID;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import java.util.Map;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
/**
* Unit tests for {@link DeleteHoldAuditEvent}.
*
* @author Sara Aspery
* @since 3.3
*/
public class DeleteHoldAuditEventUnitTest extends BaseUnitTest
{
@InjectMocks
private DeleteHoldAuditEvent deleteHoldAuditEvent;
@Mock
private NodeService mockedNodeService;
private NodeRef holdNodeRef;
/** Set up the mocks. */
@Before
public void setUp()
{
initMocks(this);
holdNodeRef = generateNodeRef();
String holdName = "Hold " + GUID.generate();
when(mockedNodeService.getProperty(holdNodeRef, PROP_NAME)).thenReturn(holdName);
}
/**
* Check that the delete hold event calls an audit event.
*
*/
@Test
public void testDeleteHoldCausesAuditEvent()
{
deleteHoldAuditEvent.beforeDeleteHold(holdNodeRef);
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(holdNodeRef), any(String.class), any(Map.class), isNull(Map.class));
}
}