Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

scriptrunner: duplicate a group's permissions

Hello!

Looking for a little help. I am creating a scriptrunner script to duplicate a group. I was able to create a new group and duplicate the users to it with the script below...

import com.atlassian.confluence.security.login.LoginManager
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.GroupManager

/* This script takes users from the group with oldGroupName and adds them to the group with newGroupName. If newGroupName doesn't exist
it is created.*/

def groupManager = ComponentLocator.getComponent(GroupManager)
def loginManager = ComponentLocator.getComponent(LoginManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)

// define the old group and new group USERS SHOULD MODIFY THESE VALUES!
def newGroupName = "group1"
def oldGroupName = "group2"

// Get the new group if it already exists. If it does not exist, create it.
def newGroup = groupManager.getGroup(newGroupName) ?: groupManager.createGroup(newGroupName)

// Get the group you will be copying the users from.
def oldGroup = groupManager.getGroup(oldGroupName)
def users = groupManager.getMemberNames(oldGroup)

users.each { userName ->
def user = userAccessor.getUserByName(userName)
if (user) {
log.info "Add user ${user.name} to the group: $newGroupName"
groupManager.addMembership(newGroup, user)
}
}

I am now trying to figure out how to duplicate the group's permissions. Found the following method that gets a list of all the permissions for a group.

https://docs.atlassian.com/atlassian-confluence/6.2.1/com/atlassian/confluence/security/SpacePermissionManager.html#getAllPermissionsForGroup-java.lang.String-

But I cannot for the life of me find out how to set these permissions for the new group. Does anyone have any suggestions?

 

Thanks!

1 answer

0 votes

Try something like this

import com.atlassian.sal.api.component.ComponentLocator
import
com.atlassian.confluence.security.SpacePermission
import com.atlassian.confluence.security.SpacePermissionManager
def spacePermissionManager = ComponentLocator.getComponent(SpacePermissionManager)
def oldGroupName = 'yourOldGroupName'
def newGroupName = 'yourNewGroupName'
spacePemrissionmanager.getAllPermissionForGroup(oldGroupName).each{oldPerm->
def newPerm =SpacePermission.createGroupSpacePermission(oldPermission.type, oldPerm.space, newGroupNamae)
spacePermissionmanager.savePermission(newPerm)
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence Cloud

Introducing Confluence Cloud for Microsoft Teams (Available for Preview!)

Hi Atlassian Community, Remote work has shifted how teams collaborate, and we’ve heard from many of you that Microsoft Teams has become mission critical to many of your workflows, from how you chat...

2,533 views 21 21
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you