I would like to be able to retrieve the permissions for specific folders in a document library via JSOM. Specifically, I would like to be able to use JS to determine if the active folder that the user has navigated to (ie: Documents/SubFolder) is accessible by "everyone" or not.

I have figured out to how pull the folder path from the URL query string and I can access the folder object using getFolderByServerRelativeUrl; however, I am having difficulty figuring out how to list the permissions for that folder. I have found other questions that address breaking permissions and assigning new permissions, but nothing that identifies how to get the current permissions. From my research, I was thinking I may need to use hasPermissions to get what I wanted, but I haven't had any luck with that yet.

Current Code:

$(document).ready(function() {
var currentURL = window.location.search;
var urlQuery = currentURL.toString();
    clientContext = new SP.ClientContext.get_current();

function getFolderPermissions(folderPath) {
var cleanFolderPath = decodeURIComponent(folderPath.split("=")[1].split("&")[0]);
var web = clientContext.get_web(); 
var folder = web.getFolderByServerRelativeUrl(cleanFolderPath);
var currentFolderAssignments = web.getFolderByServerRelativeUrl(cleanFolderPath).get_listItemAllFields().get_effectiveBasePermissions();
clientContext.load(currentFolderAssignments, 'EffectiveBasePermissions');
    function() {    
    , Function.createDelegate(this, this.OnItemQueryFailed)

I think it has to be done on the client side using: SP.ListItem.get_effectiveBasePermissions()

See this link for more info: https://andrewwburns.com/2012/02/29/check-permissions-in-javascript-client-object-model/

  • 1
    Unfortunately effectiveBasePermissions is not available for Folders in my SharePoint library. After some additional research it looks like I may be able to find what I need via .getFolderByServerRelativeUrl(folderPath).get_listItemAllFields().get_roleAssignments().getMember. I'm not there yet, but I think I'm getting closer. – Aaron Wagner Oct 24 '16 at 19:44
  • Ok, did a little more digging and it looks like I should be able to get to EffectiveBasePermissions via web.getFolderByServerRelativeUrl(cleanFolderPath).get_listItemAllFields().get_effectiveBasePermissions(); however, every time I try to do this I get an error stating "The property or field 'EffectiveBasePermissions' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested." – Aaron Wagner Oct 25 '16 at 15:25
  • Are you running the javascript as a function that runs following an event?? Or are you running the function as the page loads?? – Jason James Oct 25 '16 at 15:40
  • I run it as a function inside $(document).ready() – Aaron Wagner Oct 25 '16 at 15:58
  • Ok, figured out how to access get_effectiveBasePermissions; however, so far I have only figured out how to check permission levels for current / logged in user. What I would like to do is determine if current folder is available to everyone (all authenticated users) or not... is this possible with get_effectiveBasePermissions or maybe with get_roleAssignments? – Aaron Wagner Oct 25 '16 at 19:50

Maybe it's a little bit old... but to see Everyone permissions on folder, you can do like this:

var login = "c:0(.s|true"; //Everyone login
var folder = web.getFolderByServerRelativeUrl(cleanFolderPath);
var effectivePermissions = folder.get_listItemAllFields().getUserEffectivePermissions(login);
   Function.createDelegate(this, function () {
       var canRead = effectivePermissions.has(SP.PermissionKind.viewListItems);
   Function.createDelegate(this, errorCallback)

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.