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 12, 2016
1 parent 43805f5 commit a568a98
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
18 changes: 9 additions & 9 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const deepcopy = require('deepcopy');

// options can contain:
// collectionPrefix: the string to put in front of every collection name.
function DatabaseController(adapter, { collectionPrefix, unsafe } = {}) {
function DatabaseController(adapter, { collectionPrefix, skipValidation } = {}) {
this.adapter = adapter;

this.collectionPrefix = collectionPrefix;
Expand All @@ -20,7 +20,7 @@ function DatabaseController(adapter, { collectionPrefix, unsafe } = {}) {
// 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 @@ -30,8 +30,8 @@ function DatabaseController(adapter, { collectionPrefix, 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 Down Expand Up @@ -61,7 +61,7 @@ function returnsTrue() {
}

DatabaseController.prototype.validateClassName = function(className) {
if (this.unsafe) {
if (this.skipValidation) {
return Promise.resolve();
}
if (!Schema.classNameIsValid(className)) {
Expand Down Expand Up @@ -179,11 +179,11 @@ DatabaseController.prototype.update = function(className, query, update, options
.then(() => this.handleRelationUpdates(className, query.objectId, update))
.then(() => adaptiveCollection(this, 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 @@ -197,7 +197,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 @@ -319,7 +319,7 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
})
.then(() => adaptiveCollection(this, 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
6 changes: 3 additions & 3 deletions src/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,9 @@ class Schema {

// for non-relations, remove all the data.
// This is necessary to ensure that the data is still gone if they add the same field.
let unsafeDB = database.Unsafe();
let transformFieldName = unsafeDB.transform.transformKey(this, className, fieldName);
return unsafeDB.update(className, {}, {[transformFieldName]: {__op: 'Delete'}}, {many: true});
let db = database.WithoutValidation();
let transformFieldName = db.transform.transformKey(this, className, fieldName);
return db.update(className, {}, {[transformFieldName]: {__op: 'Delete'}}, {many: true});
})
// Save the _SCHEMA object
.then(() => this._collection.updateSchema(className, { $unset: { [fieldName]: null } }));
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 a568a98

Please sign in to comment.