I am trying to set replace group permissions on all pages from "confluence-k-m" to "confluence-v-m" with sciptrunner.
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.core.ContentPermissionManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.spaces.SpaceManager
import static com.atlassian.confluence.security.ContentPermission.EDIT_PERMISSION
import static com.atlassian.confluence.security.ContentPermission.VIEW_PERMISSION
import com.atlassian.confluence.security.ContentPermission
def ignoreSpaces = ['~lierse', '~martens_e', 'GF']
def oldGroup = "confluence-k-m"
def newGroup = "confluence-v-m"
def pageManager = ComponentLocator.getComponent(PageManager)
def spaceManager = ComponentLocator.getComponent(SpaceManager)
def contentPermissionManager = ComponentLocator.getComponent(ContentPermissionManager)
def spaces = spaceManager.getAllSpaces()
log.warn(spaces)
for (int j = 0; j < spaces.size(); j++){
log.warn(spaces[j])
def space = spaces[j]
def allPagesFromSpace = pageManager.getPages(space, false)
for (def page : allPagesFromSpace) {
log.warn('############################################')
def pageTitle = page.getTitle()
log.warn(page.getSpace())
log.warn(pageTitle)
def latestPage = page.getLatestVersion()
log.warn(page.isDeleted())
def permissionSet = contentPermissionManager.getContentPermissionSets(latestPage, EDIT_PERMISSION)
log.warn(permissionSet)
def perm_edit = []
permissionSet.toArray().each { permission ->
def newPermission = new ContentPermission()
permission.userNames.each {
name ->
perm_edit.add(newPermission.createUserPermission(EDIT_PERMISSION, name))
}
permission.groupNames.each{
name ->
if (name != oldGroup){
perm_edit.add(newPermission.createGroupPermission(EDIT_PERMISSION, name))
} else {
perm_edit.add(newPermission.createGroupPermission(EDIT_PERMISSION, newGroup))
}
}
}
def permissionSet2 = contentPermissionManager.getContentPermissionSets(latestPage, VIEW_PERMISSION)
log.warn(permissionSet2)
def perm_view = []
permissionSet2.toArray().each { permission ->
def newPermission = new ContentPermission()
permission.userNames.each {
name ->
perm_view.add(newPermission.createUserPermission(VIEW_PERMISSION, name))
}
permission.groupNames.each{
name ->
if (name != oldGroup){
perm_view.add(newPermission.createGroupPermission(VIEW_PERMISSION, name))
} else {
perm_view.add(newPermission.createGroupPermission(VIEW_PERMISSION, newGroup))
}
}
}
//if (pageTitle !in ignore){
def permissionsToSet = [:]
if (perm_edit) {
permissionsToSet[EDIT_PERMISSION] = perm_edit
}
if (perm_view) {
permissionsToSet[VIEW_PERMISSION] = perm_view
}
log.warn(latestPage.getTitle() != "")
if (!permissionsToSet.isEmpty() && !space.isPersonal() && space.getKey()!in ignoreSpaces && pageTitle != "" && !latestPage.isDeleted() && !latestPage.isDraft()) {
log.warn("Setting permissions for page: ${latestPage.getTitle()}")
contentPermissionManager.setContentPermissions(permissionsToSet, latestPage)
} else {
log.error("No valid permissions to set for page: ${latestPage.getTitle()}")
}
}
}
The Problem I have is that it runs perfectly on 100+ pages. But at some pages i ll get this error:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.