pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
762 stars 304 forks source link

Add breakroleinheritance to folder/file listItemAllFields endpoint #2905

Closed ydescortes closed 9 months ago

ydescortes commented 9 months ago

Target environment

All

Additional environment details

I'm using pnp/js in sharepoint framework and nodejs environment (webpart context or certificate azure AD authentication)

Enhancement Idea

When i use breakroleinheritance on folder item or file item, i need to write :

const item = await sp.web.getFolderByServerRelativePath(`ITEM PATH`).getItem()
await item.breakRoleInheritance(true, true)

which need 2 requests

the SharePoint rest api url knows that endpoint : _api/web/getFolderByServerRelativePath(ITEM PATH)/listitemallfields/breakroleinheritance(copyRoleAssignments=true,clearSubscopes=true) which require only one request

Can you add it natively to pnp ? now i have to use the following code :

const listItemAllFields = sp.web.getFolderByServerRelativePath(`ITEM PATH`).listItemAllFields
listItemAllFields.append("breakroleinheritance(copyRoleAssignments=true,clearSubscopes=true)")
await spPost(listItemAllFields)

thx

bcameron1231 commented 9 months ago

Hi. We'll discuss internally. Not quite sure if it would make it into v3 as we're actively working on and close to releasing v4. We would welcome a PR if you wanted to do one

I will say that your approach works, but could be simplified. You could technically achieve the same behavior doing this...

await Item(sp.web.getFolderByServerRelativePath(`ITEM PATH`).listItemAllFields).breakRoleInheritance(); .

bcameron1231 commented 9 months ago

Closing this issue as answered. If you have additional questions or we did not answer your question, please open a new issue, ref this issue, and provide any additional details available. Thank you!

We discussed internally, and decided the recommended approach was a fine approach.

github-actions[bot] commented 9 months ago

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.