How can we efficiently get a Jira user's direct groups in a system with nested groups?
I'm able to get them inefficiently by getting all of the user's groups (getGroupsForUser), then checking the direct members of each group (getDirectUsersInGroup), and looping through to see if the specific user (by matching names) is a direct member.
Is there a better way to do this with fewer calls and less looping.
CrowdService.isUserDirectGroupMember can be used to make the function more efficient
Hi @Steve Kamens -
There is no direct way to do this in the Jira's API. If you have ScriptRunner, I'd recommend reviewing this community post that describes how you can do this with the apps functionality:
How to get nested groups in Jira REST API
Hope this helps!
Jennifer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @J van Leeuwen ,
Is there any method to get list of users who have direct access to group, currently I am using the following script, it listing all users including sub-group members also.
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
def groupManager = ComponentAccessor.getGroupManager()
def users = groupManager.getUsersInGroup("groupname")
Can you please help , how we can list direct access users from respective group
FYI @J van Leeuwen
Thanks in advance!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Rao B @J van Leeuwen @Steve Kamens
use
def users = groupManager.getDirectUsersInGroup(groupManager.getGroup("grp-name"))
To get users who have direct access to the specified Group
Here you can find the complete code to get users names of users who have directaccess
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import java.text.SimpleDateFormat;
import java.util.Date;
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
def groupManager = ComponentAccessor.getGroupManager()
def users = groupManager.getDirectUsersInGroup(groupManager.getGroup("group-name"))
StringBuilder builder=new StringBuilder()
builder.append("<table border = 1><tr><td><b>UserName</b></td></tr>")
users.each{
Long lastLoginTime = loginManager.getLoginInfo(it.username).getLastLoginTime()
String activeStatus=it.active
if(activeStatus=="false")
builder.append("")
else if(lastLoginTime==null)
builder.append("<tr><td>"+it.username+"</td></tr>")
else{
Date date=new Date(lastLoginTime);
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
String dateText = df2.format(date);
builder.append("<tr><td>"+it.username+"</td></tr>");
}
}
builder.append("</table>")
return builder
Regards,
Muhammad Atib Junaid
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.