Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Project Admin role users through Rest Endpoints in script runner

Manu Mishra February 7, 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 example 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()
}

 

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events