groovy runner validator:limit to specified permission using Script Validator

fabby November 4, 2012

i want to limit specified people(who is assignee or with 'SWTL' role or wiht 'Administer Projects' permission) to Resolve Issues.

the first two condition i have test OK :

currentUser == issue.assignee || isUserMemberOfRole('SWTL')

the third one ,i try to use hasPermission('Administer Projects') in Condition Tester

returns:

javax.script.ScriptException: groovy.lang.MissingMethodException:

No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.hasPermission() is applicable for argument types:

(java.lang.String) values: [Administer Projects]

anyone knows the correct syntax of permission validator in groovy runner?

1 answer

1 accepted

0 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 4, 2012

> anyone knows the correct syntax of permission validator in groovy runner?

You mean the correct API to use in either java or groovy? There is no "different API" for groovy by the way.

import com.atlassian.jira.security.Permissions

componentManager.getPermissionManager().hasPermission(Permissions.ADMINISTER, currentUser)

(untested)

fabby November 4, 2012

hi,Jamie

what i want is Builtin Scripts of Groovy runner Plugin.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 4, 2012

You can use what I gave you for that

fabby November 6, 2012

Thanks very much ,Jamie

i used below code ,and succeed.

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.security.Permissions

ComponentManager componentManager = ComponentManager.getInstance()

currentUser == issue.assignee || isUserMemberOfRole('SWTL') || componentManager.getPermissionManager().hasPermission(Permissions.PROJECT_ADMIN,issue, currentUser)

i have to add " import com.atlassian.jira.ComponentManager" and "ComponentManager componentManager = ComponentManager.getInstance()" ,otherwise in Condition Tester will returns

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: componentManager for class: Script23

in com/onresolve/jira/groovy/canned/utils/ConditionUtils.groovy of Groovy Runner Plugin

has already define "ComponentManager componentManager = ComponentManager.getInstance()",i am wonder why i have to redefine 'componentManager' ?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2012

Yeah you're correct, I probably only add componentManager to the binding recently, and was working with a newer version than you have.

fabby November 7, 2012

thansk Jamie.

my jira version is 4.4.1 and installed groovy runner version 2.0.7

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events