Is there a way to discover if the current user can publish content to a specific Library using either Apex or Javascript?
Use Case
I have a shared library (DeveloperName = Shared_Forms
) that many users have access to. A subset of those users can publish content there. In my current page, I want a link to the library to appear if a user can publish to that library.
Problem
A User can publish content to that library because they have a ContentWorkspaceMember
record with ContentWorkspacePermission.PermissionsAddContent = true
or because they are in a Public Group (Group
) which has a ContentWorkspaceMember
record with ContentWorkspacePermission.PermissionsAddContent = true
. As you probably know, figuring out Group Membership properly is not a straightforward task
For example, a User can have a Role (Subdivision lead) which is a subordinate of another Role (Division lead) which has a related Group of type RoleAndSubordinates and that Group is a member of a Group that's a member of my current Group).
And let's not even talk about the doesIncludeBosses
option.
Question
In order to avoid recursive SOQL queries and redoing Salesforce's whole permissions model, I was wondering if there's a way I can access any of the following, as they would all get me very close to my goal:
- Can logged in User X publish content in Library L? (this is my ultimate goal)
- Who are all the users who have
PermissionsAddContent
in Library L? - What Groups is logged in User X in (recursively)?
- Who are all the users who have ContentWorkspacePermission P in Library L?
try and publish - if success, then rollback; if exception, then you know user can't publish
technique