Skip to content

Instantly share code, notes, and snippets.

@zplume
Last active July 7, 2023 14:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zplume/221e81cc12a1a8c04a4e to your computer and use it in GitHub Desktop.
Save zplume/221e81cc12a1a8c04a4e to your computer and use it in GitHub Desktop.
Get an array of Permission Levels (Role Definitions) for the current site using REST
// This script returns an array of Role Definition objects, containing the Permission Levels for the site
// See http://msdn.microsoft.com/en-us/library/office/jj244931(v=office.15).aspx for examples of how to use the
// SP.PermissionKind object to assign permissions to a Role Definition
// replacement function for console.log(), which avoids 'undefined' exception in IE 8
window.LogMsg = function (msg) {
if (window.console) {
console.log(msg);
}
};
// ensure library is loaded before executing a function
// ns = namespace (i.e. jQuery)
// url = url of library (i.e. from a CDN)
// func = a function to execute when the library has loaded
window.EnsureLibrary = function (ns, url, func) {
// execute a function when a library has loaded
var executeOnLoaded = function (ns, func) {
if (!window[ns]) {
setTimeout(function () {
executeOnLoaded(ns, func);
}, 100);
} else {
LogMsg(ns + " loaded");
func();
}
};
if (!window[ns]) {
var script = document.createElement("script");
script.setAttribute("src", url);
var head = document.getElementsByTagName("head")[0];
head.appendChild(script);
}
executeOnLoaded(ns, func);
};
(function() {
var jQueryURL = "//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js";
var restEndpoint = _spPageContextInfo.webAbsoluteUrl + "/_api/web/RoleDefinitions?$select=Name,Description,Id,BasePermissions";
EnsureLibrary("jQuery", jQueryURL, function() {
jQuery.noConflict();
jQuery.ajax({
url: restEndpoint,
cache: false,
async: true,
dataType: "json"
}).done(function (data) {
var data = data.value;
LogMsg(data);
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment