It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

scriptrunner groovy check whether user has permission in a project

There are a lot of old answers out there and only a few obscure answers using the current API

https://community.atlassian.com/t5/Answers-Developer-Questions/Script-Runner-Post-Function-Permission-Checking/qaq-p/542213 is the old answer and it would be so cool to be able to just add a new answer.

1 answer

1 accepted

0 votes
Answer accepted
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.plugin.ProjectPermissionKey

def permissionManager = ComponentAccessor.getPermissionManager()
def hasPerm = permissionManager.hasPermission(new ProjectPermissionKey("TRANSITION_ISSUES"), issue, currentUser)

 The list of permissions is in https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/permission/ProjectPermissions.html

This works in conditions and validators

Hallo Martina,

I am unfortunately a beginner in groovy/java and can't get the code snippet to run.
I get the error "cant find matching method: ProjectPermissionKey" when I run it in ScriptRunner Console.

 

def currentUser = 'User1'
def issue = 'Test-1'

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.plugin.ProjectPermissionKey

def permissionManager = ComponentAccessor.getPermissionManager()
def hasPerm = permissionManager.hasPermission(ProjectPermissionKey("TRANSITION_ISSUES"), issue, currentUser)
//"ADD_COMMENTS"

 

What am I doing wrong?

Gruß Thomas

Issue isn't just a string. In conditions and Validators it's properly set. In the console you have to get the issue object yourself.

see getIssueObject('your Issue ID') 

If you want this for a condition or validator, I just create a simple condition and do previews and asserts right in there to get it right.

just found an example where I get an issue in teh Console:

 

def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueByCurrentKey(issueKey)

Sorry, but I change it and its show the same error:

groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.ProjectPermissionKey() is applicable for argument types: (java.lang.String) values: [TRANSITION_ISSUES] at Script209.run(Script209.groovy:13)

I run JIRA Server 7.13.x

 

Unbenannt.png

You are on your own then. Have you tried it in workflow?That's where this worked for me in 7.13

I found a solution for me:

def permissionManager = ComponentAccessor.getPermissionManager()
if (permissionManager.hasPermission(ProjectPermissions.ADD_COMMENTS, issue, reporter) ){

xxx

}

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you