mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-4326: removed checkPostPermission method and changed RmSyteType to
handle allowed created types
This commit is contained in:
@@ -44,7 +44,6 @@ import org.alfresco.module.org_alfresco_module_rm.audit.event.AuditEvent;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.rma.type.HoldType;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
|
||||
@@ -103,8 +102,6 @@ public class HoldServiceImpl extends ServiceBaseImpl
|
||||
/** records management audit service */
|
||||
private RecordsManagementAuditService recordsManagementAuditService;
|
||||
|
||||
private HoldType holdType;
|
||||
|
||||
/**
|
||||
* Set the file plan service
|
||||
*
|
||||
@@ -163,11 +160,6 @@ public class HoldServiceImpl extends ServiceBaseImpl
|
||||
this.recordsManagementAuditService = recordsManagementAuditService;
|
||||
}
|
||||
|
||||
public void setHoldType(HoldType holdType)
|
||||
{
|
||||
this.holdType = holdType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise hold service
|
||||
*/
|
||||
@@ -602,15 +594,7 @@ public class HoldServiceImpl extends ServiceBaseImpl
|
||||
}
|
||||
|
||||
// Link the record to the hold
|
||||
holdType.disable();
|
||||
try
|
||||
{
|
||||
nodeService.addChild(hold, nodeRef, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
|
||||
}
|
||||
finally
|
||||
{
|
||||
holdType.enable();
|
||||
}
|
||||
nodeService.addChild(hold, nodeRef, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
|
||||
|
||||
// audit item being added to the hold
|
||||
recordsManagementAuditService.auditEvent(nodeRef, AUDIT_ADD_TO_HOLD);
|
||||
|
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 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.model.rma.type;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
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.ChildAssociationRef;
|
||||
|
||||
/**
|
||||
* rma:transferContainer behaviour bean
|
||||
*
|
||||
* @author Silviu Dinuta
|
||||
* @since 2.6
|
||||
*/
|
||||
@BehaviourBean(defaultType = "rma:hold")
|
||||
public class HoldType extends BaseBehaviourBean implements NodeServicePolicies.OnCreateChildAssociationPolicy
|
||||
{
|
||||
private static final String BEHAVIOUR_NAME = "onCreateChildAssocsForHoldType";
|
||||
|
||||
/**
|
||||
* Disable the behaviours for this transaction
|
||||
*
|
||||
*/
|
||||
public void disable()
|
||||
{
|
||||
getBehaviour(BEHAVIOUR_NAME).disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable behaviours for this transaction
|
||||
*
|
||||
*/
|
||||
public void enable()
|
||||
{
|
||||
getBehaviour(BEHAVIOUR_NAME).enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Behaviour
|
||||
(
|
||||
kind = BehaviourKind.ASSOCIATION,
|
||||
name = BEHAVIOUR_NAME
|
||||
)
|
||||
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
|
||||
{
|
||||
throw new InvalidParameterException("Operation failed. Creation is not allowed in Hold Folders");
|
||||
}
|
||||
|
||||
}
|
@@ -28,10 +28,14 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
|
||||
import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService;
|
||||
@@ -55,6 +59,8 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Behaviour associated with the RM Site type
|
||||
*
|
||||
@@ -68,10 +74,11 @@ import org.alfresco.util.PropertyMap;
|
||||
public class RmSiteType extends BaseBehaviourBean
|
||||
implements NodeServicePolicies.OnCreateNodePolicy,
|
||||
NodeServicePolicies.OnUpdatePropertiesPolicy,
|
||||
NodeServicePolicies.BeforeDeleteNodePolicy
|
||||
NodeServicePolicies.BeforeDeleteNodePolicy,
|
||||
NodeServicePolicies.OnCreateChildAssociationPolicy
|
||||
{
|
||||
/** Constant values */
|
||||
public static final String COMPONENT_DOCUMENT_LIBRARY = "documentLibrary";
|
||||
/** Constant values */
|
||||
public static final String COMPONENT_DOCUMENT_LIBRARY = "documentLibrary";
|
||||
public static final String DEFAULT_SITE_NAME = "rm";
|
||||
public static final QName DEFAULT_FILE_PLAN_TYPE = TYPE_FILE_PLAN;
|
||||
|
||||
@@ -96,8 +103,8 @@ public class RmSiteType extends BaseBehaviourBean
|
||||
*/
|
||||
public void setSiteService(SiteService siteService)
|
||||
{
|
||||
this.siteService = siteService;
|
||||
}
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recordsManagementSearchService records management search service
|
||||
@@ -132,39 +139,39 @@ public class RmSiteType extends BaseBehaviourBean
|
||||
*/
|
||||
public void registerFilePlanType(QName siteType, QName filePlanType)
|
||||
{
|
||||
ParameterCheck.mandatory("siteType", siteType);
|
||||
ParameterCheck.mandatory("filePlanType", filePlanType);
|
||||
ParameterCheck.mandatory("siteType", siteType);
|
||||
ParameterCheck.mandatory("filePlanType", filePlanType);
|
||||
|
||||
// check that the registered site type is a subtype of rma:rmsite
|
||||
if (!dictionaryService.isSubClass(siteType, TYPE_RM_SITE))
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"Can't register site type, because site type is not a sub type of rma:rmsite (siteType=" + siteType.toString() + ")");
|
||||
}
|
||||
// check that the registered site type is a subtype of rma:rmsite
|
||||
if (!dictionaryService.isSubClass(siteType, TYPE_RM_SITE))
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"Can't register site type, because site type is not a sub type of rma:rmsite (siteType=" + siteType.toString() + ")");
|
||||
}
|
||||
|
||||
// check that the registered file plan type is a sub type of rma:filePlan
|
||||
if (!dictionaryService.isSubClass(filePlanType, TYPE_FILE_PLAN))
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"Can't register file plan type, because site type is not a sub type of rma:filePlan (filePlanType=" + filePlanType.toString() + ")");
|
||||
}
|
||||
// check that the registered file plan type is a sub type of rma:filePlan
|
||||
if (!dictionaryService.isSubClass(filePlanType, TYPE_FILE_PLAN))
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"Can't register file plan type, because site type is not a sub type of rma:filePlan (filePlanType=" + filePlanType.toString() + ")");
|
||||
}
|
||||
|
||||
// add site and file plan types to map
|
||||
mapFilePlanType.put(siteType, filePlanType);
|
||||
// add site and file plan types to map
|
||||
mapFilePlanType.put(siteType, filePlanType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy#onCreateNode(org.alfresco.service.cmr.repository.ChildAssociationRef)
|
||||
*/
|
||||
@Override
|
||||
@Behaviour
|
||||
(
|
||||
kind = BehaviourKind.CLASS,
|
||||
notificationFrequency = NotificationFrequency.FIRST_EVENT
|
||||
)
|
||||
public void onCreateNode(ChildAssociationRef childAssocRef)
|
||||
{
|
||||
final NodeRef rmSite = childAssocRef.getChildRef();
|
||||
@Override
|
||||
@Behaviour
|
||||
(
|
||||
kind = BehaviourKind.CLASS,
|
||||
notificationFrequency = NotificationFrequency.FIRST_EVENT
|
||||
)
|
||||
public void onCreateNode(ChildAssociationRef childAssocRef)
|
||||
{
|
||||
final NodeRef rmSite = childAssocRef.getChildRef();
|
||||
|
||||
// Do not execute behaviour if this has been created in the archive store
|
||||
if(rmSite.getStoreRef().equals(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE))
|
||||
@@ -179,52 +186,52 @@ public class RmSiteType extends BaseBehaviourBean
|
||||
{
|
||||
public Object doWork()
|
||||
{
|
||||
SiteInfo siteInfo = siteService.getSite(rmSite);
|
||||
if (siteInfo != null)
|
||||
{
|
||||
// Create the file plan component
|
||||
siteService.createContainer(siteInfo.getShortName(), COMPONENT_DOCUMENT_LIBRARY, getFilePlanType(siteInfo), null);
|
||||
SiteInfo siteInfo = siteService.getSite(rmSite);
|
||||
if (siteInfo != null)
|
||||
{
|
||||
// Create the file plan component
|
||||
siteService.createContainer(siteInfo.getShortName(), COMPONENT_DOCUMENT_LIBRARY, getFilePlanType(siteInfo), null);
|
||||
|
||||
// Add the reports
|
||||
recordsManagementSearchService.addReports(siteInfo.getShortName());
|
||||
}
|
||||
// Add the reports
|
||||
recordsManagementSearchService.addReports(siteInfo.getShortName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, AuthenticationUtil.getAdminUserName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file plan type for the given site.
|
||||
*
|
||||
* @param siteInfo site info
|
||||
* @return QName file plan type to create as a container
|
||||
* @since 2.2
|
||||
*/
|
||||
private QName getFilePlanType(SiteInfo siteInfo)
|
||||
{
|
||||
ParameterCheck.mandatory("siteInfo", siteInfo);
|
||||
/**
|
||||
* Get the file plan type for the given site.
|
||||
*
|
||||
* @param siteInfo site info
|
||||
* @return QName file plan type to create as a container
|
||||
* @since 2.2
|
||||
*/
|
||||
private QName getFilePlanType(SiteInfo siteInfo)
|
||||
{
|
||||
ParameterCheck.mandatory("siteInfo", siteInfo);
|
||||
|
||||
// set default file plan
|
||||
QName result = DEFAULT_FILE_PLAN_TYPE;
|
||||
// set default file plan
|
||||
QName result = DEFAULT_FILE_PLAN_TYPE;
|
||||
|
||||
// check to see if there is an 'override' for the file plan type given the site type
|
||||
QName siteType = nodeService.getType(siteInfo.getNodeRef());
|
||||
if (mapFilePlanType.containsKey(siteType))
|
||||
{
|
||||
result = mapFilePlanType.get(siteType);
|
||||
}
|
||||
// check to see if there is an 'override' for the file plan type given the site type
|
||||
QName siteType = nodeService.getType(siteInfo.getNodeRef());
|
||||
if (mapFilePlanType.containsKey(siteType))
|
||||
{
|
||||
result = mapFilePlanType.get(siteType);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the visibility of a RM site can not be changed to anything but public.
|
||||
*
|
||||
* TODO support other site visibilities
|
||||
*
|
||||
* @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
|
||||
*/
|
||||
/**
|
||||
* Ensure that the visibility of a RM site can not be changed to anything but public.
|
||||
*
|
||||
* TODO support other site visibilities
|
||||
*
|
||||
* @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
|
||||
*/
|
||||
@Behaviour
|
||||
(
|
||||
kind = BehaviourKind.CLASS,
|
||||
@@ -295,4 +302,44 @@ public class RmSiteType extends BaseBehaviourBean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Silviu Dinuta
|
||||
* @since 2.6
|
||||
*/
|
||||
@Override
|
||||
@Behaviour(kind = BehaviourKind.ASSOCIATION)
|
||||
public void onCreateChildAssociation(final ChildAssociationRef childAssocRef, boolean isNewNode)
|
||||
{
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork()
|
||||
{
|
||||
final NodeRef child = childAssocRef.getChildRef();
|
||||
final NodeRef parent = childAssocRef.getParentRef();
|
||||
List<QName> acceptedUniqueChildTypes = new ArrayList<QName>();
|
||||
SiteInfo siteInfo = siteService.getSite(parent);
|
||||
acceptedUniqueChildTypes.add(getFilePlanType(siteInfo));
|
||||
List<QName> acceptedNonUniqueChildTypes = new ArrayList<QName>();
|
||||
acceptedNonUniqueChildTypes.add(ContentModel.TYPE_FOLDER);
|
||||
// check the created child is of an accepted type
|
||||
validateNewChildAssociation(parent, child, acceptedUniqueChildTypes, acceptedNonUniqueChildTypes);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateNewChildAssociation(NodeRef parent, NodeRef child, List<QName> acceptedUniqueChildType,
|
||||
List<QName> acceptedMultipleChildType) throws InvalidParameterException
|
||||
{
|
||||
super.validateNewChildAssociation(parent, child, acceptedUniqueChildType, acceptedMultipleChildType);
|
||||
|
||||
// check the user is not trying to create more than 2 folders that are created by default
|
||||
if(nodeService.getChildAssocs(parent, Sets.newHashSet(ContentModel.TYPE_FOLDER)).size() > 2)
|
||||
{
|
||||
throw new InvalidParameterException("Operation failed. Children of type " + ContentModel.TYPE_FOLDER + " are not allowed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -45,11 +45,4 @@ public interface RMNodes extends Nodes
|
||||
public static String PARAM_INCLUDE_HAS_RETENTION_SCHEDULE = "hasRetentionSchedule";
|
||||
public static String PARAM_INCLUDE_IS_CLOSED = "isClosed";
|
||||
public static String PARAM_INCLUDE_IS_COMPLETED = "isCompleted";
|
||||
|
||||
/**
|
||||
* Verifies if the post request is allowed for nodeId received as parameter.
|
||||
*
|
||||
* @param nodeId
|
||||
*/
|
||||
void checkPostPermission(String nodeId);
|
||||
}
|
||||
|
@@ -59,8 +59,6 @@ import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
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.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
@@ -86,7 +84,6 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
|
||||
private Repository repositoryHelper;
|
||||
private DictionaryService dictionaryService;
|
||||
private DispositionService dispositionService;
|
||||
private SiteService siteService;
|
||||
|
||||
/**
|
||||
* TODO to remove this after isSpecialNode is made protected in core implementation(REPO-1459)
|
||||
@@ -98,7 +95,6 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
|
||||
this.nodeService = serviceRegistry.getNodeService();
|
||||
this.dictionaryService = serviceRegistry.getDictionaryService();
|
||||
this.dispositionService = serviceRegistry.getDispositionService();
|
||||
this.siteService = serviceRegistry.getSiteService();
|
||||
}
|
||||
|
||||
public void setRecordsManagementServiceRegistry(RecordsManagementServiceRegistry serviceRegistry)
|
||||
@@ -402,20 +398,4 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
|
||||
}
|
||||
super.deleteNode(nodeId, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPostPermission(String nodeId)
|
||||
{
|
||||
NodeRef parentNodeRef = validateOrLookupNode(nodeId, null);
|
||||
|
||||
SiteInfo siteInfo = siteService.getSite(FilePlanService.DEFAULT_RM_SITE_ID);
|
||||
if(siteInfo !=null)
|
||||
{
|
||||
NodeRef rmNodeRef = siteInfo.getNodeRef();
|
||||
if(rmNodeRef.equals(parentNodeRef))
|
||||
{
|
||||
throw new PermissionDeniedException("POST request not allowed in RM site.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -67,7 +67,6 @@ public class FileplanComponentChildrenRelation implements RelationshipResourceAc
|
||||
@Override
|
||||
public List<Node> create(String parentFolderNodeId, List<Node> nodeInfos, Parameters parameters)
|
||||
{
|
||||
nodes.checkPostPermission(parentFolderNodeId);
|
||||
List<Node> result = new ArrayList<>(nodeInfos.size());
|
||||
|
||||
for (Node nodeInfo : nodeInfos)
|
||||
@@ -81,7 +80,6 @@ public class FileplanComponentChildrenRelation implements RelationshipResourceAc
|
||||
@Override
|
||||
public Node create(String parentFolderNodeId, FormData formData, Parameters parameters, WithResponse withResponse)
|
||||
{
|
||||
nodes.checkPostPermission(parentFolderNodeId);
|
||||
return nodes.upload(parentFolderNodeId, formData, parameters);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user