Removing Role Definitions from a Role Assignment
Role assignments can be exposed ala ISecurableObject and pretty much everything, in order to support Securable Objects (for item level security,etc.), is an ISecurableObject in SharePoint 2007. So, to begin with, we are going to use ISecurableObject to get assignments in combination with a SPPrincipal (representing a user or group) via the GetAssignmentByPrincipal method available off a RoleAssignments collection (it doesn’t even require casting!).
- SPRoleAssignment assignment = ISecurableObject.RoleAssignments.GetAssignmentByPrincipal(SPPrincipal);
Following, a new SPRoleAssignment object is hydrated based on the SPPrincipal object, and that SPRoleAssignment object has a RoleDefinitionBindings collection that exposes the Remove method. Therefore, if you had an array or typed collection of SPRoleDefinitions you wanted to iterate, you could do something like (of course after testing whether the SPRoleAssignment object created is not null):
- foreach (SPRoleDefinition definition in List<SPRoleDefinition>)