Skip to content

Instantly share code, notes, and snippets.

@xsolon
Last active November 24, 2015 08:01
Show Gist options
  • Save xsolon/d8497ac480aec59d9477 to your computer and use it in GitHub Desktop.
Save xsolon/d8497ac480aec59d9477 to your computer and use it in GitHub Desktop.
SharePoint JSOM: Check permissions of current page
_spPageContextInfo
{
webServerRelativeUrl : "/ProjectWeb",
webLanguage : 1033,
currentLanguage : 1033,
webUIVersion : 4,
pageListId : "{c1d7b89f-f07b-4e2e-b89c-76c315831d59}",
pageItemId : 5,
userId : 68,
alertsEnabled : true,
siteServerRelativeUrl : "/",
allowSilverlightPrompt : "True"
}
(function(){
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var list = web.get_lists().getById(_spPageContextInfo.pageListId);
var li = list.getItemById(_spPageContextInfo.pageItemId);
ctx.load(li, 'EffectiveBasePermissions');
ctx.executeQueryAsync(function(){
var perms = li.get_effectiveBasePermissions();
// PermissionKind values: https://msdn.microsoft.com/en-us/library/office/ee556747(v=office.14).aspx
if (perms.has(SP.PermissionKind.editListItems)) {
console.log('can edit');
}
}, function onError(request, errorArgs){
console.log(errorArgs.get_message());
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment