Skip to content

Commit

Permalink
Fixes SchemaController data for Volatile Classes (parse-community#3171)
Browse files Browse the repository at this point in the history
* Reproduction for the issue

* Ensures Volatile classes and other schema share the same structure
  • Loading branch information
flovilmart authored and Jcarlosjunior committed Dec 13, 2016
1 parent 0cca264 commit 2fa29e6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
32 changes: 32 additions & 0 deletions spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
14 changes: 8 additions & 6 deletions src/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2fa29e6

Please sign in to comment.