How to get and issue.Issue from an issue.IssueImpl

Va man June 8, 2023

Hello everyone,

 

I'm fairly new to Groovy for Jira, and I came across a strange case

I need to know if an user has rights to a given project/issue. I then created following code :

///

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.plugin.ProjectPermissionKey
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager;

IssueManager issueManager = ComponentAccessor.getIssueManager()
def issueobj = Issues.getByKey('BLA-136')

Issue issue = issueManager.getIssueObject(issueobj.id)

def appUser = ApplicationUser.hasPermission(new ProjectPermissionKey("BROWSE_PROJECTS"), issue )
///

But when I execute I got 

groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.user.ApplicationUser.hasPermission() is applicable for argument types: (com.atlassian.jira.security.plugin.ProjectPermissionKey, com.atlassian.jira.issue.IssueImpl) values: [BROWSE_PROJECTS, BLA-136] Possible solutions: hasPermission(com.atlassian.jira.security.plugin.ProjectPermissionKey, com.atlassian.jira.project.Project), hasPermission(com.atlassian.jira.security.plugin.ProjectPermissionKey, com.atlassian.jira.issue.Issue), hasPermission(com.atlassian.jira.permission.GlobalPermissionKey) at Script460.run(Script460.groovy:12)

 

I don't know how to hop from com.atlassian.jira.issue.IssueImpl to com.atlassian.jira.issue.Issue. It's the same if I try to load the project, I even tried mutableIssue but still the same result. I tried to use directly issueobj but same result too.

 

Do you have any indication or documentation I may have missed on how to convert that into the type I need ? 

 

Regards,

1 answer

1 accepted

1 vote
Answer accepted
Evgenii
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.
June 8, 2023
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.PermissionManager
import com.atlassian.jira.security.plugin.ProjectPermissionKey
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserManager

IssueManager issueManager = ComponentAccessor.getIssueManager()
UserManager userManager = ComponentAccessor.getUserManager()
PermissionManager permissionManager = ComponentAccessor.getPermissionManager()

Issue issue = issueManager.getIssueObject('ABC-123') as Issue
ApplicationUser appUser = userManager.getUserByName('dummy')

boolean hasPerm = permissionManager.hasPermission(new ProjectPermissionKey("BROWSE_PROJECTS"), issue, appUser)
Va man June 8, 2023

Thanks, it works ! 

So what I missed here was to cast into an Issue type using "as Issue" ? 

Evgenii
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.
June 8, 2023

No, it will work and without "as Issue"

Your errors are:

- wrong way of getting issue object

- wrong way of checking permissions.

ApplicationUser - is abstract and don't have hasPermission function. You have to add new variable with object type Application User, what I made at line 14.

And then you have to use permissionManager, that checks permissions of user

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events