Show the list of all Project Admin Role "users" on project summary page.

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.

1 answer

1 accepted

1 vote
Alexey Matveev Community Champion Dec 21, 2017

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 should provide "DEVOPS-1". It should work after it.  Of course the issue with the key DEVOPS-1 must exist in your Jira instance

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.

@Alexey MatveevProjectRole.JPG

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.

Alexey Matveev Community Champion Dec 21, 2017

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. 

Thanks @Alexey Matveev for your kind help.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Mission-critical battery manufacturer fulfills FAA software requirements with Commit Policy Plugin

EaglePicher Technologies is a leading manufacturer of battery systems for diverse industries like defense, aviation, space or medical. As they operate in highly regulated industries, keeping a clear ...

178 views 0 2
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you