Fixes SchemaController data for Volatile Classes (#3171)
* Reproduction for the issue * Ensures Volatile classes and other schema share the same structure
This commit is contained in:
@@ -880,6 +880,38 @@ describe('SchemaController', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('properly handles volatile _Schemas', done => {
|
||||
function validateSchemaStructure(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];
|
||||
// Hooks has className...
|
||||
if (className != '_Hooks') {
|
||||
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', () => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user