.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Pankaj Mishra
Shivakumaran
alex morco
Imran Ghani
Meenakshi

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

How to Check User permission in SharePoint 2013 using REST API?

Posted By:Sagar Pardeshi       Posted Date: September 24, 2015    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

In this Article I have explore how to check login user has full permission or not using SharePoint 2013 REST API.
 

Introduction

In this Article I have explore how to check login user has full permission or not using SharePoint 2013  REST API.

I wanted to avoid using JSOM and do everything with REST. Fortunately, I understand that you must rely on JSOM for certain things. In this case JSOM has the SP.BasePermissions type with methods for combining sets of permissions. This type is defined in SP.js. JSOM also exposes the types of permissions as a basic integer enumeration as SP.PermissionKind. This enumeration is defined in SP.Runtime.js.  I still could not figure out how to get the high an low values for the permission. I knew what the values were supposed to be for the EditLisitItems permission. Looking at the permission in debug view I noticed the values were exposed by the typical nonsensical property names $4_1 and $5_1 . Whenever you set the permission with a permission kind the JSOM function will bit shift the values and re-calculate the high and low values.
Normally we need to perform tasks such as
- Does current user is admin on the site etc.
SharePoint provides a method called doesUserHavePermissions to perform that. First of all we need to know how SharePoint defines User roles by assigning permission levels  such as Full Control, Contributor , design and etc.

For an example site admin is assigned by Full Control which is a composite of few permission items we called as permission kind.

Example:
Assume that we want to check whether current user is an admin of the site. For that we need to check user has  manageWeb permission kind. (Actually we need to check other permission kinds assign to full control as well but if user has manage web it is more likely user can perform admin tasks, in my other example i will show how to check full permission kinds.
function getUserWebPermissionREST() {
 
    //Permission for admin to show or hide the entries on memory board using ShowOnHomePage Field
    var perm = new SP.BasePermissions();
    perm.set(SP.PermissionKind.manageWeb);
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/doesuserhavepermissions(@v)?@v={'High':'" + perm.$4_1.toString() + "', 'Low':'" + perm.$5_1.toString() + "'}",
        type: "GET",
        headers: { "accept": "application/json;odata=verbose" },
        success: function (data) {
            var d = data.d.DoesUserHavePermissions;
 
            if (d === true) {
                //Show Check Box if Full Control
            }
            else {
                //hide Check Box
            }
 
        },
  error: function (err) {
            alert(JSON.stringify(err));
        }
 
    });
 
}


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend