2

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?
1

Admittedly a hack but is "future proof" to any additional complexities that SFDC might add to the library permissioning model or until a built-in method exists to tell you what you need.

In the Apex ...

public Boolean isPublishable() {
  Database.Savepoint sp;
  try {
    sp = Database.setSavepoint();
    ... insert some strawperson doc into library of interest
    Database.rollback(sp); // worked, must be publishable, roll it back
    return true;
  }
  catch (Exception e) {return false;}
}
|improve this answer|||||
  • Yeah, that's basically what I settled on. It makes my skin crawl. I wish there was a more robust API in Apex that could answer these domain-specific questions. Especially around permissions and sharing. – Charles Koppelman Dec 11 '19 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.