Wednesday, March 17, 2021

How to get permission of a SharePoint list for a user using RESTApi

 Use EffectiveBasePermissions to get permissions of the user on a list. Example:


/_api/web/lists/getbytitle('L2')/EffectiveBasePermissions

Note that this will give the permissions of the logged in user


function checkPermissions() {

    var call = jQuery.ajax({

        url: _spPageContextInfo.webAbsoluteUrl +

            "/_api/Web/effectiveBasePermissions",

        type: "GET",

        dataType: "json",

        headers: {

            Accept: "application/json;odata=verbose"

        }

    });


    call.done(function (data, textStatus, jqXHR) {

        var manageListsPerms = new SP.BasePermissions();

        manageListsPerms.initPropertiesFromJson(data.d.EffectiveBasePermissions);


        var manageLists = manageListsPerms.has(SP.PermissionKind.manageLists);


        var message = jQuery("#message");

        message.text("Manage Lists: " + manageLists);

    });

}

No comments:

Post a Comment