Automatically add schemas for object level permissions. (#1970)

This commit is contained in:
Christian Melchior 2018-08-17 10:10:20 +02:00 committed by GitHub
parent 0d5e4ad5be
commit a58a984f3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View File

@ -17,6 +17,7 @@
### Bug fixes ### Bug fixes
* React Native for Android now supports the Android Gradle Plugin 3.0 (#1742). * React Native for Android now supports the Android Gradle Plugin 3.0 (#1742).
* [Sync] Classes used by the Object-level permission system are now automatically part of the schema for Query-based Realms (#1966).
* [Sync] Fixed distinct queries with query-based sync (broken since v2.11.0). * [Sync] Fixed distinct queries with query-based sync (broken since v2.11.0).
### Internals ### Internals

View File

@ -543,7 +543,8 @@ const instanceMethods = {
sync: { sync: {
user: this, user: this,
url: realmUrl, url: realmUrl,
} },
schema: [],
}; };
// Set query-based as the default setting if the user doesn't specified any other behaviour. // Set query-based as the default setting if the user doesn't specified any other behaviour.
@ -551,6 +552,16 @@ const instanceMethods = {
defaultConfig.sync.fullSynchronization = false; defaultConfig.sync.fullSynchronization = false;
} }
// Automatically add Permission classes to the schema if Query-based sync is enabled
if (defaultConfig.sync.fullSynchronization === false || (config && config.sync && config.sync.partial === true)) {
defaultConfig.schema = [
Realm.Permissions.Class,
Realm.Permissions.Permission,
Realm.Permissions.Role,
Realm.Permissions.User,
];
}
// Merge default configuration with user provided config. User defined properties should aways win. // Merge default configuration with user provided config. User defined properties should aways win.
// Doing the naive merge in JS break objects that are backed by native objects, so these needs to // Doing the naive merge in JS break objects that are backed by native objects, so these needs to
// be merged manually. This is currently only `sync.user`. // be merged manually. This is currently only `sync.user`.

View File

@ -1036,4 +1036,17 @@ module.exports = {
}); });
}, },
}; testOfflinePermissionSchemas() {
if (!isNodeProccess) {
return;
}
return Realm.Sync.User.register('http://localhost:9080', uuid(), 'password').then((u) => {
return new Promise((resolve, reject) => {
let realm = new Realm(u.createConfiguration());
TestCase.assertEqual(5, realm.objects(Realm.Permissions.Class.schema.name).length);
resolve('Done');
});
});
}
}