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

Confluence page restrictions scriptrunner

Alexander_Kaemmer March 26, 2020

Hi,

I created a confluence space for a empolyee blog. Every employee shall be able to write a blog post, but only the author and a moderator group should be able to edit these posts.

This doesn't seem possible without scriptrunner.
So I think a custom event listener for the "BlogPostCreateEvent" would be the right way to trigger a script, that will set the restrictions to these values:
- view everyone
- edit author user
- edit moderator group

Do you think this is the right way?
Is there an example for setting page restrictions through scriptrunner?
There is a built-in script to set page restrictions, but I can't see the source code of it.

 

Thank you

2 answers

1 vote
Tiffany Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2020

Hi Alexander!

This script should be pretty close to what you're looking for when creating your custom event listener:

import com.atlassian.confluence.core.ContentPermissionManager
import com.atlassian.confluence.pages.AbstractPage
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.security.ContentPermission
import com.atlassian.confluence.user.ConfluenceUser

import static com.atlassian.confluence.security.ContentPermission.EDIT_PERMISSION
import static com.atlassian.confluence.security.ContentPermission.VIEW_PERMISSION

def contentPermissionManager = ComponentLocator.getComponent(ContentPermissionManager)

def blogPost = event.blogPost
def author = blogPost.creator

def everyonePermission = ContentPermission.createGroupPermission(VIEW_PERMISSION, "confluence-users")
def authorPermission = ContentPermission.createUserPermission(EDIT_PERMISSION, author)
def moderatorPermission = ContentPermission.createGroupPermission(EDIT_PERMISSION, "confluence-administrators")

contentPermissionManager.setContentPermissions(
[
(VIEW_PERMISSION): [everyonePermission],
(EDIT_PERMISSION): [authorPermission, moderatorPermission]
], blogPost
0 votes
Jenna Davis
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 22, 2020

Hello!

I believe that if you want to use a listener to do this you'll need to take a look at the ContentPermissionManager and PagePermissionManager classes in order to set the permissions. I don't believe there's an example, but if you have trouble getting something to work feel free to post your code up here and I'll give you some pointers. :)

Jenna Davis

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events