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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
just found an example where I get an issue in teh Console:
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueByCurrentKey(issueKey)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are on your own then. Have you tried it in workflow?That's where this worked for me in 7.13
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found a solution for me:
def permissionManager = ComponentAccessor.getPermissionManager()
if (permissionManager.hasPermission(ProjectPermissions.ADD_COMMENTS, issue, reporter) ){
xxx
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.