6

I'm trying to understand what exactly is the "webPermMasks" property inside the "_spPageContextInfo" object, I tried to look in many websites on the web and also in the MSDN.

In the MSDN I wasn't able to find anything... and on another website the only thing I found is a very basic (and not very useful) answer that is: "Object with properties High & Low" which in my opinion doesn't really explain anything.

Can anyone please try to give me a better explaination?

Cheers and thanks in advance!

1
  • I think it is the Permission mask value on the web for the Current User/Possible Max, min permission mask values available on the web. kx.cloudingenium.com/programming/net/… Ex: the FullMask value is 9223372036854775807 Sep 15, 2015 at 14:42

3 Answers 3

18

webPermMasks are TWO 32-bit integers indicating which permissions a user has.

Each bit represents a permission.

(_spPageContextInfo.webPermMasks.High).toString(2)
(_spPageContextInfo.webPermMasks.Low).toString(2)

Displays the bits

High & Low

In the good old days computer worked with 8 bits, which someone named a Byte.
With 8 bits (8 permissions) you can only count from 0 to 255

So to store a larger number of 16 bits (0- 32768) on an 8-bit CPU you need 2 Bytes.

We called these the High-Byte and the Low-Byte

SharePoint has 37 types of permissions

Present computers have evolved from CPUs that can handle 8-bits to 16-bits to 32-bits

Currently SharePoint has 37 different Security permissions.. which do not fit in those 32 bits

Like so many moons ago you need TWO 32-bit values to encode Permissions
Which some Microsoft engineer with common sense named the High and Low value

The SP.js library (available standard on most pages) has the information on which Permission is which bit number

Run this in the developer console:

for (var permLevelName in SP.PermissionKind.prototype) {
    if (SP.PermissionKind.hasOwnProperty(permLevelName)) {
        var permLevel = SP.PermissionKind.parse(permLevelName);
           console.info(permLevelName,permLevel);
        }
    }
}

Note permLevel is not the value, it is the bit-number

SP.PermissionKind.openItems is bit-number 6 and thus value 2^6

If you add up all the values you get the High order and Low order integer values for Permissions.

Note permLevel for SP.PermissionKind.manageAlerts is the 39th bit

This is in the High order integer, so the value is 2^(39-31)

webPermMasks

   _spPageContextInfo.webPermMasks.Low
   _spPageContextInfo.webPermMasks.High

Gives you 64 bits in TWO 32 bit Integers (with 37 permissions only a few are used in the High order)

indicating what Permissions the Current User has on the Current Page

All PermissionKinds (SP.PermissionsKnd.[name])

Note: This is the bit-number, not the value!

To check if someone has permissions, You have to calculate the (summed) value then binary check against the High and Low order integers.

    viewListItems: 1
    addListItems: 2
    editListItems: 3
    deleteListItems: 4
    approveItems: 5
    openItems: 6
    viewVersions: 7
    deleteVersions: 8
    cancelCheckout: 9
    managePersonalViews: 10
    manageLists: 12
    viewFormPages: 13
    anonymousSearchAccessList: 14
    open: 17
    viewPages: 18
    addAndCustomizePages: 19
    applyThemeAndBorder: 20
    applyStyleSheets: 21
    viewUsageData: 22
    createSSCSite: 23
    manageSubwebs: 24
    createGroups: 25
    managePermissions: 26
    browseDirectories: 27
    browseUserInfo: 28
    addDelPrivateWebParts: 29
    updatePersonalWebParts: 30
    manageWeb: 31
    anonymousSearchAccessWebLists: 32
    useClientIntegration: 37
    useRemoteAPIs: 38
    manageAlerts: 39
    createAlerts: 40
    editMyUserInfo: 41
    enumeratePermissions: 63

Use in script

The SP library supplies a function to check for individual levels:

  SP.PageContextInfo.get_webPermMasks().has( [bitnumber] );

  SP.PageContextInfo.get_webPermMasks().has( SP.PermissionKind.enumeratePermissions );

Using unused space (tales of the past)

Only a handfull of bits in the High Order integer are used by SharePoint.

Yet the database stores all 32 bits...

When we still built SharePoint Back End stuff we would use those unused bits for our own Permission scheme.

The free trials we let everyone install was actually the full blown product.
And when they bought the Licensed Product.. all it did was flip one bit in the database.

J1 iSPT

3

It's not "quite simple". The values high and low are used to determine permissions. The only function in SP that uses webPermsMask is called SP.PageContextInfo.get_webPermMasks(). It returns a value of high or low (High=2147483647, Low=4294967295). Then that number is used to create a SP.ContextPermissions object to determine permissions. As far as I can tell this is exclusively used for Ribbon commands (to determine if a Ribbon command should be enabled or not) Take a look at this CommandUIHandler for example:

<CommandUIHandler
    Command="Ribbon.DesignTab.Site.Logo"
    EnabledScript="javascript:
        (function (){
            var p = SP.PageContextInfo.get_webPermMasks();
            return p &amp;&amp; p.has(SP.PermissionKind.manageWeb);
        }());"
    CommandAction="javascript:
    EnsureScript('SP.js', typeof SP.PageContextInfo, function () {
        var i = document.querySelector('.ms-siteicon-img'), src = i &amp;&amp; i.src;
        SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', {
            url: SP.Utilities.Utility.getLayoutsPageUrl('prjsetng.aspx?section=logo'), autoSize: true,
            dialogReturnValueCallback: i &amp;&amp; function (result, retval) {
                if (!result) i.src = src;
                else if (!i) location.reload();
            }
        });
});" />

My guess is this property is used to determine if a website is in read only mode or not :)

2
  • This make more sense. According to the script, it's asking if the current user has permission to manageweb into the context, right? I have try with a user with visitor's permission and the webPermsMask return the same values. Does not this should be changed?
    – Marco
    Sep 15, 2015 at 15:10
  • As far as I know no JavaScript sets that value, so it must come from code behind. Maybe when a site collection is being backed up the webPermsMask is set to Low to disable some of the ribbon controls. I can't tell more but it might be worth looking into SharePoint DLLS. Sep 15, 2015 at 15:19
-4

quite simple :P. The variable return is:

Object {High: 2147483647, Low: 4294967295}

those two values are:

int.MaxValue: 2,147,483,647

uint.MaxValue: 4,294,967,295

Dont ask me why this values are stored into an array into de SharePoint context, but that it's

Greetings :)

2
  • Yes, but what does high and low stands for?
    – FabioEnne
    Sep 15, 2015 at 14:30
  • I dont know the reason of it, perhaps it's a var use it internaly by sp.js to validate data, perhaps the developers forgot to remove it, I dont know. You asked what it is and I answered :p
    – Marco
    Sep 15, 2015 at 14:42

Your Answer

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

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