From ef139e4ad17f1f2fdddf1bc0f9f71b85dd216230 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Sun, 20 Jan 2013 20:46:35 +0000 Subject: [PATCH] RM-577 (A user can chose to hide a record within a collaboriation site, via a UI action) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@45630 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org_alfresco_module_rm/action-context.xml | 50 ++++--- .../action/dm/HideRecordAction.java | 126 ++++++++++++++++++ .../test/action/HideRecordActionTest.java | 75 +++++++++++ 3 files changed, 229 insertions(+), 22 deletions(-) create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/HideRecordAction.java create mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/HideRecordActionTest.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/action-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/action-context.xml index fce6814b19..3403de833c 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/action-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/action-context.xml @@ -3,25 +3,31 @@ - - - - - alfresco.module.org_alfresco_module_rm.messages.actions - - - - - - - - - - - - {http://www.alfresco.org/model/content/1.0}content - - - - - \ No newline at end of file + + + + + alfresco.module.org_alfresco_module_rm.messages.actions + + + + + + + + + + + + {http://www.alfresco.org/model/content/1.0}content + + + + + + + + + + + \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/HideRecordAction.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/HideRecordAction.java new file mode 100644 index 0000000000..0b7fa3920e --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/HideRecordAction.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.action.dm; + +import java.util.List; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.security.permissions.AccessDeniedException; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Hides a record within a collaboration site. + * + * Note: This is a 'normal' dm action, rather than a records management action. + * + * @author Tuna Aksoy + * @since 2.1 + */ +public class HideRecordAction extends ActionExecuterAbstractBase implements RecordsManagementModel +{ + + /** Logger */ + private static Log logger = LogFactory.getLog(HideRecordAction.class); + + /** Action name */ + public static final String NAME = "hide-record"; + + /** Node service */ + private NodeService nodeService; + + /** Permission service */ + private PermissionService permissionService; + + /** + * @param nodeService node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * @param permissionService permission service + */ + public void setPermissionService(PermissionService permissionService) + { + this.permissionService = permissionService; + } + + /** + * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + protected void executeImpl(Action action, NodeRef actionedUponNodeRef) + { + if (nodeService.hasAspect(actionedUponNodeRef, ASPECT_RECORD) == false) + { + // We cannot hide a document which is not a record + if (logger.isDebugEnabled() == true) + { + logger.debug("Cannot hide the document, because '" + actionedUponNodeRef.toString() + "' is not a record."); + } + } + else if (permissionService.hasPermission(actionedUponNodeRef, PermissionService.WRITE) != AccessStatus.ALLOWED) + { + // We do a sanity check to ensure that the user has at least write permissions on the record + throw new AccessDeniedException("Cannot hide record, because the user '" + AuthenticationUtil.getFullyAuthenticatedUser() + "' does not have write permissions on the record '" + actionedUponNodeRef.toString() + "'."); + } + else if (nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_HIDDEN) == true) + { + // We cannot hide records which are already hidden + if (logger.isDebugEnabled() == true) + { + logger.debug("Cannot hide record, because '" + actionedUponNodeRef.toString() + "' is already hidden."); + } + } + else + { + List parentAssocs = nodeService.getParentAssocs(actionedUponNodeRef); + for (ChildAssociationRef childAssociationRef : parentAssocs) + { + if (childAssociationRef.isPrimary() == false) + { + nodeService.removeChildAssociation(childAssociationRef); + } + } + } + } + + /** + * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List) + */ + @Override + protected void addParameterDefinitions(List paramList) + { + // Intentionally empty + } + +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/HideRecordActionTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/HideRecordActionTest.java new file mode 100644 index 0000000000..e95fc61d11 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/HideRecordActionTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.test.action; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.security.PermissionService; + +/** + * Hide Record Action Unit Test + * + * @author Tuna Aksoy + * @since 2.1 + */ +public class HideRecordActionTest extends BaseRMTestCase +{ + /** Services */ + protected ActionService dmActionService; + protected PermissionService dmPermissionService; + + @Override + protected void initServices() + { + super.initServices(); + + dmActionService = (ActionService) applicationContext.getBean("ActionService"); + dmPermissionService = (PermissionService) applicationContext.getBean("PermissionService"); + } + + @Override + protected boolean isUserTest() + { + return true; + } + + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + public void testHideRecordAction() + { + doTestInTransaction(new Test() + { + public Void run() + { + // FIXME + return null; + } + + public void test(Void result) throws Exception + { + // FIXME + }; + }, + dmCollaborator); + } +}