public RoleDefinitionToken(Web web, RoleDefinition definition) : base(web, string.Format("{{roledefinition:{0}}}", definition.RoleTypeKind.ToString())) { name = definition.EnsureProperty(r => r.Name); }
public RoleDefinitionToken(Web web, RoleDefinition definition) : base(web, string.Format("{{roledefinition:{0}}}", definition.RoleTypeKind.ToString())) { name = definition.EnsureProperty(r => r.Name); }
private static void AddPermissionLevelImplementation(this SecurableObject securableObject, Principal principal, RoleDefinition roleDefinition, bool removeExistingPermissionLevels = false) { if (principal == null) { return; } var roleAssignments = securableObject.RoleAssignments; securableObject.Context.Load(roleAssignments); securableObject.Context.ExecuteQueryRetry(); var roleAssignment = roleAssignments.FirstOrDefault(ra => ra.PrincipalId.Equals(principal.Id)); //current principal doesn't have any roles assigned for this securableObject if (roleAssignment == null) { var rdc = new RoleDefinitionBindingCollection(securableObject.Context); rdc.Add(roleDefinition); securableObject.RoleAssignments.Add(principal, rdc); securableObject.Context.ExecuteQueryRetry(); } else //current principal has roles assigned for this securableObject, then add new role definition for the role assignment { var roleDefinitionBindings = roleAssignment.RoleDefinitionBindings; securableObject.Context.Load(roleDefinitionBindings); securableObject.Context.ExecuteQueryRetry(); // Load the role definition to add (e.g. contribute) if (removeExistingPermissionLevels) { // Remove current role definitions by removing all current role definitions roleDefinitionBindings.RemoveAll(); } // Add the selected role definition if (!roleDefinitionBindings.Any(r => r.Name.Equals(roleDefinition.EnsureProperty(rd => rd.Name)))) { roleDefinitionBindings.Add(roleDefinition); //update roleAssignment.ImportRoleDefinitionBindings(roleDefinitionBindings); roleAssignment.Update(); securableObject.Context.ExecuteQueryRetry(); } } }
public RoleDefinitionToken(Web web, RoleDefinition definition) : base(web, $"{{roledefinition:{definition.RoleTypeKind}}}") { name = definition.EnsureProperty(r => r.Name); }