mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
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
This commit is contained in:
@@ -24,4 +24,10 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Hide record action -->
|
||||
<bean id="hide-record" parent="action-executer" class="org.alfresco.module.org_alfresco_module_rm.action.dm.HideRecordAction">
|
||||
<property name="permissionService" ref="PermissionService"/>
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<ChildAssociationRef> 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<ParameterDefinition> paramList)
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Void>()
|
||||
{
|
||||
public Void run()
|
||||
{
|
||||
// FIXME
|
||||
return null;
|
||||
}
|
||||
|
||||
public void test(Void result) throws Exception
|
||||
{
|
||||
// FIXME
|
||||
};
|
||||
},
|
||||
dmCollaborator);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user