Skip to content

Commit 2e569ca

Browse files
authored
Fixes SchemaController data for Volatile Classes (#3171)
* Reproduction for the issue * Ensures Volatile classes and other schema share the same structure
1 parent 8111c33 commit 2e569ca

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

spec/Schema.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,38 @@ describe('SchemaController', () => {
880880
done();
881881
});
882882
});
883+
884+
it('properly handles volatile _Schemas', done => {
885+
function validateSchemaStructure(schema) {
886+
expect(schema.hasOwnProperty('className')).toBe(true);
887+
expect(schema.hasOwnProperty('fields')).toBe(true);
888+
expect(schema.hasOwnProperty('classLevelPermissions')).toBe(true);
889+
}
890+
function validateSchemaDataStructure(schemaData) {
891+
Object.keys(schemaData).forEach(className => {
892+
let schema = schemaData[className];
893+
// Hooks has className...
894+
if (className != '_Hooks') {
895+
expect(schema.hasOwnProperty('className')).toBe(false);
896+
}
897+
expect(schema.hasOwnProperty('fields')).toBe(false);
898+
expect(schema.hasOwnProperty('classLevelPermissions')).toBe(false);
899+
});
900+
}
901+
let schema;
902+
config.database.loadSchema().then(s => {
903+
schema = s;
904+
return schema.getOneSchema('_User', false);
905+
}).then(userSchema => {
906+
validateSchemaStructure(userSchema);
907+
validateSchemaDataStructure(schema.data);
908+
return schema.getOneSchema('_PushStatus', true);
909+
}).then(pushStatusSchema => {
910+
validateSchemaStructure(pushStatusSchema);
911+
validateSchemaDataStructure(schema.data);
912+
done();
913+
});
914+
});
883915
});
884916

885917
describe('Class Level Permissions for requiredAuth', () => {

src/Controllers/SchemaController.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,9 @@ export default class SchemaController {
346346

347347
// Inject the in-memory classes
348348
volatileClasses.forEach(className => {
349-
this.data[className] = injectDefaultSchema({
350-
className,
351-
fields: {},
352-
classLevelPermissions: {}
353-
});
349+
let schema = injectDefaultSchema({ className });
350+
this.data[className] = schema.fields;
351+
this.perms[className] = schema.classLevelPermissions;
354352
});
355353
delete this.reloadDataPromise;
356354
}, (err) => {
@@ -388,7 +386,11 @@ export default class SchemaController {
388386
}
389387
return promise.then(() => {
390388
if (allowVolatileClasses && volatileClasses.indexOf(className) > -1) {
391-
return Promise.resolve(this.data[className]);
389+
return Promise.resolve({
390+
className,
391+
fields: this.data[className],
392+
classLevelPermissions: this.perms[className]
393+
});
392394
}
393395
return this._cache.getOneSchema(className).then((cached) => {
394396
if (cached && !options.clearCache) {

0 commit comments

Comments
 (0)