Skip to content

Commit

Permalink
Renames Unsafe to WithoutValidation
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Apr 14, 2016
1 parent 8ebeb76 commit 035146b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ var Parse = require('parse/node').Parse;
var Schema = require('./../Schema');
const deepcopy = require('deepcopy');

function DatabaseController(adapter, { unsafe } = {}) {
function DatabaseController(adapter, { skipValidation } = {}) {
this.adapter = adapter;

// We don't want a mutable this.schema, because then you could have
// one request that uses different schemas for different parts of
// it. Instead, use loadSchema to get a schema.
this.schemaPromise = null;
this.unsafe = !!unsafe;
this.skipValidation = !!skipValidation;
this.connect();

Object.defineProperty(this, 'transform', {
Expand All @@ -26,8 +26,8 @@ function DatabaseController(adapter, { unsafe } = {}) {
})
}

DatabaseController.prototype.Unsafe = function() {
return new DatabaseController(this.adapter, {collectionPrefix: this.collectionPrefix, unsafe: true});
DatabaseController.prototype.WithoutValidation = function() {
return new DatabaseController(this.adapter, {collectionPrefix: this.collectionPrefix, skipValidation: true});
}

// Connects to the database. Returns a promise that resolves when the
Expand All @@ -49,7 +49,7 @@ DatabaseController.prototype.dropCollection = function(className) {
};

DatabaseController.prototype.validateClassName = function(className) {
if (this.unsafe) {
if (this.skipValidation) {
return Promise.resolve();
}
if (!Schema.classNameIsValid(className)) {
Expand Down Expand Up @@ -167,11 +167,11 @@ DatabaseController.prototype.update = function(className, query, update, options
.then(() => this.handleRelationUpdates(className, query.objectId, update))
.then(() => this.adapter.adaptiveCollection(className))
.then(collection => {
var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.unsafe});
var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation});
if (options.acl) {
mongoWhere = this.transform.addWriteACL(mongoWhere, options.acl);
}
mongoUpdate = this.transform.transformUpdate(schema, className, update, {validate: !this.unsafe});
mongoUpdate = this.transform.transformUpdate(schema, className, update, {validate: !this.skipValidation});
if (options.many) {
return collection.updateMany(mongoWhere, mongoUpdate);
}else if (options.upsert) {
Expand All @@ -185,7 +185,7 @@ DatabaseController.prototype.update = function(className, query, update, options
return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
'Object not found.'));
}
if (this.unsafe) {
if (this.skipValidation) {
return Promise.resolve(result);
}
return sanitizeDatabaseResult(originalUpdate, result);
Expand Down Expand Up @@ -307,7 +307,7 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
})
.then(() => this.adapter.adaptiveCollection(className))
.then(collection => {
let mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.unsafe});
let mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation});
if (options.acl) {
mongoWhere = this.transform.addWriteACL(mongoWhere, options.acl);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/HooksController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class HooksController {
constructor(applicationId:string, collectionPrefix:string = '') {
this._applicationId = applicationId;
this._collectionPrefix = collectionPrefix;
this.database = DatabaseAdapter.getDatabaseConnection(this._applicationId, this._collectionPrefix).Unsafe();
this.database = DatabaseAdapter.getDatabaseConnection(this._applicationId, this._collectionPrefix).WithoutValidation();
}

load() {
Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class UserController extends AdaptableController {
// TODO: Better error here.
return Promise.reject();
}
let database = this.config.database.Unsafe();
let database = this.config.database.WithoutValidation();
return database.update('_User', {
username: username,
_email_verify_token: token
Expand All @@ -58,7 +58,7 @@ export class UserController extends AdaptableController {
}

checkResetTokenValidity(username, token) {
let database = this.config.database.Unsafe();
let database = this.config.database.WithoutValidation();
return database.find('_User', {
username: username,
_perishable_token: token
Expand Down Expand Up @@ -115,7 +115,7 @@ export class UserController extends AdaptableController {

setPasswordResetToken(email) {
let token = randomString(25);
let database = this.config.database.Unsafe();
let database = this.config.database.WithoutValidation();
return database.update('_User', {email: email}, {_perishable_token: token});
}

Expand Down Expand Up @@ -153,7 +153,7 @@ export class UserController extends AdaptableController {
return updateUserPassword(user.objectId, password, this.config);
}).then(() => {
// clear reset password token
return this.config.database.Unsafe().update('_User', { username }, {
return this.config.database.WithoutValidation().update('_User', { username }, {
_perishable_token: {__op: 'Delete'}
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/Routers/GlobalConfigRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as middleware from "../middlewares";

export class GlobalConfigRouter extends PromiseRouter {
getGlobalConfig(req) {
let database = req.config.database.Unsafe();
let database = req.config.database.WithoutValidation();
return database.find('_GlobalConfig', { '_id': 1 }, { limit: 1 }).then((results) => {
if (results.length != 1) {
// If there is no config in the database - return empty config.
Expand All @@ -23,7 +23,7 @@ export class GlobalConfigRouter extends PromiseRouter {
acc[`params.${key}`] = params[key];
return acc;
}, {});
let database = req.config.database.Unsafe();
let database = req.config.database.WithoutValidation();
return database.update('_GlobalConfig', {_id: 1}, update, {upsert: true}).then(() => {
return Promise.resolve({ response: { result: true } });
});
Expand Down
2 changes: 1 addition & 1 deletion src/pushStatusHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function pushStatusHandler(config) {
let initialPromise;
let pushStatus;
let objectId = newObjectId();
let database = config.database.Unsafe();
let database = config.database.WithoutValidation();

let setInitial = function(body = {}, where, options = {source: 'rest'}) {
let now = new Date();
Expand Down

0 comments on commit 035146b

Please sign in to comment.