Hello guys,
Until recently we were on jira Server 8.22 and we were using this script in scriptunner console to copy user groups from A user to B user:
import
com.atlassian.jira.component.ComponentAccessor
import
com.atlassian.jira.security.roles.ProjectRoleActor
import
com.atlassian.jira.security.roles.ProjectRoleManager
import
com.atlassian.jira.bc.projectroles.ProjectRoleService
import
com.atlassian.jira.security.GlobalPermissionManager
import
com.atlassian.jira.security.Permissions
import
com.atlassian.jira.user.util.UserUtil
import
com.atlassian.jira.util.SimpleErrorCollection
import
org.apache.log4j.Category
import
com.atlassian.jira.project.Project;
import
java.util.ArrayList;
def
userManager = ComponentAccessor.getUserManager()
def
groupManager = ComponentAccessor.getGroupManager()
def
groups = groupManager.getGroupsForUser(
"A"
)
// user à copier
def
uu = ComponentAccessor.getUserUtil()
def
user = uu.getUser(
"B"
)
// user prenant la copie
groups.
each
{ group ->
def
grplec = uu.getGroupObject(group.name)
groupManager.addUserToGroup(user,grplec)
}
The script was working just fine before upgrading to jira server 9.4.4
Now we get this error:
"
Something went wrong: MissingMethodExceptionNo signature of method: com.atlassian.jira.user.util.UserUtilImpl.getUser() is applicable for argument types: (String) values: [B] Possible solutions: getAt(java.lang.String)"
Does anyone has a solution?
Hi, @Andra Marilena SANDULEASA
You're welcome :) Slightly optimized and refactored script.
/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
UserManager userManager = ComponentAccessor.getUserManager()
GroupManager groupManager = ComponentAccessor.getGroupManager()
ApplicationUser userA = userManager.getUserByName("A") as ApplicationUser
ApplicationUser userB = userManager.getUserByName("B") as ApplicationUser
Collection<Group> groups = groupManager.getGroupsForUser(userA)
groups.each { Group group ->
groupManager.addUserToGroup(userB, group)
}
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.