In this SharePoint 2013 tutorial, I have explored how to check login user has full permission or not using the SharePoint 2013 REST API.
I wanted to avoid using JSOM SharePoint 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 high low values for 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 an 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 the current user is an admin of the site. For that, we need to check the user has manageweb permission kind. (Actually, we need to check other permission kinds assign to full control as well but if the user has to 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)[email protected]={'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));
}
});
}
You may like following SharePoint Rest API tutorials:
- Display SharePoint List items in a data table using Rest API and jQuery
- Create custom SharePoint Survey poll using REST API and AngularJS
- Create a custom User profile web part using SharePoint REST API and bootstrap
- Display custom alert message in SharePoint using REST API
- Retrieve and Display TASK status using REST API in SharePoint
- Create a Custom Calendar in SharePoint using Rest API and jQuery
- Display SharePoint list data in jQuery data table using Rest API
- SharePoint Rest API Crud Operations
- Create Highcharts in SharePoint using Rest API
Hope this SharePoint tutorial will help to check current logged in user permission in SharePoint 2013 using Rest API.
I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core
Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.