From c3ab1ec60e183d3873dfd56e2903a083ebfcc309 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Sat, 3 Dec 2016 16:10:26 -0500 Subject: [PATCH 1/2] Reproduction for the issue --- spec/Schema.spec.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/Schema.spec.js b/spec/Schema.spec.js index 0f23a108a8..3fb27fe54b 100644 --- a/spec/Schema.spec.js +++ b/spec/Schema.spec.js @@ -880,6 +880,36 @@ describe('SchemaController', () => { done(); }); }); + + it('properly handles volatile _Schemas', done => { + function validateSchemaStructure(schema) { + console.log(schema); + expect(schema.hasOwnProperty('className')).toBe(true); + expect(schema.hasOwnProperty('fields')).toBe(true); + expect(schema.hasOwnProperty('classLevelPermissions')).toBe(true); + } + function validateSchemaDataStructure(schemaData) { + Object.keys(schemaData).forEach(className => { + let schema = schemaData[className]; + expect(schema.hasOwnProperty('className')).toBe(false); + expect(schema.hasOwnProperty('fields')).toBe(false); + expect(schema.hasOwnProperty('classLevelPermissions')).toBe(false); + }); + } + let schema; + config.database.loadSchema().then(s => { + schema = s; + return schema.getOneSchema('_User', false); + }).then(userSchema => { + validateSchemaStructure(userSchema); + validateSchemaDataStructure(schema.data); + return schema.getOneSchema('_PushStatus', true); + }).then(pushStatusSchema => { + validateSchemaStructure(pushStatusSchema); + validateSchemaDataStructure(schema.data); + done(); + }); + }); }); describe('Class Level Permissions for requiredAuth', () => { From 75488abf1fccc1e39cbc62ef98a43add29668cdc Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Sat, 3 Dec 2016 16:10:34 -0500 Subject: [PATCH 2/2] Ensures Volatile classes and other schema share the same structure --- spec/Schema.spec.js | 6 ++++-- src/Controllers/SchemaController.js | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/spec/Schema.spec.js b/spec/Schema.spec.js index 3fb27fe54b..ca7b1fb65a 100644 --- a/spec/Schema.spec.js +++ b/spec/Schema.spec.js @@ -883,7 +883,6 @@ describe('SchemaController', () => { it('properly handles volatile _Schemas', done => { function validateSchemaStructure(schema) { - console.log(schema); expect(schema.hasOwnProperty('className')).toBe(true); expect(schema.hasOwnProperty('fields')).toBe(true); expect(schema.hasOwnProperty('classLevelPermissions')).toBe(true); @@ -891,7 +890,10 @@ describe('SchemaController', () => { function validateSchemaDataStructure(schemaData) { Object.keys(schemaData).forEach(className => { let schema = schemaData[className]; - expect(schema.hasOwnProperty('className')).toBe(false); + // Hooks has className... + if (className != '_Hooks') { + expect(schema.hasOwnProperty('className')).toBe(false); + } expect(schema.hasOwnProperty('fields')).toBe(false); expect(schema.hasOwnProperty('classLevelPermissions')).toBe(false); }); diff --git a/src/Controllers/SchemaController.js b/src/Controllers/SchemaController.js index 21d252c607..19e83b8ca0 100644 --- a/src/Controllers/SchemaController.js +++ b/src/Controllers/SchemaController.js @@ -346,11 +346,9 @@ export default class SchemaController { // Inject the in-memory classes volatileClasses.forEach(className => { - this.data[className] = injectDefaultSchema({ - className, - fields: {}, - classLevelPermissions: {} - }); + let schema = injectDefaultSchema({ className }); + this.data[className] = schema.fields; + this.perms[className] = schema.classLevelPermissions; }); delete this.reloadDataPromise; }, (err) => { @@ -388,7 +386,11 @@ export default class SchemaController { } return promise.then(() => { if (allowVolatileClasses && volatileClasses.indexOf(className) > -1) { - return Promise.resolve(this.data[className]); + return Promise.resolve({ + className, + fields: this.data[className], + classLevelPermissions: this.perms[className] + }); } return this._cache.getOneSchema(className).then((cached) => { if (cached && !options.clearCache) {