From 546a8a90cfa922ec25fb58ddf8e364106f4e41af Mon Sep 17 00:00:00 2001 From: Lucian Mateescu Date: Sun, 31 Jan 2016 10:48:01 +0200 Subject: [PATCH 1/7] added user, isMaster, installationId on functions as Parse.Cloud.FunctionRequest specs --- functions.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/functions.js b/functions.js index cf4aeb28bf..194c15ec08 100644 --- a/functions.js +++ b/functions.js @@ -13,7 +13,10 @@ function handleCloudFunction(req) { return new Promise(function (resolve, reject) { var response = createResponseObject(resolve, reject); var request = { - params: req.body || {} + params: req.body || {}, + master : req.auth ? req.auth.isMaster : false, + user : req.auth && req.auth.user ? req.auth.user : undefined, + installationId : req.auth && req.auth.installationId ? req.auth.installationId : undefined }; Parse.Cloud.Functions[req.params.functionName](request, response); }); @@ -34,10 +37,10 @@ function createResponseObject(resolve, reject) { error: function(error) { reject(new Parse.Error(Parse.Error.SCRIPT_FAILED, error)); } - } + }; } -router.route('POST', '/functions/:functionName', handleCloudFunction); +router.route('POST', '/functions/:functionName+', handleCloudFunction); module.exports = router; From b96f72d800ac1f466fdf78cfe4c19873ba38c03f Mon Sep 17 00:00:00 2001 From: Lucian Mateescu Date: Sun, 31 Jan 2016 14:58:25 +0200 Subject: [PATCH 2/7] Schema is frozen unless isMaster (maser key used) or NODE_ENV === 'development' --- ExportAdapter.js | 4 ++-- RestWrite.js | 3 ++- Schema.js | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ExportAdapter.js b/ExportAdapter.js index 89cb6c5900..83ec24bc3a 100644 --- a/ExportAdapter.js +++ b/ExportAdapter.js @@ -111,9 +111,9 @@ ExportAdapter.prototype.redirectClassNameForKey = function(className, key) { // Returns a promise that resolves to the new schema. // This does not update this.schema, because in a situation like a // batch request, that could confuse other users of the schema. -ExportAdapter.prototype.validateObject = function(className, object) { +ExportAdapter.prototype.validateObject = function(className, object, freeze) { return this.loadSchema().then((schema) => { - return schema.validateObject(className, object); + return schema.validateObject(className, object, freeze); }); }; diff --git a/RestWrite.js b/RestWrite.js index 2e57f8fcc8..db374d2bbb 100644 --- a/RestWrite.js +++ b/RestWrite.js @@ -90,7 +90,8 @@ RestWrite.prototype.execute = function() { // Validates this operation against the schema. RestWrite.prototype.validateSchema = function() { - return this.config.database.validateObject(this.className, this.data); + var schemaFrozen = (process.env.NODE_ENV !== 'development') ? !(this.auth && this.auth.isMaster) : false; + return this.config.database.validateObject(this.className, this.data, schemaFrozen); }; // Runs any beforeSave triggers against this operation. diff --git a/Schema.js b/Schema.js index c95444045e..8b6accc5ce 100644 --- a/Schema.js +++ b/Schema.js @@ -199,18 +199,18 @@ Schema.prototype.validateField = function(className, key, type, freeze) { // Given a schema promise, construct another schema promise that // validates this field once the schema loads. -function thenValidateField(schemaPromise, className, key, type) { +function thenValidateField(schemaPromise, className, key, type, freeze) { return schemaPromise.then((schema) => { - return schema.validateField(className, key, type); + return schema.validateField(className, key, type, freeze); }); } // Validates an object provided in REST format. // Returns a promise that resolves to the new schema if this object is // valid. -Schema.prototype.validateObject = function(className, object) { +Schema.prototype.validateObject = function(className, object, freeze) { var geocount = 0; - var promise = this.validateClassName(className); + var promise = this.validateClassName(className, freeze); for (var key in object) { var expected = getType(object[key]); if (expected === 'geopoint') { @@ -224,7 +224,7 @@ Schema.prototype.validateObject = function(className, object) { if (!expected) { continue; } - promise = thenValidateField(promise, className, key, expected); + promise = thenValidateField(promise, className, key, expected, freeze); } return promise; }; From 171cba6f28ee7785d95c7d01d142dcbb8840b89b Mon Sep 17 00:00:00 2001 From: Lucian Mateescu Date: Wed, 3 Feb 2016 00:11:38 +0200 Subject: [PATCH 3/7] rezolved git messup --- functions.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/functions.js b/functions.js index 933da4c823..8a60d7b84c 100644 --- a/functions.js +++ b/functions.js @@ -13,13 +13,9 @@ function handleCloudFunction(req) { var response = createResponseObject(resolve, reject); var request = { params: req.body || {}, -<<<<<<< HEAD master : req.auth ? req.auth.isMaster : false, - user : req.auth && req.auth.user ? req.auth.user : undefined, - installationId : req.auth && req.auth.installationId ? req.auth.installationId : undefined -======= + installationId : req.auth && req.auth.installationId ? req.auth.installationId : undefined, user: req.auth && req.auth.user || {} ->>>>>>> upstream/master }; Parse.Cloud.Functions[req.params.functionName](request, response); }); From c5a72d0affe06f5e7a99ab64913721b6a6cebd27 Mon Sep 17 00:00:00 2001 From: Lucian Mateescu Date: Sat, 6 Feb 2016 08:49:58 +0200 Subject: [PATCH 4/7] fixed crash on nonexistend field relation query --- ExportAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExportAdapter.js b/ExportAdapter.js index d113ac0001..136b1671f3 100644 --- a/ExportAdapter.js +++ b/ExportAdapter.js @@ -105,7 +105,7 @@ ExportAdapter.prototype.loadSchema = function(acceptor) { ExportAdapter.prototype.redirectClassNameForKey = function(className, key) { return this.loadSchema().then((schema) => { var t = schema.getExpectedType(className, key); - var match = t.match(/^relation<(.*)>$/); + var match = t ? t.match(/^relation<(.*)>$/) : false; // if no field exist, undefined.match error thrown if (match) { return match[1]; } else { From f1f353edcee247a85e06a0a2eab090e9e8b44d66 Mon Sep 17 00:00:00 2001 From: lucianmat Date: Sun, 7 Feb 2016 08:34:48 +0200 Subject: [PATCH 5/7] Revert "Merge branch 'master' of https://github.com/lucianmat/parse-server" This reverts commit 31e37a6aade3db2f132eea262b9c7eea2703ad0e, reversing changes made to 9a14f53e45c29b4fd0c530ea23194fc33ce45f7f. --- ExportAdapter.js | 4 ++-- RestWrite.js | 3 +-- Schema.js | 10 +++++----- functions.js | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ExportAdapter.js b/ExportAdapter.js index 136b1671f3..63c9539976 100644 --- a/ExportAdapter.js +++ b/ExportAdapter.js @@ -118,9 +118,9 @@ ExportAdapter.prototype.redirectClassNameForKey = function(className, key) { // Returns a promise that resolves to the new schema. // This does not update this.schema, because in a situation like a // batch request, that could confuse other users of the schema. -ExportAdapter.prototype.validateObject = function(className, object, freeze) { +ExportAdapter.prototype.validateObject = function(className, object) { return this.loadSchema().then((schema) => { - return schema.validateObject(className, object, freeze); + return schema.validateObject(className, object); }); }; diff --git a/RestWrite.js b/RestWrite.js index e5740cbbe9..446a2db9a2 100644 --- a/RestWrite.js +++ b/RestWrite.js @@ -91,8 +91,7 @@ RestWrite.prototype.execute = function() { // Validates this operation against the schema. RestWrite.prototype.validateSchema = function() { - var schemaFrozen = (process.env.NODE_ENV !== 'development') ? !(this.auth && this.auth.isMaster) : false; - return this.config.database.validateObject(this.className, this.data, schemaFrozen); + return this.config.database.validateObject(this.className, this.data); }; // Runs any beforeSave triggers against this operation. diff --git a/Schema.js b/Schema.js index 10c843e395..25e301cdd9 100644 --- a/Schema.js +++ b/Schema.js @@ -412,18 +412,18 @@ Schema.prototype.validateField = function(className, key, type, freeze) { // Given a schema promise, construct another schema promise that // validates this field once the schema loads. -function thenValidateField(schemaPromise, className, key, type, freeze) { +function thenValidateField(schemaPromise, className, key, type) { return schemaPromise.then((schema) => { - return schema.validateField(className, key, type, freeze); + return schema.validateField(className, key, type); }); } // Validates an object provided in REST format. // Returns a promise that resolves to the new schema if this object is // valid. -Schema.prototype.validateObject = function(className, object, freeze) { +Schema.prototype.validateObject = function(className, object) { var geocount = 0; - var promise = this.validateClassName(className, freeze); + var promise = this.validateClassName(className); for (var key in object) { if (object[key] === undefined) { continue; @@ -440,7 +440,7 @@ Schema.prototype.validateObject = function(className, object, freeze) { if (!expected) { continue; } - promise = thenValidateField(promise, className, key, expected, freeze); + promise = thenValidateField(promise, className, key, expected); } return promise; }; diff --git a/functions.js b/functions.js index 39dbac2e67..09e43ed344 100644 --- a/functions.js +++ b/functions.js @@ -42,10 +42,10 @@ function createResponseObject(resolve, reject) { error: function(error) { reject(new Parse.Error(Parse.Error.SCRIPT_FAILED, error)); } - }; + } } -router.route('POST', '/functions/:functionName+', handleCloudFunction); +router.route('POST', '/functions/:functionName', handleCloudFunction); module.exports = router; From 9b18e42245f2c25948dd7e1a64fef0ce7951f8eb Mon Sep 17 00:00:00 2001 From: lucianmat Date: Sun, 7 Feb 2016 08:34:56 +0200 Subject: [PATCH 6/7] Revert "fixed crash on nonexistend field relation query" This reverts commit c5a72d0affe06f5e7a99ab64913721b6a6cebd27. --- ExportAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExportAdapter.js b/ExportAdapter.js index 63c9539976..df417ac83a 100644 --- a/ExportAdapter.js +++ b/ExportAdapter.js @@ -105,7 +105,7 @@ ExportAdapter.prototype.loadSchema = function(acceptor) { ExportAdapter.prototype.redirectClassNameForKey = function(className, key) { return this.loadSchema().then((schema) => { var t = schema.getExpectedType(className, key); - var match = t ? t.match(/^relation<(.*)>$/) : false; // if no field exist, undefined.match error thrown + var match = t.match(/^relation<(.*)>$/); if (match) { return match[1]; } else { From 7bd66ec61a518b3ebcbd265faf3f7e0c2eebdde0 Mon Sep 17 00:00:00 2001 From: lucianmat Date: Sun, 7 Feb 2016 10:08:39 +0200 Subject: [PATCH 7/7] fixed query crash on nonexistent field relation For example, query for Role users, when no user is added to any role. --- ExportAdapter.js | 2 +- spec/ParseRole.spec.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ExportAdapter.js b/ExportAdapter.js index df417ac83a..f12bb8384b 100644 --- a/ExportAdapter.js +++ b/ExportAdapter.js @@ -105,7 +105,7 @@ ExportAdapter.prototype.loadSchema = function(acceptor) { ExportAdapter.prototype.redirectClassNameForKey = function(className, key) { return this.loadSchema().then((schema) => { var t = schema.getExpectedType(className, key); - var match = t.match(/^relation<(.*)>$/); + var match = t ? t.match(/^relation<(.*)>$/) : false; if (match) { return match[1]; } else { diff --git a/spec/ParseRole.spec.js b/spec/ParseRole.spec.js index 44476f1bd2..57c54fceaa 100644 --- a/spec/ParseRole.spec.js +++ b/spec/ParseRole.spec.js @@ -58,5 +58,19 @@ describe('Parse Role testing', () => { }); + it('user role subscribers', (done)=> { + var role = new Parse.Role(); + role.set('name','subscribers'); + role.save({}, {useMasterKey : true}) + .then((x)=>{ + var query = role.relation('users').query(); + query.find({useMasterKey : true}) + .then((users)=>{ + done(); + }, (e)=>{ + fail('should not have errors'); + }); + }); + }) });