public void AddPermission(SPBindingCollection bindingCol, bool forceBreak, bool permissionsApplyRecursively) { if (HasUniquePermissions.HasValue && !HasUniquePermissions.Value) { if (!forceBreak) { throw new NoForceBreakException(this.Id); } else { SecObj.BreakRoleInheritance(true, true); } } else if (!HasUniquePermissions.HasValue) { throw new InvalidOperationException("The permissions for object id \"" + Convert.ToString(this.Id) + "\" cannot be modified!"); } var list = new List <RoleAssignment>(bindingCol.Count); for (int i = 0; i < bindingCol.Count; i++) { var binding = bindingCol[i]; var bCol = new RoleDefinitionBindingCollection(CTX.SP1) { binding.Definition }; list.Add(SecObj.RoleAssignments.Add( binding.Principal, bCol)); foreach (var ass in list) { CTX.Lae(ass, false); } Update(); CTX.Lae(); } if (Permissions != null) { for (int ra = 0; ra < list.Count; ra++) { var r = list[ra]; CTX.Lae(r, true, ras => ras.Member.Id, ras => ras.Member.Title); } Permissions.AddRange(this, list); } else { this.GetPermissions(); } //if () }
public bool BreakInheritance(bool copyRoleAssignments, bool clearSubscopes) { bool result = true; if (HasUniquePermissions.HasValue && HasUniquePermissions.Value) { throw new InvalidBreakInheritanceException(this.Id); } SecObj.BreakRoleInheritance(copyRoleAssignments, clearSubscopes); try { CTX.Lae(); } catch { result = false; } return(result); }