I have created a Custom list named Test List. I need to check whether the current user is having edit list permission for Test List list or not, by using JSOM.

up vote 16 down vote accepted

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.

  • thanks for your answer.but I need to check whether the current user is having edit list permission for Test List – Jeeva Jeyapaul Jul 4 '17 at 6:41

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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