diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c2f832d..925e644f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ ### Bug fixes * 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). ### Internals diff --git a/lib/user-methods.js b/lib/user-methods.js index f1bbce2c..69411a78 100644 --- a/lib/user-methods.js +++ b/lib/user-methods.js @@ -543,7 +543,8 @@ const instanceMethods = { sync: { user: this, url: realmUrl, - } + }, + schema: [], }; // 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; } + // 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. // 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`. diff --git a/tests/js/session-tests.js b/tests/js/session-tests.js index 4a070c0e..c1f795d9 100644 --- a/tests/js/session-tests.js +++ b/tests/js/session-tests.js @@ -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'); + }); + }); + } +}