private static void AssertObjectPrivileges(Realm realm, ObjectPrivileges expected) { foreach (var obj in realm.All <ObjectWithPermissions>()) { var objectPrivileges = realm.GetPrivileges(obj); Assert.That(objectPrivileges, Is.EqualTo(expected)); } }
private static void AssertRealmPrivileges(Realm realm, RealmPrivileges expected) { var realmPrivileges = realm.GetPrivileges(); Assert.That(realmPrivileges, Is.EqualTo(expected)); }
private static void AssertClassPrivileges(Realm realm, ClassPrivileges expected) { var classPrivileges = realm.GetPrivileges <ObjectWithPermissions>(); Assert.That(classPrivileges, Is.EqualTo(expected)); }
/// <summary> /// Returns the computed privileges which the current user has for the given class. /// <para/> /// This combines all privileges granted on the class by all Roles which the /// current User is a member of into the final privileges which will be /// enforced by the server. /// <para/> /// The privilege calculation is done locally using cached data, and inherently /// may be stale. It is possible that this method may indicate that an /// operation is permitted but the server will still reject it if permission is /// revoked before the changes have been integrated on the server. /// <para/> /// Non-synchronized Realms always have permission to perform all operations. /// </summary> /// <typeparam name="T">The <see cref="RealmObject"/> inheritor to get the privileges for.</typeparam> /// <param name="realm">The Realm whose privileges are inspected.</param> /// <returns>The privileges which the current user has for the given class.</returns> public static ClassPrivileges GetPrivileges <T>(this Realm realm) where T : RealmObject { return(realm.GetPrivileges(typeof(T).GetTypeInfo().GetMappedOrOriginalName())); }