1

In sharepoint 2013, I need to check if a the current user, has access to a specific list, for that I'm using the following REST endpoint (using AJAX)

host/_api/web/list(guid"xxxxxxxxxxx")/RoleAssignments

But i'm not able to check on the roles assigned for that list with a user that it's not an admin? The query it returns a login forma asking for a user with enough privileges

How can i check if the current user can query the items for example the "invoices" list ?

1 Answer 1

0

The example shows how to determine whether current user could access list or not:

function getListPermissions(weburl,listTitle) 
{
    var endpointUrl = weburl + "/_api/web/lists/getbytitle('" + listTitle + "')/effectivebasepermissions";
    return $.ajax({
        'url': endpointUrl,
        'method': 'GET',
        'headers': {
            'accept': 'application/json;odata=verbose',
            'content-type': 'application/json;odata=verbose',
            'X-RequestDigest': $('#__REQUESTDIGEST').val()
        }
    });
}






var listTitle = 'Pages';
getListPermissions(_spPageContextInfo.webAbsoluteUrl,listTitle)
.done(function(data)
{
    var permissions = new SP.BasePermissions();
    permissions.initPropertiesFromJson(data.d.EffectiveBasePermissions);
    if (!permissions.has(SP.PermissionKind.viewListItems)){
       console.log(String.format('Current user cant access {0} list',listTitle));    
    }
})
.fail(function(error){
    console.log(JSON.stringify(error));
});
4
  • Seems i have a proble with "SP.BasePermissions();" Cant find it at pageload time, dows it depends on a specific JS file that i need to add?
    – Forres
    May 18, 2015 at 6:30
  • SP.BasePermissions is declared in sp.js, so there is a dependency to SharePoint library, could you reference that library in your app? May 18, 2015 at 6:43
  • Ill guess ill delay the checking of the permissions till SP.js is loaded, this could do the trick :) $.getScript(_spPageContextInfo.webAbsoluteUrl+"/_layouts/15/sp.js",$scope.getFilters())
    – Forres
    May 18, 2015 at 7:01
  • Point is...when i do all that, the moment I try to excecute permissions.initPropertiesFromJson(data.d.EffectiveBasePermissions); "permissions" doesnt have the "initPropertiesFromJson" property :
    – Forres
    May 18, 2015 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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