Merged 5.1.N (5.1.1) to HEAD (5.1)

120414 arebegea: Merged 5.0.N (5.0.4) to 5.1.N (5.1.1)
      120386 abozianu: Merged DEV to 5.0.N (5.0.4)
         120352 abozianu: MNT-14411 : Re-created user can't cancel created task
            - fix and unit test


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@123619 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-03-11 21:35:42 +00:00
parent 58efe344c2
commit 21549b96bc
2 changed files with 65 additions and 8 deletions

View File

@@ -18,13 +18,17 @@
*/
package org.alfresco.repo.web.scripts.workflow;
import java.io.Serializable;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.workflow.WorkflowConstants;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.workflow.WorkflowInstance;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
@@ -120,19 +124,40 @@ public class WorkflowInstanceDelete extends AbstractWorkflowWebscript
}
else
{
String ownerName = null;
// Determine if the current user is the initiator of the workflow.
// Get the username of the initiator.
NodeRef initiator = wi.getInitiator();
// determine if the current user is the initiator of the workflow
if (initiator != null)
if (initiator != null && nodeService.exists(initiator))
{
// get the username of the initiator
String userName = (String)nodeService.getProperty(initiator, ContentModel.PROP_USERNAME);
// if the current user started the workflow allow the cancel action
if (currentUserName.equals(userName))
ownerName = (String) nodeService.getProperty(initiator, ContentModel.PROP_USERNAME);
}
else
{
/*
* Fix for MNT-14411 : Re-created user can't cancel created task.
* If owner value can't be found on workflow properties
* because initiator nodeRef no longer exists get owner from
* initiatorhome nodeRef owner property.
*/
WorkflowTask startTask = workflowService.getStartTask(wi.getId());
Map<QName, Serializable> props = startTask.getProperties();
ownerName = (String) props.get(ContentModel.PROP_OWNER);
if (ownerName == null)
{
canEnd = true;
NodeRef initiatorHomeNodeRef = (NodeRef) props.get(QName.createQName("", WorkflowConstants.PROP_INITIATOR_HOME));
if (initiatorHomeNodeRef != null)
{
ownerName = (String) nodeService.getProperty(initiatorHomeNodeRef, ContentModel.PROP_OWNER);
}
}
}
// if the current user started the workflow allow the cancel action
if (currentUserName.equals(ownerName))
{
canEnd = true;
}
}
return canEnd;
}