Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ExportAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

Expand Down
3 changes: 2 additions & 1 deletion RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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;
};
Expand Down
9 changes: 6 additions & 3 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the + sign here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • will allow to have a structured calls on functions, such as
Parse.Cloud.run('workflow/list', { objs : true}), 

extending functions reach.
It is an optional route parameter from express, it will be ignored if it is not present and it will work as pervious.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires latest express and path-to-regexp version, otherwise it will fallback to initial behaviour.



module.exports = router;