/// <summary> /// Get the the permission for this collection by a given identity. /// </summary> /// <returns>The permission the identity has over the given collection</returns> public void SetPermission(TType collection, TIdentity identity, ReadWritePermission permission) { SetKeys(collection); SetKeys(identity); // Remove the collection from the list, unless we're the owners, in that case, just set it to no permission. if (permission == ReadWritePermission.None && identity.Equals(collection.owner) == false) { _collectionToIdentity[collection].Remove(identity); _identityToCollection[identity].Remove(new PermissionModel <TType>(collection, ReadWritePermission.None)); } else { _collectionToIdentity[collection].Add(identity); var c = _identityToCollection[identity]; var model = new PermissionModel <TType>(collection, permission); // The equality operator ignores the permission on the PermissionModel object, however, // the HashSet<T> doesn't update a value if the equality operator considers the object equal. // Because of this the model is never set in the hashset; The only work around I could find was removing and re-adding. c.Remove(model); c.Add(model); } // Notify event listeners if (_eventHandlers.ContainsKey(identity)) { foreach (var d in _eventHandlers[identity]) { d(new PermissionChangedResult <TType, TIdentity>(collection, identity, permission)); } } }
public bool Equals(PermissionModel <T> x, PermissionModel <T> y) { return(GetHashCode(x) == GetHashCode(y)); }
/// <summary> /// Note: The permission is ignored in the hascode, this way a collection + permission's hash will ignore the permission. /// When added to a haspmap it will overwrite previous entries. /// </summary> public int GetHashCode(PermissionModel <T> obj) { return(obj.obj.GetHashCode()); }