I have a SharePoint Library 'World'.In World library,there are multiple country folders and in each country folders we have different cities(subfolders in document lib).
I want to give permission to City group on City Subfolder(in country folder).
Now what I did is I have stopped inheritance of World Library and added to user X to City Group and City group has access on City subfolder that is within Country folder in document library.
Issue is when user X trying to browse City subfolder,access denied is coming.X is part of City Subfolder but not Country folder in Document library.I cheched permissions on City Subfolder,City group has unique permissions on City Subfolder.
I am using below code to give permission on City Subfolder and it is working fine.
function CountryDocumnetsAccess(role, principalid, folderPath) {
var headers = {
"Accept": "application/json;odata=verbose",
"content-Type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
}
//folder path is Country/City
var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('/sites/gsdcs/World/" + folderPath + "')/ListItemAllFields/";
var call = $.ajax(
{
url: endPointUrl + "breakroleinheritance(true)",
type: "POST",
headers: headers,
dataType: 'json',
success: function (data) {
var call = $.ajax(
{
url: endPointUrl + "roleassignments/addroleassignment(principalid=" + principalid + ",roleDefId=" + role + ")",
type: "POST",
headers: headers,
dataType: 'json',
success: function (data) {
console.log('Permission Granted to Country Documents successfully ! ' + endPointUrl);
CountryLinksAccess(role, principalid, folderPath);
if (IsDebug == false)
SPClientForms.ClientFormManager.SubmitClientForm(frmID);
},
error: function (error) {
console.log('Permission failed ' + endPointUrl + ' ' + JSON.stringify(error));
}
});
},
error: function (error) {
console.log(JSON.stringify(error));
}
});
}
I am using SharePoint Online.