Merge pull request #587 from ParsePlatform/nlutsenko.cc.test
Do not pass objectId, updatedAt, createdAt to beforeSave hooks on object create.
This commit is contained in:
@@ -50,15 +50,6 @@ function RestWrite(config, auth, className, query, data, originalData) {
|
||||
|
||||
// The timestamp we'll use for this whole operation
|
||||
this.updatedAt = Parse._encode(new Date()).iso;
|
||||
|
||||
if (this.data) {
|
||||
// Add default fields
|
||||
this.data.updatedAt = this.updatedAt;
|
||||
if (!this.query) {
|
||||
this.data.createdAt = this.updatedAt;
|
||||
this.data.objectId = cryptoUtils.newObjectId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A convenient method to perform all the steps of processing the
|
||||
@@ -76,6 +67,8 @@ RestWrite.prototype.execute = function() {
|
||||
return this.handleSession();
|
||||
}).then(() => {
|
||||
return this.runBeforeTrigger();
|
||||
}).then(() => {
|
||||
return this.setRequiredFieldsIfNeeded();
|
||||
}).then(() => {
|
||||
return this.validateAuthData();
|
||||
}).then(() => {
|
||||
@@ -99,7 +92,7 @@ RestWrite.prototype.getUserAndRoleACL = function() {
|
||||
|
||||
this.runOptions.acl = ['*'];
|
||||
|
||||
if( this.auth.user ){
|
||||
if (this.auth.user) {
|
||||
return this.auth.getUserRoles().then((roles) => {
|
||||
roles.push(this.auth.user.id);
|
||||
this.runOptions.acl = this.runOptions.acl.concat(roles);
|
||||
@@ -146,6 +139,18 @@ RestWrite.prototype.runBeforeTrigger = function() {
|
||||
});
|
||||
};
|
||||
|
||||
RestWrite.prototype.setRequiredFieldsIfNeeded = function() {
|
||||
if (this.data) {
|
||||
// Add default fields
|
||||
this.data.updatedAt = this.updatedAt;
|
||||
if (!this.query) {
|
||||
this.data.createdAt = this.updatedAt;
|
||||
this.data.objectId = cryptoUtils.newObjectId();
|
||||
}
|
||||
}
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
// Transforms auth data for a user object.
|
||||
// Does nothing if this isn't a user object.
|
||||
// Returns a promise for when we're done if it can't finish this tick.
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
var Parse = require('parse/node').Parse;
|
||||
|
||||
Parse.Cloud.define('hello', function(req, res) {
|
||||
res.success('Hello world!');
|
||||
});
|
||||
|
||||
Parse.Cloud.beforeSave('BeforeSaveFail', function(req, res) {
|
||||
res.error('You shall not pass!');
|
||||
});
|
||||
|
||||
Parse.Cloud.beforeSave('BeforeSaveFailWithPromise', function (req, res) {
|
||||
var query = new Parse.Query('Yolo');
|
||||
query.find().then(() => {
|
||||
res.error('Nope');
|
||||
}, () => {
|
||||
res.success();
|
||||
});
|
||||
});
|
||||
|
||||
Parse.Cloud.beforeSave('BeforeSaveUnchanged', function(req, res) {
|
||||
res.success();
|
||||
});
|
||||
|
||||
Parse.Cloud.beforeSave('BeforeSaveChanged', function(req, res) {
|
||||
req.object.set('foo', 'baz');
|
||||
res.success();
|
||||
});
|
||||
|
||||
Parse.Cloud.afterSave('AfterSaveTest', function(req) {
|
||||
var obj = new Parse.Object('AfterSaveProof');
|
||||
obj.set('proof', req.object.id);
|
||||
obj.save();
|
||||
});
|
||||
|
||||
Parse.Cloud.beforeDelete('BeforeDeleteFail', function(req, res) {
|
||||
res.error('Nope');
|
||||
});
|
||||
|
||||
Parse.Cloud.beforeSave('BeforeDeleteFailWithPromise', function (req, res) {
|
||||
var query = new Parse.Query('Yolo');
|
||||
query.find().then(() => {
|
||||
res.error('Nope');
|
||||
}, () => {
|
||||
res.success();
|
||||
});
|
||||
});
|
||||
|
||||
Parse.Cloud.beforeDelete('BeforeDeleteTest', function(req, res) {
|
||||
res.success();
|
||||
});
|
||||
|
||||
Parse.Cloud.afterDelete('AfterDeleteTest', function(req) {
|
||||
var obj = new Parse.Object('AfterDeleteProof');
|
||||
obj.set('proof', req.object.id);
|
||||
obj.save();
|
||||
});
|
||||
|
||||
Parse.Cloud.beforeSave('SaveTriggerUser', function(req, res) {
|
||||
if (req.user && req.user.id) {
|
||||
res.success();
|
||||
} else {
|
||||
res.error('No user present on request object for beforeSave.');
|
||||
}
|
||||
});
|
||||
|
||||
Parse.Cloud.afterSave('SaveTriggerUser', function(req) {
|
||||
if (!req.user || !req.user.id) {
|
||||
console.log('No user present on request object for afterSave.');
|
||||
}
|
||||
});
|
||||
|
||||
Parse.Cloud.define('foo', function(req, res) {
|
||||
res.success({
|
||||
object: {
|
||||
__type: 'Object',
|
||||
className: 'Foo',
|
||||
objectId: '123',
|
||||
x: 2,
|
||||
relation: {
|
||||
__type: 'Object',
|
||||
className: 'Bar',
|
||||
objectId: '234',
|
||||
x: 3
|
||||
}
|
||||
},
|
||||
array: [{
|
||||
__type: 'Object',
|
||||
className: 'Bar',
|
||||
objectId: '345',
|
||||
x: 2
|
||||
}],
|
||||
a: 2
|
||||
});
|
||||
});
|
||||
|
||||
Parse.Cloud.define('bar', function(req, res) {
|
||||
res.error('baz');
|
||||
});
|
||||
|
||||
Parse.Cloud.define('requiredParameterCheck', function(req, res) {
|
||||
res.success();
|
||||
}, function(params) {
|
||||
return params.name;
|
||||
});
|
||||
Reference in New Issue
Block a user