Tuesday, 29 September 2015

Get Current User Permission in Sharepoint Online Uisng REST API

function getCurrentUserPermission(userId) {
    $.ajax
    ({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + userId + ")/Groups",
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        dataType: "json",
        async: true,
        success: function (data) {
            /* get all group's title of current user. */
            for (var i = 0; i < data.d.results.length; i++) {
                if (data.d.results[i].Title == "Users") {
                    groupName = data.d.results[i].Title
                }
                else if (data.d.results[i].Title == "Admin") {
                    groupName = data.d.results[i].Title;
                   
                }
                else if (data.d.results[i].Title == "Operation") {
                    groupName = data.d.results[i].Title;
                  }
            }
        }
    });
}