Reputation: 1
I'm encountering an issue with the following code snippet while trying to change permissions on a SharePoint list item based on a flag. Depending on the flag (readOnly), I need to switch the permissions from write to read and vice versa. I'm using PnP Core 1.12 and .NET 6. Here's the code:
private void ApplyPermissions(IListItem itemOfferta, List<ISharePointUser> users, bool readOnly)
{
itemOfferta.BreakRoleInheritance(false, true);
itemOfferta.AddRoleDefinition(_sharePointGroupAdmin.Id, _sharePointRoleEdit);
foreach (var user in users)
{
foreach (var role in itemOfferta.GetRoleDefinitions(user.Id))
{
itemOfferta.RemoveRoleDefinition(user.Id, role);
}
if (readOnly)
itemOfferta.AddRoleDefinition(user.Id, _sharePointRoleRead);
else
itemOfferta.AddRoleDefinition(user.Id, _sharePointRoleEdit);
}
}
The problem I'm facing is that when the readOnly flag is true, it's not correctly removing the write role for the specified users. The write role persists even after attempting to remove it using RemoveRoleDefinition.
Is there something I'm missing in my approach, or is there a better way to achieve this functionality using PnP Core 1.12 and .NET 6?
Any help or insights would be greatly appreciated! Thank you!
Upvotes: 0
Views: 42