Skip to content

Instantly share code, notes, and snippets.

@ktskumar
Created November 30, 2021 07:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktskumar/0e74e5a4a54ba969e4efbed556ddbdc2 to your computer and use it in GitHub Desktop.
Save ktskumar/0e74e5a4a54ba969e4efbed556ddbdc2 to your computer and use it in GitHub Desktop.
Change Item Level permission for SitePages Library
//Update the WriteSecurity to change the item level permissions
//Set the Edit property to Create items and edit items that were created by the user
// 1 - Create and edit all items
// 2 - Create items and edit items that were created by the user
// 3 - None
import { sp, Web } from "@pnp/sp/presets/all";
(async () => {
let web1 = await Web("https://contoso.sharepoint.com/sites/sitename");
const list = await web1.lists.getByTitle("Site Pages").select('Title,ReadSecurity,WriteSecurity').get()
console.log("Before Update: " + list.Title);
console.log("************************************");
console.log('Read Security: ' + list.ReadSecurity);
console.log('Write Security: ' + list.WriteSecurity);
console.log("\n");
const updateProperties = {
WriteSecurity: 2
};
await web1.lists.getByTitle("Site Pages").update(updateProperties).then(async (l: any) => {
// get the updated WriteSecurity
const r = await l.list.select("Title", "Description", "ReadSecurity", "WriteSecurity")();
console.log("After Update: " + r.Title);
console.log("************************************")
console.log('Read Security: ' + r.ReadSecurity);
console.log('Write Security: ' + r.WriteSecurity);
});
})().catch(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment