Skip to content

Run Schema validations after beforeSave #2672 #2677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,11 @@ it('beforeSave should not affect fetched pointers', done => {
});
});

it('should fully delete objects when using `unset` with beforeSave (regression test for #1840)', done => {
/*
TODO: fix for Postgres
trying to delete a field that doesn't exists doesn't play nice
*/
it_exclude_dbs(['postgres'])('should fully delete objects when using `unset` with beforeSave (regression test for #1840)', done => {
var TestObject = Parse.Object.extend('TestObject');
var BeforeSaveObject = Parse.Object.extend('BeforeSaveChanged');

Expand Down
36 changes: 36 additions & 0 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,42 @@ it('ensure that if you try to sign up a user with a unique username and email, b
done();
});
});

it('should not update schema beforeSave #2672', (done) => {
Parse.Cloud.beforeSave('MyObject', (request, response) => {
if (request.object.get('secret')) {
response.error('cannot set secret here');
return;
}
response.success();
});

let object = new Parse.Object('MyObject');
object.set('key', 'value');
object.save().then(() => {
return object.save({'secret': 'should not update schema'});
}).then(() => {
fail();
done();
}, () => {
return rp({
method: 'GET',
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test'
},
uri: 'http://localhost:8378/1/schemas/MyObject',
json: true
});
}).then((res) => {
let fields = res.fields;
expect(fields.secret).toBeUndefined();
done();
}, (err) => {
jfail(err);
done();
});
});
});

describe_only_db('mongo')('legacy _acl', () => {
Expand Down
5 changes: 4 additions & 1 deletion spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ const userSchema = {
"username": {"type": "String"},
"password": {"type": "String"},
"email": {"type": "String"},
"emailVerified": {"type": "Boolean"}
"emailVerified": {"type": "Boolean"},
"authData": {"type": "Object"}
},
"classLevelPermissions": defaultClassLevelPermissions,
}
Expand Down Expand Up @@ -676,6 +677,7 @@ describe('schemas', () => {
password: {type: 'String'},
email: {type: 'String'},
emailVerified: {type: 'Boolean'},
authData: {type: 'Object'},
newField: {type: 'String'},
ACL: {type: 'ACL'}
},
Expand All @@ -696,6 +698,7 @@ describe('schemas', () => {
password: {type: 'String'},
email: {type: 'String'},
emailVerified: {type: 'Boolean'},
authData: {type: 'Object'},
newField: {type: 'String'},
ACL: {type: 'ACL'}
},
Expand Down
1 change: 1 addition & 0 deletions src/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const defaultColumns = Object.freeze({
"password": {type:'String'},
"email": {type:'String'},
"emailVerified": {type:'Boolean'},
"authData": {type:'Object'}
},
// The additional default columns for the _Installation collection (in addition to DefaultCols)
_Installation: {
Expand Down
5 changes: 2 additions & 3 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ RestWrite.prototype.execute = function() {
return this.getUserAndRoleACL();
}).then(() => {
return this.validateClientClassCreation();
}).then(() => {
return this.validateSchema();
}).then(() => {
return this.handleInstallation();
}).then(() => {
Expand All @@ -72,6 +70,8 @@ RestWrite.prototype.execute = function() {
return this.validateAuthData();
}).then(() => {
return this.runBeforeTrigger();
}).then(() => {
return this.validateSchema();
}).then(() => {
return this.setRequiredFieldsIfNeeded();
}).then(() => {
Expand Down Expand Up @@ -176,7 +176,6 @@ RestWrite.prototype.runBeforeTrigger = function() {
if (this.query && this.query.objectId) {
delete this.data.objectId
}
return this.validateSchema();
}
});
};
Expand Down