I want to show the list of all Project Admin "Users" on project summary page. As i have created REST Endpoints and below is my code.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.user.ApplicationUsers
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import com.atlassian.jira.bc.projectroles.DefaultProjectRoleService
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
@@BaseScript CustomEndpointDelegate delegat
ProjectAdmins() { MultivaluedMap queryParams ->
// get a reference to the current page...
// def page = getPage(queryParams)
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
long projectRoleId = 10050 // ID of Automatic Watcher project role
def role = projectRoleManager.getProjectRole(projectRoleId)
def actors = projectRoleManager.getProjectRoleActors(role, Issue.getProjectObject())
def usersInRole = actors.getApplicationUsers();
def projectPermissionList = new StringBuffer()
projectPermissionList.append("Test value; ")
//for (g in usersInRole) {
//projectPermissionList.append(g.getName()+"; ")
//groupList.append("<br>")
//}
def dlgHeader = """<div>
<b><u>The Puspose of this Diaglog is print the Project Admins</u></b>
</div>"""
def dialog =
"""<section role="dialog" id="sr-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" aria-hidden="true" data-aui-remove-on-hide="true">
<header class="aui-dialog2-header">
<h2 class="aui-dialog2-header-main"><b>Project Admin List</b></h2>
<a class="aui-dialog2-header-close">
<span class="aui-icon aui-icon-small aui-iconfont-close-dialog"><b>Close</b></span>
</a>
</header>
<div class="aui-dialog2-content">
""" + dlgHeader + """
""" + projectPermissionList + """
</div>
</section>
"""
Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}
The Above script is not working though there is no compilation error. But the script above is not returning the desired outputs. As far as my understanding says there is an error in the line
def actors = projectRoleManager.getProjectRoleActors(role, Issue.getProjectObject())
Please help me debugging the script. If possible can you modify the script.
Issue.getProjectObject() will not work. You need to get a reference to an issue first. For example
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("STAR-1")
and then you can use
def actors = projectRoleManager.getProjectRoleActors(role, issue.getProjectObject())
Thanks @Alexey Matveev The script is working untill
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
long projectRoleId = 10050 // ID of Automatic Watcher project role
def role = projectRoleManager.getProjectRole(projectRoleId)
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("DevOps")
What you are referring <("STAR-1")>. Do i have to pass the "issue key" (e.g. devops-1).
So when i will be passing the issue key, will it return the project role admin users?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should provide "DEVOPS-1". It should work after it. Of course the issue with the key DEVOPS-1 must exist in your Jira instance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So do i have to pass the key very time?
My requirement is whenever someone walks into any project summary page they should click on the button "Project Admin" (Right Corner) and that will display the list of Project Admin Role "Users" in comma delimited string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you look at the URL the project is "DevOps" and under the Projet Roles Admin there is only one user (Manoj Mishra). So my requirement is whenever someone click one the Project Admin button in the project summary page. He should only get one User which is (Manoj Mishra). But the scripts is returning all the users who have Project Role Admin permission irrespective of any projects. I only want the users to be returned against the projects.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I really do not understand the architecture what you are doing there. Your question was about the error in your script. I answered about the error. The problem is that you should initialize the issue. How you do it depends on how the whole thing, you are developing, works.
If you want your code to work, you should pass to your code either a project key or issue key and get the project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.