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?
3
  • related: salesforce.stackexchange.com/questions/166396/… Commented Dec 9, 2019 at 19:58
  • 1
    there's alway the try and publish - if success, then rollback; if exception, then you know user can't publish technique
    – cropredy
    Commented Dec 9, 2019 at 22:34
  • @cropredy That sort of coding makes me feel dirty, but I find Salesforce leaves me with no other option for many permission-y things Commented Dec 10, 2019 at 13:43

1 Answer 1

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;}
}
1
  • 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. Commented Dec 11, 2019 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .