//Common Method for Getting Current User Permission in list Item
//Parameters Required
//1)AppwebUrl
//2)HostWebUrl
//3)ListName
//4)Listem Id
//5)Callback
//for calling function use GetItemPermissions({AppwebUrl},{HostWebUrl},{ListName},{Listem Id},function(data){
//alert(data);
//});
//sample
//GetItemPermissions(SPAppWebUrl,SPHostUrl,"Save List",41,function(data){
//alert(data);
//});
function getListUserEffectivePermissions(AppWebUrl, HostURL, listTitle, accountName, ItemID, callback) {
var endpointUrl = AppWebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listTitle + "')/items(" + ItemID + ")/getusereffectivepermissions(@u)?@u='" + encodeURIComponent(accountName) + "'&@target='" + HostURL + "'";
$.getJSON(endpointUrl).done(function(data) {
callback(data);
}).fail(function(data) {
console.log(data);
callback("error")
});
}
function parseBasePermissions(value) {
var permissions = new SP.BasePermissions();
permissions.initPropertiesFromJson(value);
var permLevels = [];
for (var permLevelName in SP.PermissionKind.prototype) {
if (SP.PermissionKind.hasOwnProperty(permLevelName)) {
var permLevel = SP.PermissionKind.parse(permLevelName);
if (permissions.has(permLevel)) {
permLevels.push(permLevelName);
}
}
}
return permLevels;
}
function GetItemPermissions(AppWebUrl, HostURL, ListName, ItemID, callback) {
$.getJSON(AppWebUrl + "/_api/SP.AppContextSite(@target)" + "/web/currentuser?@target='" + HostURL + "'").done(function(data) {
Email = data.LoginName;
getListUserEffectivePermissions(AppWebUrl, HostURL, ListName, Email, ItemID, function(data) {
if (data != "error") {
var roles = parseBasePermissions(data);
callback(roles);
} else {
callback("Error");
}
});
}).fail(function(data) {
console.log(data);
callback("Error");
});
}
//Parameters Required
//1)AppwebUrl
//2)HostWebUrl
//3)ListName
//4)Listem Id
//5)Callback
//for calling function use GetItemPermissions({AppwebUrl},{HostWebUrl},{ListName},{Listem Id},function(data){
//alert(data);
//});
//sample
//GetItemPermissions(SPAppWebUrl,SPHostUrl,"Save List",41,function(data){
//alert(data);
//});
function getListUserEffectivePermissions(AppWebUrl, HostURL, listTitle, accountName, ItemID, callback) {
var endpointUrl = AppWebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listTitle + "')/items(" + ItemID + ")/getusereffectivepermissions(@u)?@u='" + encodeURIComponent(accountName) + "'&@target='" + HostURL + "'";
$.getJSON(endpointUrl).done(function(data) {
callback(data);
}).fail(function(data) {
console.log(data);
callback("error")
});
}
function parseBasePermissions(value) {
var permissions = new SP.BasePermissions();
permissions.initPropertiesFromJson(value);
var permLevels = [];
for (var permLevelName in SP.PermissionKind.prototype) {
if (SP.PermissionKind.hasOwnProperty(permLevelName)) {
var permLevel = SP.PermissionKind.parse(permLevelName);
if (permissions.has(permLevel)) {
permLevels.push(permLevelName);
}
}
}
return permLevels;
}
function GetItemPermissions(AppWebUrl, HostURL, ListName, ItemID, callback) {
$.getJSON(AppWebUrl + "/_api/SP.AppContextSite(@target)" + "/web/currentuser?@target='" + HostURL + "'").done(function(data) {
Email = data.LoginName;
getListUserEffectivePermissions(AppWebUrl, HostURL, ListName, Email, ItemID, function(data) {
if (data != "error") {
var roles = parseBasePermissions(data);
callback(roles);
} else {
callback("Error");
}
});
}).fail(function(data) {
console.log(data);
callback("Error");
});
}
No comments:
Post a Comment