Created
August 27, 2014 11:46
-
-
Save jamieechlin/cd1e102f3833ded10ced to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.atlassian.jira.component.ComponentAccessor | |
import com.atlassian.jira.workflow.JiraWorkflow | |
import com.atlassian.jira.workflow.condition.InProjectRoleCondition | |
import com.opensymphony.workflow.loader.ConditionDescriptor | |
def workflowName = "My workflow" | |
def workflowManager = ComponentAccessor.getWorkflowManager() | |
def workflow = workflowManager.getWorkflow(workflowName) | |
if (workflow.hasDraftWorkflow()) { | |
throw new Exception("Delete or publish the draft workflow for $workflowName") | |
} | |
def user = ComponentAccessor.getJiraAuthenticationContext().getUser() | |
JiraWorkflow draft | |
if (workflow.isActive()) { | |
log.debug("Creating draft") | |
draft = workflowManager.createDraftWorkflow(user, workflowName) | |
} | |
else { | |
draft = workflow | |
} | |
draft.allActions.each {action -> | |
def conditions = action.getRestriction()?.getConditionsDescriptor()?.getConditions() | |
if (conditions) { | |
def iterator = conditions.iterator() | |
while (iterator.hasNext()) { | |
ConditionDescriptor cd = iterator.next() as ConditionDescriptor; | |
if (cd.args == ["class.name": InProjectRoleCondition.class.name, "jira.projectrole.id": "10001"]) { | |
log.debug("delete Condtiion from ${action.name}") | |
iterator.remove() | |
} | |
} | |
} | |
} | |
// save changes | |
workflowManager.updateWorkflow(user, draft) | |
// optionally, publish workflow | |
// remove to eyeball draft workflow before publishing manually | |
workflowManager.overwriteActiveWorkflow(user, workflowName) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment