The Custom "Scripted Field" from Scriptrunner is used to display external url link to the current issue. We do want to put other info in there, but for testing this will do. The script below is stripped to bare and works fine as shown.
Problem is we want it only to be placed in a ticket when the currentUser is a member of a certain group (ex: tpsc-intern). The userUtil construction to compare works. What doesnt work is de "def currentUser" line. From what we read its a version 6 solution and de new JIRA 7 uses the "jira.security" library now for ApplicationUser.getUser(), but i cannot import that one.
Can someone tell me how to fix the below script?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.RendererManager
import com.atlassian.jira.ComponentManager
// new lib does not work
//import com.atlassian.jira.security
def componentManager = ComponentManager.getInstance()
def info = null
// should work? but doesnt
//def currentUser = ComponentAccessor.JiraAuthenticationContext.getLoggedInUser()
//if (! ComponentAccessor.userUtil.getGroupNamesForUser(currentUser.name).contains("tpsc-intern")) {
// works
//info = "groups: "+ComponentAccessor.userUtil.getGroupNamesForUser("tim")
info = "https://my.patientsafety.com/jira/rest/api/2/issue/"+issue.key
def rendererManager = ComponentAccessor.getComponent(RendererManager.class)
def fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem("timeinfo")
def renderer = rendererManager.getRendererForField(fieldLayoutItem)
renderer.render(info, null)
//}
The only difference there is getting the current user, vs hardcoding the name "tim", I don't see why that would not work. Can you explain how it doesn't work? ie error, wrong result etc.
I would consider using:
def groupManager = ComponentAccessor.getComponent(GroupManager) def currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser() groupManager.getGroupNamesForUser(currentUser).contains(...)
the reason being is it lets you pass a user object not a name.
Sometimes in the API they say pass a name, but I think they mean use a key.
Thanks that was a pointer to the solution. Problem was in the changes of version 7 concerning "User -> ApplicationUser" type changes. Fixed using:
def String username = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getName()
if (ComponentAccessor.userUtil.getGroupNamesForUser(username.toString()).contains('tpsc-intern')) {
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.