ALF-17405: Admin can now delete ANY workflow instance through REST + added test

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@46618 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Frederik Heremans
2013-02-14 11:26:31 +00:00
parent 7b527ca4b3
commit da7307b375
2 changed files with 61 additions and 15 deletions

View File

@@ -31,6 +31,7 @@ import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.person.TestGroupManager;
import org.alfresco.repo.security.person.TestPersonManager;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
@@ -1124,7 +1125,45 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
assertTrue(afterCancelResult.length() == 0);
}
public void testWorkflowInstanceDeleteAsAdministrator() throws Exception
{
//Start workflow as USER1
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
Date dueDate = new Date();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
params.put(WorkflowModel.PROP_CONTEXT, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
startTask = workflowService.endTask(startTask.getId(), null);
WorkflowInstance adhocInstance = startTask.getPath().getInstance();
// Run next request as admin
String admin = authenticationComponent.getDefaultAdministratorUserNames().iterator().next();
AuthenticationUtil.setFullyAuthenticatedUser(admin);
sendRequest(new DeleteRequest(URL_WORKFLOW_INSTANCES + "/" + adhocInstance.getId()), Status.STATUS_OK);
WorkflowInstance instance = workflowService.getWorkflowById(adhocInstance.getId());
if (instance != null)
{
assertFalse("The deleted workflow is still active!", instance.isActive());
}
List<WorkflowInstance> instances = workflowService.getActiveWorkflows(adhocInstance.getDefinition().getId());
for (WorkflowInstance activeInstance : instances)
{
assertFalse(adhocInstance.getId().equals(activeInstance.getId()));
}
}
public void testWorkflowInstanceDelete() throws Exception
{
//Start workflow as USER1 and assign task to USER2.

View File

@@ -111,22 +111,29 @@ public class WorkflowInstanceDelete extends AbstractWorkflowWebscript
"The workflow instance to delete/cancel with id " + instanceId + " doesn't exist: ");
}
NodeRef initiator = wi.getInitiator();
if (initiator != null)
{
// determine if the current user is the initiator of the workflow
String currentUserName = authenticationService.getCurrentUserName();
// 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))
{
canEnd = true;
}
}
String currentUserName = authenticationService.getCurrentUserName();
// ALF-17405: Admin can always delete/cancel workflows, regardless of the initiator
if(authorityService.isAdminAuthority(currentUserName))
{
canEnd = true;
}
else
{
NodeRef initiator = wi.getInitiator();
// determine if the current user is the initiator of the workflow
if (initiator != null)
{
// 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))
{
canEnd = true;
}
}
}
return canEnd;
}
}