I'm trying to retrieve the current user's permissions for a list but I keep getting an emptyMask result, even when my current user account is a Site Collection Admin.
function getListUserEffectivePermissions (){
var account = 'domain\\myaccount';
var endpointUrl = _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbytitle('My Library')/getusereffectivepermissions(@u)?@u='"+account+"'";
return $.ajax({
url : endpointUrl,
dataType : 'json',
headers : { 'accept': 'application/json;odata=verbose' }
});
}
function parseBasePermissions (value){
var permissions = new SP.BasePermissions();
permissions.initPropertiesFromJson(value);
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;
}
getListUserEffectivePermissions().done(function(data){
var roles = parseBasePermissions(data);
console.log(roles);
});
A quick explanation of the code:
- Retrieving information for library "My Library"
- Retrieving permissions for user: "account"
- When completed, it compares the results to the
SP.PermissionKindobject - prints results
I'm pretty sure that the values being passed in for "My Library" and account are correct. If I change the account to a user name not present in my SharePoint instance I get
{"error":{"code":"-2130575276, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The user does not exist or is not unique."}}}
When I use my own account name I just get:
["emptyMask"]
And the responseText I get is:
{"d":{
"GetUserEffectivePermissions":{
"__metadata":{
"type":"SP.BasePermissions"
},
"High":"0",
"Low":"0"
}
}}
Can anyone tell me what I'm doing wrong?
parseBasePermissions(data.d.GetUserEffectivePermissions);. I was only passingdatainstead ofdata.d.GetUserEffectivePermissions. My original code is working now – jasonscript Jul 30 '15 at 01:42