I have a shared transition from two statuses (e.g. "open" and "verified") to one (e.g. "ready").
I want to enable users to use the transition when the source status is "verified".
Only users of two project roles (e.g. "admin", "heros") should be allowed to use the transition from "open" ro "ready" without going over "verified".
I set up the following Groovy script to accomplish the first part but struggle with the roles.
def project = issue.getProjectObject();
log.debug( project.getLeadUserKey() );
def verifiedStatusId = "10008";
// God mode (check for Project Leads or Administrators)
// Regular mode (check if source status is "Verified")
if ( issue.getStatusId() == verifiedStatusId ) {
return true;
}
return false;
Currently I see no way to determine the project roles assigned to the current user by the user object itself. Also the getProjectObject() just returns very generic methods (e.g. project name) which are irrelevant for my task.
How to I check if the current user is in one or more of two project roles of the issue of the project?
You can receive the current user with
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggiedInUser()
then you can use
ComponentAccessor.getGroupManager().isUserInGroup(user, "admin") || ComponentAccessor.getGroupManager().isUserInGroup(user, "heroes")
That was for groups. For roles it will be like this
ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class);
projectRoleManager.isUserInProjectRole(ApplicationUser user, ProjectRole projectRole, Project project)
Use something like this if you're using Scriptrunner Behaviours.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
if (underlyingIssue != null) {
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def componentManager = ComponentManager.getInstance();
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class) as ProjectRoleManager
def role = projectRoleManager.getProjectRole("XXXXX") as ProjectRole
if (currentUser != null && role != null && projectRoleManager.isUserInProjectRole(currentUser, role, underlyingIssue.getProjectObject()) ) {
return true
}
else return false
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.