It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage
Highlighted

Project Admin role users through Rest Endpoints in script runner

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

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you