I have a requirement to find all the group of user "A" and align user "B" with all those groups. Basically want to do mirror.
Please help what could be the best solution for this or if any scriptrunner code that would be very helpful.
Thanks in Advance. Appreciate for your quick response.
A combination of the examples at https://library.adaptavist.com/entity/identify-the-groups-of-a-user and https://library.adaptavist.com/entity/remove-specified-users-from-a-group (tweaked from "delete" to "add") should do the job.
Thanks Nic for this. It is very helpful. I am very new to scriprunner and sure i am doing some mistake. In below code i am able to get the group of user "mpan" but not able to add to user "mpan1". Could you please help me with the code. Thanks in advance.
import com.atlassian.jira.component.ComponentAccessor
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
def groupManager = ComponentAccessor.groupManager
def username = "mpan"
def groupNames = groupManager.getGroupNamesForUser(username) as String[]
"The groups for user '${username}' are: ${groupNames.join(' ')}"
def usertoadd1= "mpan1"
groupNames.each {
def usertoadd = userManager.getUserByName(it)
userUtil.addUserToGroup(usertoadd1, groupNames)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the delay!
I think there are two problems:
You've converted the groups to strings (which is fine for your log message) and then tried to use those strings instead of the group objects the addUserToGroup expects
Similarly, usertoadd1 contains a string, but the add to group call needs an ApplicationUser
So you're not giving the last line any data it can work with. Check https://docs.atlassian.com/software/jira/docs/api/8.18.1/com/atlassian/jira/user/util/UserUtil.html for the docs on what it expects
The group one can be fixed by dumping the "as String" from the end. The user bit needs to be fixed by working out what ApplicationUser object "mpan1" is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nic this worked perfectly now. Thank you so much.
Do we have any similar code for Bitbucket also ?
Thanks for your time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've not tried user management in Bitbucket. I suspect the principle of "there is a user object" is the same but I don't know how to use it. I'd start at https://docs.atlassian.com/bitbucket-server/javadoc/7.15.1/api/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.