Sharepoint - How to check whether the current user has edit permission for a particular list using JSOM in SharePoint 2013
You can try using below code. Since its OnPrem, we first need to get the login name of user and pass it to the get_effectiveBasePermissions
method.
To ensure that user has edit permission, we will check the SP.PermissionKind.editListItems
enum.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
getCurrentUserPermission();
});
function getCurrentUserPermission()
{
var web,clientContext,currentUser,oList,perMask;
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
currentUser = web.get_currentUser();
oList = web.get_lists().getByTitle('Test List');
clientContext.load(oList,'EffectiveBasePermissions');
clientContext.load(currentUser);
clientContext.load(web);
clientContext.executeQueryAsync(function(){
if (oList.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)){
console.log("user has edit permission");
}else{
console.log("user doesn't have edit permission");
}
}, function(sender, args){
console.log('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());
});
}
Here is the code you are looking for:
var ctx = new SP.ClientContext.get_current();
var web = context.get_web();
var ob = new SP.BasePermissions();
ob.set(SP.PermissionKind.manageWeb)
ob.set(SP.PermissionKind.managePermissions)
var per = web.doesUserHavePermissions(ob)
ctx.executeQueryAsync(
function(){
alert(per.get_value()); // If this is true, user has permission, if not, no
},
function(a,b){
alert ("Something wrong");
}
);
Instead of web
you can check for list
.
Found here.
You can also get complete list of permission enumeration here.
If you want to do this via REST API, then references are here and here for you.