I'm using the Client Object Model and trying to remove a specific RoleDefinition from a RoleDefinitionBindingCollection
in a RoleAssignment.
This is the code I'm using:
Web web = context.Web;
List list = context.Web.Lists.GetByTitle("List");
context.Load(
list,
l => l.RoleAssignments.Include(
ra => ra.Member,
ra => ra.RoleDefinitionBindings
)
);
context.ExecuteQuery();
List<RoleDefinition> toDelete = new List<RoleDefinition>();
foreach (RoleAssignment ra in list.RoleAssignments) {
toDelete.Clear();
foreach (RoleDefinition rd in ra.RoleDefinitionBindings) {
if (rd.RoleTypeKind == RoleType.Administrator) {
toDelete.Add(rd);
}
}
if (toDelete.Count > 0) {
toDelete.ForEach(td => ra.RoleDefinitionBindings.Remove(td));
}
}
context.ExecuteQuery();
I can see that the RoleDefinition
is removed from the parent RoleDefinitionBindings
list, but nothing happens. There is no error and the permissions on the list stays exactly as they were after the context.ExecuteQuery()
All the examples I found are showing how to remove an entire RoleAssignment, or how to delete the RoleDefinition from the site.