Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Project Admin role users through Rest Endpoints in script runner

Manu Mishra
Contributor
February 8, 2018

I want to show the project admin role users in project summary page, though i have written the custom script to show the users under role: projet admin. However, there is a dependency to pass the "issue key" manually to get the users under role "10050" for that perticualler project . Though i dont want to pass the "issue key", it should dynamically get the "project key" from the project summary page. Here 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 delegate

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 issue1 = ComponentAccessor.getIssueManager().getIssueByCurrentKey("INT-1")
def actors = projectRoleManager.getProjectRoleActors(role, issue1.getProjectObject())
def usersInRole = actors.getApplicationUsers();
def projectRoleUsers = new StringBuffer()
for (g in usersInRole) {
projectRoleUsers.append(g.getName()+",")
projectRoleUsers.append("<br>")
}

def dlgHeader = """<div>
<b><u>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 User 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 + """
""" + projectRoleUsers + """
</div>
</section>
"""

Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}

 

1 answer

1 accepted

0 votes
Answer accepted
Alexey Matveev
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.
February 8, 2018

Rest Endpoint is situated in the server side. It can not know information about the page which is viewd by a user in his/her browser. That is why you need to pass the issue key.

Manu Mishra
Contributor
February 12, 2018

@Alexey Matveev Is there any other way a part from Rest Endpoints? My only requirement is to show the member of project admin role per project.

Alexey Matveev
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.
February 12, 2018

You should create a web panel in ScriptRunner. Kindly have a look here:

https://scriptrunner.adaptavist.com/5.3.1/jira/fragments/WebPanel.html

Manu Mishra
Contributor
February 12, 2018

@Alexey Matveev Ok, So if i provide the link into the provider class/script to execute. But still i need to pass the issue key right? So do you have an example code to put into the file where i dont need to pass the issue key in variable? Or second option would be to pass the issue key's in "condition section" but that will be quite difficult. Because there are more then 100 projects.

Alexey Matveev
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.
February 12, 2018

You do not need an issue key. You need to know the project. You can query the project by

jiraHelper.project

You can see it in the example in the ScriptRunner documentation.

Dan27
Contributor
November 11, 2018

Hi @Alexey Matveev ,

I made my own script , that made a dialog like in here.

It worked good, until we upgrade the script runner.

Now, the dialog opens in a different page (not as a pop up)..

like this:

pic11.JPG 

I need this dialog to open like a pop up on the view screen of the issue.

 

Thanks,

Daniel

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events