Skip to content

Commit e4cfe5a

Browse files
drew-grossflovilmart
authored andcommitted
Kill without validation (#2089)
* remove WithoutValidation from config and push * remove one use of WithoutValidation * remove another WithoutValidation * Kill WithoutValidation and skipValidation
1 parent 147b493 commit e4cfe5a

File tree

4 files changed

+18
-35
lines changed

4 files changed

+18
-35
lines changed

src/Controllers/DatabaseController.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,13 @@ const validateQuery = query => {
8080
});
8181
}
8282

83-
function DatabaseController(adapter, { skipValidation } = {}) {
83+
function DatabaseController(adapter) {
8484
this.adapter = adapter;
8585

8686
// We don't want a mutable this.schema, because then you could have
8787
// one request that uses different schemas for different parts of
8888
// it. Instead, use loadSchema to get a schema.
8989
this.schemaPromise = null;
90-
this.skipValidation = !!skipValidation;
91-
}
92-
93-
DatabaseController.prototype.WithoutValidation = function() {
94-
return new DatabaseController(this.adapter, { skipValidation: true });
9590
}
9691

9792
DatabaseController.prototype.collectionExists = function(className) {
@@ -105,9 +100,6 @@ DatabaseController.prototype.purgeCollection = function(className) {
105100
};
106101

107102
DatabaseController.prototype.validateClassName = function(className) {
108-
if (this.skipValidation) {
109-
return Promise.resolve();
110-
}
111103
if (!SchemaController.classNameIsValid(className)) {
112104
return Promise.reject(new Parse.Error(Parse.Error.INVALID_CLASS_NAME, 'invalid className: ' + className));
113105
}
@@ -189,8 +181,7 @@ DatabaseController.prototype.update = function(className, query, update, {
189181
acl,
190182
many,
191183
upsert,
192-
} = {}) {
193-
184+
} = {}, skipSanitization = false) {
194185
const originalUpdate = update;
195186
// Make a copy of the object, so we don't mutate the incoming data.
196187
update = deepcopy(update);
@@ -252,7 +243,7 @@ DatabaseController.prototype.update = function(className, query, update, {
252243
if (!result) {
253244
return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.'));
254245
}
255-
if (this.skipValidation) {
246+
if (skipSanitization) {
256247
return Promise.resolve(result);
257248
}
258249
return sanitizeDatabaseResult(originalUpdate, result);

src/Controllers/UserController.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ export class UserController extends AdaptableController {
4545
// TODO: Better error here.
4646
throw undefined;
4747
}
48-
let database = this.config.database.WithoutValidation();
49-
return database.update('_User', {
48+
return this.config.database.update('_User', {
5049
username: username,
5150
_email_verify_token: token
5251
}, {emailVerified: true}).then(document => {
@@ -58,8 +57,7 @@ export class UserController extends AdaptableController {
5857
}
5958

6059
checkResetTokenValidity(username, token) {
61-
let database = this.config.database.WithoutValidation();
62-
return database.find('_User', {
60+
return this.config.database.find('_User', {
6361
username: username,
6462
_perishable_token: token
6563
}, {limit: 1}).then(results => {
@@ -114,9 +112,7 @@ export class UserController extends AdaptableController {
114112
}
115113

116114
setPasswordResetToken(email) {
117-
let token = randomString(25);
118-
let database = this.config.database.WithoutValidation();
119-
return database.update('_User', {email: email}, {_perishable_token: token});
115+
return this.config.database.update('_User', { email }, { _perishable_token: randomString(25) }, {}, true)
120116
}
121117

122118
sendPasswordResetEmail(email) {
@@ -126,8 +122,8 @@ export class UserController extends AdaptableController {
126122
return;
127123
}
128124

129-
return this.setPasswordResetToken(email).then((user) => {
130-
125+
return this.setPasswordResetToken(email)
126+
.then(user => {
131127
const token = encodeURIComponent(user._perishable_token);
132128
const username = encodeURIComponent(user.username);
133129
let link = `${this.config.requestResetPasswordURL}?token=${token}&username=${username}`
@@ -149,14 +145,12 @@ export class UserController extends AdaptableController {
149145
}
150146

151147
updatePassword(username, token, password, config) {
152-
return this.checkResetTokenValidity(username, token).then((user) => {
153-
return updateUserPassword(user.objectId, password, this.config);
154-
}).then(() => {
155-
// clear reset password token
156-
return this.config.database.WithoutValidation().update('_User', { username }, {
157-
_perishable_token: {__op: 'Delete'}
158-
});
159-
});
148+
return this.checkResetTokenValidity(username, token)
149+
.then(user => updateUserPassword(user.objectId, password, this.config))
150+
// clear reset password token
151+
.then(() => this.config.database.update('_User', { username }, {
152+
_perishable_token: {__op: 'Delete'}
153+
}));
160154
}
161155

162156
defaultVerificationEmail({link, user, appName, }) {

src/Routers/GlobalConfigRouter.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import * as middleware from "../middlewares";
55

66
export class GlobalConfigRouter extends PromiseRouter {
77
getGlobalConfig(req) {
8-
let database = req.config.database.WithoutValidation();
9-
return database.find('_GlobalConfig', { objectId: 1 }, { limit: 1 }).then((results) => {
8+
return req.config.database.find('_GlobalConfig', { objectId: 1 }, { limit: 1 }).then((results) => {
109
if (results.length != 1) {
1110
// If there is no config in the database - return empty config.
1211
return { response: { params: {} } };
@@ -23,8 +22,7 @@ export class GlobalConfigRouter extends PromiseRouter {
2322
acc[`params.${key}`] = params[key];
2423
return acc;
2524
}, {});
26-
let database = req.config.database.WithoutValidation();
27-
return database.update('_GlobalConfig', {objectId: 1}, update, {upsert: true}).then(() => ({ response: { result: true } }));
25+
return req.config.database.update('_GlobalConfig', {objectId: 1}, update, {upsert: true}).then(() => ({ response: { result: true } }));
2826
}
2927

3028
mountRoutes() {

src/pushStatusHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { md5Hash, newObjectId } from './cryptoUtils';
2-
import { logger } from './logger';
2+
import { logger } from './logger';
33

44
const PUSH_STATUS_COLLECTION = '_PushStatus';
55

@@ -19,7 +19,7 @@ export default function pushStatusHandler(config) {
1919
let initialPromise;
2020
let pushStatus;
2121
let objectId = newObjectId();
22-
let database = config.database.WithoutValidation();
22+
let database = config.database;
2323

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

0 commit comments

Comments
 (0)