How to check if certain user has “PERSONAL SPACE” permission using confluence java api?
When you say, “PERSONAL SPACE” permission, what do you exactly mean? Is it permission to create a personal space? If so, you might want to check out PermissionHelper, specifically PermissionHelper#canCreatePersonalSpace. There are other permission-related checks there that might come in handy for your use case. You might want to check ParmissionManager too, just in case.
thank you! One more question: how to grant global permission to a user?
To add to @iragudo’s answer - you might also want to consider if the user has a personal space already by going through the search service and using https://docs.atlassian.com/atlassian-confluence/6.5.2/com/atlassian/confluence/search/v2/query/HasPersonalSpaceQuery.html . (The user might already have created the space and then had the permission removed from them). It all really depends on what you’re trying to do.
Yes, it makes sense, thanks! And what about granting global permission, how to do it?
An administrator can do it by ranting the global permission “Personal Space”. See https://confluence.atlassian.com/conf59/global-permissions-overview-792499454.html
I mean what java class do i need to use to grant a user a global permission?
@o.polinkevych, check out GlobalPermissions, it has a grantPermission method that accepts a GlobalPermission (which is tagged as deprecated now) and a user. I have not tried this personally but it looks like a good place to start.
Another way would be to use the SpacePermissionManager which provides the deprecated method
savePermission(SpacePermission permission). A
SpacePermission without a space is a global permission in Confluence - sounds reasonable
So to check if a user has the
import com.atlassian.confluence.security.SpacePermission; import com.atlassian.confluence.security.SpacePermissionManager; ... @ComponentImport // inject this class somehow private final SpacePermissionManager spacePermissionManager; ... // the 2. param is the space, if null, it means a global permission final SpacePermission permission = SpacePermission.createUserSpacePermission(SpacePermission.PERSONAL_SPACE_PERMISSION, null, confluenceUser); // save the globale permission spacePermissionManager.savePermission(permission);
thank you a lot, it really works!
Unfortunately it does not seem to work as of now. The following exception was thrown by scriptRunner: unable to resolve class … GlobalPermission, GlobalPermissions