1

I am trying to obtain user roles to pass from Sharepoint server to a specific tool, and I have to perform a lot of gets to obtain it.

There is a simples REST request to do it?

2
  • 1
    Is the information given to you from the REST URL "/_api/web/CurrentUser/Groups" sufficient?
    – Choggo
    Commented Jan 27, 2015 at 13:02
  • It should list all user SP Groups, but not FBA roles or AD groups
    – Choggo
    Commented Jan 27, 2015 at 13:03

1 Answer 1

2

You could consider the following solution to get permission levels/roles:

JavaScript example

function getUserEffectivePermissions(webUrl,accountName) 
{
    var endpointUrl = webUrl +  "/_api/web/getusereffectivepermissions(@u)?@u='" + encodeURIComponent(accountName) + "'";
    return $.getJSON(endpointUrl);
}

function getUserRoles(webUrl,accountName)
{
    return getUserEffectivePermissions(webUrl,accountName).then(function(data){
        var permissions = new SP.BasePermissions();
        permissions.initPropertiesFromJson(data);
        var permLevels = [];
        for(var permLevelName in SP.PermissionKind.prototype) {
            if (SP.PermissionKind.hasOwnProperty(permLevelName)) {
               var permLevel = SP.PermissionKind.parse(permLevelName);
               if(permissions.has(permLevel)){
                  permLevels.push(permLevelName);
                }
            }     
        }
        return permLevels;
    });   
}

Usage

var webUrl = _spPageContextInfo.webAbsoluteUrl;
getUserRoles(webUrl,'i:0#.f|membership|[email protected]').done(function(permLevels){
    console.log(permLevels); 
});

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.