Merge pull request #684 from Marco129/client-class-creation
Add allowClientClassCreation option
This commit is contained in:
@@ -59,6 +59,8 @@ function RestWrite(config, auth, className, query, data, originalData) {
|
||||
RestWrite.prototype.execute = function() {
|
||||
return Promise.resolve().then(() => {
|
||||
return this.getUserAndRoleACL();
|
||||
}).then(() => {
|
||||
return this.validateClientClassCreation();
|
||||
}).then(() => {
|
||||
return this.validateSchema();
|
||||
}).then(() => {
|
||||
@@ -105,6 +107,25 @@ RestWrite.prototype.getUserAndRoleACL = function() {
|
||||
}
|
||||
};
|
||||
|
||||
// Validates this operation against the allowClientClassCreation config.
|
||||
RestWrite.prototype.validateClientClassCreation = function() {
|
||||
if (this.config.allowClientClassCreation === false && !this.auth.isMaster) {
|
||||
return this.config.database.loadSchema().then((schema) => {
|
||||
return schema.hasClass(this.className)
|
||||
}).then((hasClass) => {
|
||||
if (hasClass === true) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN,
|
||||
'This user is not allowed to access ' +
|
||||
'non-existent class: ' + this.className);
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
// Validates this operation against the schema.
|
||||
RestWrite.prototype.validateSchema = function() {
|
||||
return this.config.database.validateObject(this.className, this.data, this.query);
|
||||
|
||||
Reference in New Issue
Block a user