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

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

Confluence page restrictions scriptrunner

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

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

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
Community showcase
Published in Confluence

Confluence Mythbusters: Does Atlassian even use Confluence?

Hi, Confluence collaborators! As part of #Confluence-Collaboratory month, we’ve created a very special Mythsbusters segment, where we're dive into an interesting myth and uncover the truth behind i...

1,690 views 7 31
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