Last active
June 11, 2018 20:56
-
-
Save vaderj/c27987fb76284934b5fbc6546d22e25b to your computer and use it in GitHub Desktop.
SP REST: Assign user permissions #Javascript #SharePoint #REST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function assignPerms(libraryName, folderName, usersPrincipalID, roleDefID) | |
{ | |
// To List the required Role Definition ID's : /_api/web/roleDefinitions() ; | |
// /_api/web/lists/getByTitle('Test')/roleassignments/addroleassignment(principalid=20,roleDefId=" + + ")" | |
var assignPerms = jQuery.ajax({ | |
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('" + _spPageContextInfo.siteServerRelativeUrl + "/" + libraryName + "/" + folderName + "/ListItemAllFields/roleassignments/addroleassignment(principalid=" + usersPrincipalID + ",roleDefId=" + roleDefID + ")", | |
type: 'POST', | |
contentType: 'application/json;odata=verbose', | |
headers: { | |
'Accept': 'application/json;odata=verbose', | |
'content-type':'application/json;odata=verbose', | |
'X-RequestDigest': $("#__REQUESTDIGEST").val() | |
} | |
}); | |
assignPerms.done(function(listData, textStatus, jqXHR) | |
{ | |
console.dir(listData) ; | |
console.dir(textStatus) ; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment