diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/FilePlanTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/FilePlanTests.java index 574f4f14bb..c644d61c4e 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/FilePlanTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/FilePlanTests.java @@ -198,7 +198,7 @@ public class FilePlanTests extends BaseRestTest /** * Given that a file plan exists * When I ask the API to delete the file plan - * Then the 403 response code is returned. + * Then the 422 response code is returned. */ @Test ( @@ -217,6 +217,40 @@ public class FilePlanTests extends BaseRestTest // Delete the file plan component filePlanComponentAPI.deleteFilePlanComponent(filePlanAlias.toString()); + // Check the DELETE response status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); + } + + /** + * Given that a file plan exists and I am a non RM user + * When I ask the API to delete the file plan + * Then the 403 response code is returned. + */ + @Test + ( + description = "Check the response code when deleting the special file plan components with non RM user", + dataProviderClass = TestData.class, + dataProvider = "getContainers" + ) + public void deleteFilePlanSpecialComponentsNonRMUser(String filePlanAlias) throws Exception + { + // Create RM Site if doesn't exist + createRMSiteIfNotExists(); + + // Disconnect the current user from the API session + rmSiteAPI.usingRestWrapper().disconnect(); + // Authenticate admin user to Alfresco REST API + restClient.authenticateUser(dataUser.getAdminUser()); + + // Create a random user + UserModel nonRMuser = dataUser.createRandomTestUser("testUser"); + + // Authenticate using the random user + filePlanComponentAPI.usingRestWrapper().authenticateUser(nonRMuser); + + // Delete the file plan component + filePlanComponentAPI.deleteFilePlanComponent(filePlanAlias.toString()); + // Check the DELETE response status code filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); } diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/capability/rm-capabilities-fileplan-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/capability/rm-capabilities-fileplan-context.xml index e8eeae8602..02a69e2521 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/capability/rm-capabilities-fileplan-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/capability/rm-capabilities-fileplan-context.xml @@ -94,4 +94,23 @@ + + + + + TRANSFER_CONTAINER + + + + + + + + + HOLD_CONTAINER + + + \ No newline at end of file diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/capability/rm-capabilities-group-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/capability/rm-capabilities-group-context.xml index 91a50ef89d..3b67d92639 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/capability/rm-capabilities-group-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/capability/rm-capabilities-group-context.xml @@ -25,6 +25,8 @@ + + diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml index 8a26e80449..aba5909bb3 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml @@ -77,6 +77,8 @@ + + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java index 3fe97f36d0..6d2684b0ce 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java @@ -83,6 +83,10 @@ public class FilePlanType extends BaseBehaviourBean private UnfiledRecordContainerType unfilerRecordContainerType; + private TransferContainerType transferContainerType; + + private HoldContainerType holdContainerType; + /** * @return File plan service */ @@ -152,6 +156,15 @@ public class FilePlanType extends BaseBehaviourBean this.unfilerRecordContainerType = unfilerRecordContainerType; } + public void setTransferContainerType(TransferContainerType transferContainerType) + { + this.transferContainerType = transferContainerType; + } + + public void setHoldContainerType(HoldContainerType holdContainerType) + { + this.holdContainerType = holdContainerType; + } /** * Disable the behaviours for this transaction @@ -234,6 +247,8 @@ public class FilePlanType extends BaseBehaviourBean public void onDeleteNode(ChildAssociationRef childAssocRef, boolean archived) { unfilerRecordContainerType.enable(); + transferContainerType.enable(); + holdContainerType.enable(); throw new IntegrityException("Operation failed. Deletion of File Plan is not allowed.", null); } @@ -249,6 +264,8 @@ public class FilePlanType extends BaseBehaviourBean public void beforeDeleteNode(NodeRef nodeRef) { unfilerRecordContainerType.disable(); + transferContainerType.disable(); + holdContainerType.disable(); } @Behaviour @@ -262,5 +279,7 @@ public class FilePlanType extends BaseBehaviourBean // tear down the file plan roles getFilePlanRoleService().tearDownFilePlanRoles(childAssocRef.getChildRef()); unfilerRecordContainerType.enable(); + transferContainerType.enable(); + holdContainerType.enable(); } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/HoldContainerType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/HoldContainerType.java index 989b92699b..2326b41f64 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/HoldContainerType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/HoldContainerType.java @@ -33,6 +33,7 @@ import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.node.integrity.IntegrityException; import org.alfresco.repo.policy.annotation.Behaviour; import org.alfresco.repo.policy.annotation.BehaviourBean; import org.alfresco.repo.policy.annotation.BehaviourKind; @@ -49,10 +50,31 @@ import org.springframework.extensions.surf.util.I18NUtil; */ @BehaviourBean(defaultType = "rma:holdContainer") public class HoldContainerType extends BaseBehaviourBean - implements NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnCreateNodePolicy + implements NodeServicePolicies.OnCreateChildAssociationPolicy, + NodeServicePolicies.OnCreateNodePolicy, + NodeServicePolicies.OnDeleteNodePolicy { private final static String MSG_ERROR_ADD_CONTENT_CONTAINER = "rm.service.error-add-content-container"; private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_HOLD); + private static final String DELETE_BEHAVIOUR_NAME = "onDeleteHoldContainer"; + + /** + * Disable the behaviours for this transaction + * + */ + public void disable() + { + getBehaviour(DELETE_BEHAVIOUR_NAME).disable(); + } + + /** + * Enable behaviours for this transaction + * + */ + public void enable() + { + getBehaviour(DELETE_BEHAVIOUR_NAME).enable(); + } /** * On every event @@ -74,6 +96,16 @@ public class HoldContainerType extends BaseBehaviourBean NodeRef nodeRef = childAssocRef.getChildRef(); if (instanceOf(nodeRef, ContentModel.TYPE_CONTENT) == true) { throw new AlfrescoRuntimeException( I18NUtil.getMessage(MSG_ERROR_ADD_CONTENT_CONTAINER)); } + } + @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + name = DELETE_BEHAVIOUR_NAME + ) + public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived) + { + throw new IntegrityException("Operation failed. Deletion of Hold Container is not allowed.", null); } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/TransferContainerType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/TransferContainerType.java index d0fba4ff99..6fb4cca3ef 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/TransferContainerType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/TransferContainerType.java @@ -46,11 +46,15 @@ import org.springframework.extensions.surf.util.I18NUtil; */ @BehaviourBean(defaultType = "rma:transferContainer") public class TransferContainerType extends BaseBehaviourBean - implements NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnCreateNodePolicy + implements NodeServicePolicies.OnCreateChildAssociationPolicy, + NodeServicePolicies.OnCreateNodePolicy, + NodeServicePolicies.OnDeleteNodePolicy + { private final static String MSG_ERROR_ADD_CONTENT_CONTAINER = "rm.service.error-add-content-container"; private final static String MSG_ERROR_ADD_CHILD_TO_TRANSFER_CONTAINER = "rm.action.create.transfer.container.child-error-message"; private static final String BEHAVIOUR_NAME = "onCreateChildAssocsForTransferContainer"; + private static final String DELETE_BEHAVIOUR_NAME = "onDeleteTransferContainer"; /** * Disable the behaviours for this transaction @@ -59,6 +63,7 @@ public class TransferContainerType extends BaseBehaviourBean public void disable() { getBehaviour(BEHAVIOUR_NAME).disable(); + getBehaviour(DELETE_BEHAVIOUR_NAME).disable(); } /** @@ -68,6 +73,7 @@ public class TransferContainerType extends BaseBehaviourBean public void enable() { getBehaviour(BEHAVIOUR_NAME).enable(); + getBehaviour(DELETE_BEHAVIOUR_NAME).enable(); } /** @@ -94,4 +100,15 @@ public class TransferContainerType extends BaseBehaviourBean if (instanceOf(nodeRef, ContentModel.TYPE_CONTENT) == true) { throw new AlfrescoRuntimeException( I18NUtil.getMessage(MSG_ERROR_ADD_CONTENT_CONTAINER)); } } + + @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + name = DELETE_BEHAVIOUR_NAME + ) + public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived) + { + throw new IntegrityException("Operation failed. Deletion of Transfer Container is not allowed.", null); + } }