Do not allow addition of locked content to holds

This commit is contained in:
cagache
2019-08-13 17:10:06 +03:00
parent ce8eb66ab3
commit eda69a6eb6
5 changed files with 50 additions and 43 deletions

View File

@@ -27,6 +27,8 @@
package org.alfresco.module.org_alfresco_module_rm.hold;
import static org.alfresco.model.ContentModel.ASPECT_LOCKABLE;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
@@ -59,7 +61,6 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.AccessDeniedException;
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.alfresco.service.namespace.NamespaceService;
@@ -122,16 +123,6 @@ public class HoldServiceImpl extends ServiceBaseImpl
this.filePlanService = filePlanService;
}
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the record service
*
@@ -575,8 +566,7 @@ public class HoldServiceImpl extends ServiceBaseImpl
throw new IntegrityException(I18NUtil.getMessage("rm.hold.not-hold", holdName), null);
}
if (permissionService.hasPermission(hold, RMPermissionModel.FILING) == AccessStatus.DENIED ||
!AccessStatus.ALLOWED.equals(
if (!AccessStatus.ALLOWED.equals(
capabilityService.getCapabilityAccessState(hold, RMPermissionModel.ADD_TO_HOLD)))
{
throw new AccessDeniedException(I18NUtil.getMessage(MSG_ERR_ACCESS_DENIED));
@@ -638,6 +628,11 @@ public class HoldServiceImpl extends ServiceBaseImpl
{
throw new IntegrityException(I18NUtil.getMessage("rm.hold.add-to-hold-archived-node"), null);
}
if (nodeService.hasAspect(nodeRef, ASPECT_LOCKABLE))
{
throw new IntegrityException(I18NUtil.getMessage("rm.hold.add-to-hold-locked-node"), null);
}
}
/**

View File

@@ -131,9 +131,9 @@ public abstract class BaseHold extends DeclarativeWebScript
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
JSONObject json = getJSONFromContent(req);
List<NodeRef> holds = getHolds(json);
List<NodeRef> nodeRefs = getItemNodeRefs(json);
final JSONObject json = getJSONFromContent(req);
final List<NodeRef> holds = getHolds(json);
final List<NodeRef> nodeRefs = getItemNodeRefs(json);
doAction(holds, nodeRefs);
return new HashMap<>();
}
@@ -159,7 +159,7 @@ public abstract class BaseHold extends DeclarativeWebScript
JSONObject json = null;
try
{
String content = req.getContent().getContent();
final String content = req.getContent().getContent();
json = new JSONObject(new JSONTokener(content));
}
catch (IOException iox)
@@ -185,10 +185,10 @@ public abstract class BaseHold extends DeclarativeWebScript
*/
protected List<NodeRef> getItemNodeRefs(JSONObject json)
{
List<NodeRef> nodeRefs = new ArrayList<>();
final List<NodeRef> nodeRefs = new ArrayList<>();
try
{
JSONArray nodeRefsArray = json.getJSONArray("nodeRefs");
final JSONArray nodeRefsArray = json.getJSONArray("nodeRefs");
for (int i = 0; i < nodeRefsArray.length(); i++)
{
NodeRef nodeReference = new NodeRef(nodeRefsArray.getString(i));
@@ -234,13 +234,13 @@ public abstract class BaseHold extends DeclarativeWebScript
*/
protected List<NodeRef> getHolds(JSONObject json)
{
List<NodeRef> holds = new ArrayList<>();
final List<NodeRef> holds = new ArrayList<>();
try
{
JSONArray holdsArray = json.getJSONArray("holds");
final JSONArray holdsArray = json.getJSONArray("holds");
for (int i = 0; i < holdsArray.length(); i++)
{
NodeRef nodeRef = new NodeRef(holdsArray.getString(i));
final NodeRef nodeRef = new NodeRef(holdsArray.getString(i));
checkHoldNodeRef(nodeRef);
holds.add(nodeRef);
}

View File

@@ -116,33 +116,33 @@ public class HoldsGet extends DeclarativeWebScript
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
boolean fileOnly = getFileOnly(req);
NodeRef itemNodeRef = getItemNodeRef(req);
List<NodeRef> holds = new ArrayList<>();
final boolean fileOnly = getFileOnly(req);
final NodeRef itemNodeRef = getItemNodeRef(req);
final List<NodeRef> holds = new ArrayList<>();
if (itemNodeRef == null)
{
NodeRef filePlan = getFilePlan(req);
final NodeRef filePlan = getFilePlan(req);
holds.addAll(holdService.getHolds(filePlan));
}
else
{
boolean includedInHold = getIncludedInHold(req);
final boolean includedInHold = getIncludedInHold(req);
holds.addAll(holdService.heldBy(itemNodeRef, includedInHold));
}
List<Hold> holdObjects = new ArrayList<>(holds.size());
final List<Hold> holdObjects = new ArrayList<>(holds.size());
for (NodeRef nodeRef : holds)
{
// only add if user has filling permission on the hold
if (!fileOnly || permissionService.hasPermission(nodeRef, RMPermissionModel.FILING) == AccessStatus.ALLOWED)
{
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
final String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
holdObjects.add(new Hold(name, nodeRef));
}
}
Map<String, Object> model = new HashMap<>(1);
final Map<String, Object> model = new HashMap<>(1);
sortHoldByName(holdObjects);
model.put("holds", holdObjects);
@@ -159,10 +159,10 @@ public class HoldsGet extends DeclarativeWebScript
{
NodeRef filePlan = null;
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String storeType = templateVars.get("store_type");
String storeId = templateVars.get("store_id");
String id = templateVars.get("id");
final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
final String storeType = templateVars.get("store_type");
final String storeId = templateVars.get("store_id");
final String id = templateVars.get("id");
if (StringUtils.isNotBlank(storeType) && StringUtils.isNotBlank(storeId) && StringUtils.isNotBlank(id))
{
@@ -194,7 +194,7 @@ public class HoldsGet extends DeclarativeWebScript
*/
private NodeRef getItemNodeRef(WebScriptRequest req)
{
String nodeRef = req.getParameter("itemNodeRef");
final String nodeRef = req.getParameter("itemNodeRef");
NodeRef itemNodeRef = null;
if (StringUtils.isNotBlank(nodeRef))
{
@@ -212,7 +212,7 @@ public class HoldsGet extends DeclarativeWebScript
private boolean getIncludedInHold(WebScriptRequest req)
{
boolean result = true;
String includedInHold = req.getParameter("includedInHold");
final String includedInHold = req.getParameter("includedInHold");
if (StringUtils.isNotBlank(includedInHold))
{
result = Boolean.parseBoolean(includedInHold);
@@ -223,7 +223,7 @@ public class HoldsGet extends DeclarativeWebScript
private boolean getFileOnly(WebScriptRequest req)
{
boolean result = false;
String fillingOnly = req.getParameter("fileOnly");
final String fillingOnly = req.getParameter("fileOnly");
if (StringUtils.isNotBlank(fillingOnly))
{
result = Boolean.parseBoolean(fillingOnly);