Search code examples
javascriptpermissionssharepoint-2007

Reading Individual Permissions from Permission Mask for Sharepoint 2007


I am trying to use the SPServices jQuery library to read the permissions mask for users on Sharepoint 2007 sites. I can successfully get a number for the permissions mask but I am having trouble converting the permissions mask response into something that makes sense.

I am getting the permissions mask using the following Javascript:

function getPermissions(url, sobj) {

  $().SPServices.defaults.webURL = url;

  //FIRST DO SITE

  $().SPServices({

     operation: "GetPermissionCollection",

     async: false,

     objectName: url,

     objectType: "Web",

     completefunc: function(xData, Status){

        $(xData.responseXML).find("Permission").each(function(){

           sobj.Permissions.push($(this).attr("UserLogin"));

           sobj.PermissionsLevel.push($(this).attr("Mask"));

        });

     }

  });


  //NOW DO LISTS

  for (x in sobj.Lists) {

      $().SPServices({

          operation: "GetPermissionCollection",

          async: false,

          objectName: sobj.Lists[x].InternalName,

          objectType: "List",

          completefunc: function(xData, Status){

              $(xData.responseXML).find("Permission").each(function(){

                 sobj.Lists[x].Permissions.push($(this).attr("UserLogin"));

                 sobj.Lists[x].PermissionsLevel.push($(this).attr("Mask"));

              });

          }

      });

   }

}

A couple of examples are: A) -2013006751 B) -1140590865

The respective binary values for these are (assuming use of two's complement): A) 10001000000000111111010001100000 B) 10111100000000111111011011101110

I can't get my head around how these numbers equate to the permissions that the user actually has. Using the table of permissions from http://jamestsai.net/Blog/post/Understand-SharePoint-Permissions-Part-1-SPBasePermissions-in-Hex2c-Decimal-and-Binary-The-Basics.aspx, it just doesn't seem to match up with what permissions the users actually have.

I'm away from work at the moment so I'll update this with more information but can anyone spot what I'm doing wrong from the information I currently have?


Solution

  • bitwise comparison is what you are after.

    e.g.

    var permissionMask = -2013006751;
    var viewPages = 131072; // 100000000000000000
    if((permissionMask & viewPages)===viewPages)
    {
        alert('person has view pages permission');
    }
    

    See here for a more detailed explanation.