Display the SharePoint list item permissions using REST API

Lets see how we can display the SharePoint list item permissions using REST API

I am going to use the SharePoint hosted app and SharePoint online. You could use an on premises installation as well.

Lets start by creating a SharePoint hosted app. Update the App.js as follows:

'use strict';

var hostweburl;
var appweburl;
var executor;

$(document).ready(function () {
  getCustomPermission();
});

// retrieve the hostweb url and appweb url from the query string
function getCustomPermission() {
  $(document).ready(function () {
    hostweburl =
        decodeURIComponent(
            getQueryStringParameter("SPHostUrl")
    );
    appweburl =
        decodeURIComponent(
            getQueryStringParameter("SPAppWebUrl")
    );

    var scriptbase = hostweburl + "/_layouts/15/";

    $.getScript(scriptbase + "SP.RequestExecutor.js", getRoleAssignments);
  });
}

//make the rest call
function getRoleAssignments() {
  executor = new SP.RequestExecutor(appweburl);

  executor.executeAsync(
      {
        url:
            appweburl +
            "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Test')/items(1)?$expand=RoleAssignments/Member/Users&@target='" +
            hostweburl + "'",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: successHandler,
        error: errorHandler
      }
  );
}

//display results
function successHandler(data) {
  var jsonObject = JSON.parse(data.body);
  var roleAssignmentHTML = "";

  var results = jsonObject.d.RoleAssignments.results;
  for (var i = 0; i < results.length; i++) {

    roleAssignmentHTML = roleAssignmentHTML +
          "<p><b>" + results[i].Member.OwnerTitle +
          "</b></p>";
    var users = results[i].Member.Users.results;
    if (users) {
      for (var u = 0; u < users.length; u++) {
        roleAssignmentHTML = roleAssignmentHTML + "<p>" + users[u].Title + "</p>";
      }
    }
  }
  document.getElementById("message").innerHTML =
      roleAssignmentHTML;
}


function errorHandler(data, errorCode, errorMessage) {
  document.getElementById("message").innerText =
      "Could not complete cross-domain call: " + errorMessage;
}

function getQueryStringParameter(paramToRetrieve) {
  var params =
      document.URL.split("?")[1].split("&");
  var strParams = "";
  for (var i = 0; i < params.length; i = i + 1) {
    var singleParam = params[i].split("=");
    if (singleParam[0] == paramToRetrieve)
      return singleParam[1];
  }
}

Notice that we are using the $expand=RoleAssignments/Member/Users to get the user information present in each assignment.

App Permissions

In deploying to production you need to try out the different permission levels to ensure you are using the minimum required permissions.

This approach requires that we have a high enough permission level because we are listing the information of other users also.

When you build and execute the code, it should list the users and SharePoint groups which have the permission on the item.

Item Level Permissions Output

I have uploaded the code for this solution in github at ItemLevelPermissions

Customizing SharePoint Forms using JSLink

Lets explore customizing SharePoint Forms using JSLink.
Lets say we want to customize the New Form of a custom list.
Continue reading “Customizing SharePoint Forms using JSLink”

Creating a SharePoint SPA using AngularJS and Breeze

Today, we will look at creating a SharePoint SPA using AngularJS and Breeze in a SharePoint hosted app. Single Page Apps or SPA does not mean the application is limited to one page. The experience of navigating between pages is seamless for the user without the postback which happens when navigating to a page.
Continue reading “Creating a SharePoint SPA using AngularJS and Breeze”

Customizing SharePoint 2013 Search Center

In SharePoint 2010, FAST search existed alongside with SharePoint Search. In SharePoint 2013, both have been integrated and you now have a single interface of SharePoint Search.

In this post, we’ll go over some SharePoint 2013 Search concepts such as crawled properties, managed properties. Then, we’ll see how you can customize the search center with Custom result page and navigation, Result Source, Display template, Result type, Query Rules and Refiners.

Continue reading “Customizing SharePoint 2013 Search Center”

PnP Provisioning Engine

Today, let’s explore the Microsoft patterns and practices or PnP Provisioning Engine solution to provision SharePoint artifacts. The way this works is the business users and designers make the required changes to the UI from the browser in one site. After that, we can import this entire configuration. Then, we can create new sites or artifacts using this configuration.

Continue reading “PnP Provisioning Engine”

Branding SharePoint Online

Even though the title for this post is Branding SharePoint Online, this is applicable to on-premises as well. Microsoft is suggesting that we should avoid creating custom master pages. Not that it should not be used, however we should consider other approaches such as themes and alternate css first.

Continue reading “Branding SharePoint Online”

Customize SharePoint UI using JavaScript

As a best practice, Microsoft recommends us to avoid customizing the SharePoint farm to achieve our business logic and functionality. Using the app model is a step towards this goal. The patterns and practices gives us guidance on how to achieve some of the functionality we used to do with farm solutions.

Today, lets see how to customize SharePoint UI using JavaScript

Continue reading “Customize SharePoint UI using JavaScript”

SharePoint Search – how to return all results

By default, when we use the Search API, SharePoint limits the number of items retrieved. If your query returns a number of items within this limit, then it is not a problem. However, if your query results in a larger set, then by default those items will not be present in the result set.
Continue reading “SharePoint Search – how to return all results”

WebMethods in SharePoint using JQuery

Lets say we have a SharePoint Site Page or Application Page which has a server side method and we would like to call this method from JavaScript code. Wouldn’t it be great if we can do the server side processing and return the result such as a string or a json object back to the client side? Well, this is precisely what we can do using WebMethod framework.
Continue reading “WebMethods in SharePoint using JQuery”

Cross Domain Library in SharePoint 2013

Let’s have a look at the Cross Domain Library in SharePoint 2013

In this series of posts, I will be posting my experience following along to the Microsoft Virtual Academy course on SharePoint Online Development for Office 365.

Let’s see how to use the cross domain library from a provider hosted app.
Continue reading “Cross Domain Library in SharePoint 2013”