Hello Team,
Kindly share API to remove specific user from project roles and board administrators using groovy script runner or through other ways to implement it inside plugin.
Thanks and Regards,
Jyoti
Hi @Jyoti Kumari,
I've found two scripts from the Adaptavist library that might help:
Hi @Jyoti Kumari
You can use this script to replace a specific administrator on all boards that have one:
import com.atlassian.greenhopper.service.rapid.view.BoardAdminServiceimport com.atlassian.greenhopper.service.rapid.view.RapidViewServiceimport com.onresolve.scriptrunner.runner.customisers.JiraAgileBeanimport com.onresolve.scriptrunner.canned.util.OutputFormatterimport com.atlassian.greenhopper.model.rapid.BoardAdminimport com.atlassian.greenhopper.model.rapid.RapidViewimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.user.util.UserManagerimport com.atlassian.jira.user.ApplicationUser@JiraAgileBean BoardAdminService boardAdminService@JiraAgileBean RapidViewService rapidViewServiceUserManager userManager = ComponentAccessor.getUserManager()ApplicationUser jiraAdmin = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()ApplicationUser oldUser = userManager.getUserByName("old_username") // <-- insert the username of the current user.ApplicationUser newUser = userManager.getUserByName("new_username") // <-- insert the username of the new user.Map<List<String>, List<String>> boardChanges = new HashMap<>()BoardAdmin newBoardAdmin = BoardAdmin.builder().type(BoardAdmin.Type.USER).key(newUser.key).build()List<RapidView> allBoards = rapidViewService.getRapidViews(jiraAdmin).getValue()allBoards.each { RapidView board -> try { List<BoardAdmin> boardAdmins = boardAdminService.getBoardAdmins(board) List<BoardAdmin> disabledBoardAdmin = boardAdmins .findAll { BoardAdmin it -> it.type == BoardAdmin.Type.USER } .findAll { BoardAdmin it -> userManager.getUserByKey(it.key) == oldUser } if (disabledBoardAdmin) { List<BoardAdmin> newAdmins = (boardAdmins - disabledBoardAdmin) .findAll { BoardAdmin it -> it.key != newBoardAdmin.key } .collect { BoardAdmin it -> BoardAdmin.builder().type(it.type).key(it.key).build() } + newBoardAdmin boardAdminService.updateBoardAdmins(board, jiraAdmin, newAdmins) boardChanges.put([board.name, board.id.toString()] , [boardAdmins.collect{it.key}.toString(), newAdmins.collect{it.key}.toString()]) } } catch (Exception ignored) {}}OutputFormatter.markupBuilder { if (boardChanges) { ul { boardChanges.each {str -> li("Board name: " + str.key[0] + ", Board id: " + str.key[1]) ul{ li("Old board admins: " + str.value[0]) li("New board admins: " + str.value[1]) } span{} } } } else { p('No changes to be made') }}
Thank you @Kseniia Trushnikova
It helps a lot for removing project role and board Admin.
Hello @Vitali Basarevski ,
Thank you so much,It is working perfectly .
It looks like you're new here. Sign in or register to get started.