Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,233
Community Members
 
Community Events
168
Community Groups

Remove user permissions from Confluence space

Hello,

 

Could someone help me with ScriptRunner REST endpoint running on Confluence Server 7.2.0?

 

I just need to remove user permissions from space only. For example, I pass username and space key, and the script removes all permissions. I've been trying to use SpaceManager, SpaceManagerInternal but my context is always null. 

 

def space = spaceManager.getSpace(spaceKey)

SpacePermissionContext context = SpacePermissionContext.builder().build()

spacePermissionManager.removeAllUserPermissions(user,context)

 

The builder().build() doesn't work, and createDefault() as well.

How do I use this context in the right way?

 

Thanks.

1 answer

Hi Tomislav! 

I was able to get this working with the snippet linked here

For reference, I am using Confluence 7.8 with ScriptRunner 6.14.0 installed. 

Please let me know if this works for you! 

Thanks,
Lee

WW Rising Star Oct 21, 2021

I know it's a bit delayed, but could you please put the code in your answer here?  Unfortunately a lot of sites like Bitbucket are blocked by the company I work for.

Thanks!

Sure thing! Here's the script: 

/*
 * This script provides an example of how you can remove all space permissions from a single user
 
 * All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner 
 * license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed
 * or amended and must be included in any circumstances where the code snippet is shared by You or a third party." 
*/

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.internal.security.SpacePermissionContext
import com.atlassian.confluence.security.SpacePermissionManager
import com.atlassian.confluence.user.UserAccessor


def spacePermissionManager = ComponentLocator.getComponent(SpacePermissionManager)
SpacePermissionContext context = SpacePermissionContext.createDefault()

def userAccessor = ComponentLocator.getComponent(UserAccessor)
def user = userAccessor.getUserByName("<username>")

spacePermissionManager.removeAllUserPermissions(user, context)
WW Rising Star Oct 26, 2021

The removeAllUserPermissions method is deprecated now. 

Do you happen to know if we're able to use the SpacePermissionManagerInternal class that the documentation says replaces the old method?

I think I read somewhere that Internal classes are only for Atlassian use, but I could very well be wrong.

WW Rising Star Dec 06, 2021

I got the answer from our TAM (I don't remember what TAM stands for but it's our Atlassian liaison for those who don't have a TAM).

The deprecated methods in the SpacePermissionManager class are scheduled for deletion in Confluence 8.  However, from the TAM:

  • Confluence 8 is still a ways off and details are still being scoped.  If those methods do get removed, alternatives will be provided during the EAP period.  These alternatives would not be the internal methods (more on that below)
  • Access to the internal methods is blocked (so no idea why they would be listed as alternatives then, and I did ask that in a follow up).  Continue to use the deprecated methods until they are officially removed / replaced as mentioned above.
  • The developer pages will be updated as the new methods are available.

In summary, for now, use the SpacePermissionManager's deprecated methods, and before they are deleted, Atlassian will provide other, usable to people outside of Atlassian, methods.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events