From 3a28352c96d0a1f18dd7e898e6698896f261bbb2 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Mon, 4 Apr 2016 08:36:40 -0400 Subject: [PATCH] :tada: fixes #1355 - injects default schema upon schema load --- spec/schemas.spec.js | 15 +++++++++++++++ src/Schema.js | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/spec/schemas.spec.js b/spec/schemas.spec.js index 3edd2e5884..e2d1955c08 100644 --- a/spec/schemas.spec.js +++ b/spec/schemas.spec.js @@ -1511,5 +1511,20 @@ describe('schemas', () => { fail('should not fail'); done(); }); + }); + + it('can login when addFields is false (issue #1355)', (done) => { + setPermissionsOnClass('_User', { + 'addField': {} + }).then(() => { + return Parse.User.signUp('foo', 'bar'); + }).then((user) => { + expect(user.getUsername()).toBe('foo'); + done() + }, (err) => { + console.error(err); + fail('should create user'); + done(); + }) }) }); diff --git a/src/Schema.js b/src/Schema.js index bcb4573ffd..0e43fc73d3 100644 --- a/src/Schema.js +++ b/src/Schema.js @@ -263,6 +263,16 @@ class Schema { } }); if (className) { + // merge with the default schema + let defaultClassData = Object.assign({}, defaultColumns._Default, defaultColumns[className]); + defaultClassData = Object.keys(defaultClassData).reduce((memo, key) => { + let type = schemaAPITypeToMongoFieldType(defaultClassData[key]).result; + if (type) { + memo[key] = type; + } + return memo; + }, {}); + classData = Object.assign({}, defaultClassData, classData); this.data[className] = classData; if (permsData) { this.perms[className] = permsData;