I have a plugin that needs to get all the groups, and then any additional individual users that have read access to a page.
I have looked at the permissionManager and it will tell me if a single user can access the page. But i havent been able to find anything that takes a page and returns all users/groups that can access it.
I know i could implement a brute force approach and for the page first generate a list of all users and then ask if each user can access the page. However at its simplest this masks which groups have access. It could im guessing be enhanced to first ask if a group has access then additionally ask all users not in groups with access if they have permission.
However this is clearly the wrong way around and a less than optimal approach if the process needs to be performed over multiple pages... for example all pages in a space.
I am assuming that there is a better and more efficient approach to this. Perhapes the permission manager does something similar internally?
Can someone please point me in the right dirrection.
Community moderators have prevented the ability to post new answers.
The Solution is to usethe ContentPermissionManager.
Set<ContentPermission> permissions = contentPermissionManager.getViewContentPermissions(page);
My guess is that there is no method that's going to return all users who can view a specified page, because it would be innefficient to store that information. It's much more efficient from the database side to take a user name and decide if that user can access it. You can imagine how big a few additional tables in the DB that stores this info would be.
The same logic probably applies to groups. However, since you likely have far fewer groups than users, it might be feasible to brute force them.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.