refactor: Add option to convert Parse.Object to instance in Cloud Function payload (#8656)
This commit is contained in:
@@ -9,7 +9,7 @@ import { jobStatusHandler } from '../StatusHandler';
|
||||
import _ from 'lodash';
|
||||
import { logger } from '../logger';
|
||||
|
||||
function parseObject(obj) {
|
||||
function parseObject(obj, config) {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(item => {
|
||||
return parseObject(item);
|
||||
@@ -18,21 +18,21 @@ function parseObject(obj) {
|
||||
return Object.assign(new Date(obj.iso), obj);
|
||||
} else if (obj && obj.__type == 'File') {
|
||||
return Parse.File.fromJSON(obj);
|
||||
} else if (obj && obj.__type == 'Pointer') {
|
||||
} else if (obj && obj.__type == 'Pointer' && config.encodeParseObjectInCloudFunction) {
|
||||
return Parse.Object.fromJSON({
|
||||
__type: 'Pointer',
|
||||
className: obj.className,
|
||||
objectId: obj.objectId,
|
||||
});
|
||||
} else if (obj && typeof obj === 'object') {
|
||||
return parseParams(obj);
|
||||
return parseParams(obj, config);
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
function parseParams(params) {
|
||||
return _.mapValues(params, parseObject);
|
||||
function parseParams(params, config) {
|
||||
return _.mapValues(params, item => parseObject(item, config));
|
||||
}
|
||||
|
||||
export class FunctionsRouter extends PromiseRouter {
|
||||
@@ -66,7 +66,7 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Invalid job.');
|
||||
}
|
||||
let params = Object.assign({}, req.body, req.query);
|
||||
params = parseParams(params);
|
||||
params = parseParams(params, req.config);
|
||||
const request = {
|
||||
params: params,
|
||||
log: req.config.loggerController,
|
||||
@@ -126,7 +126,7 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, `Invalid function: "${functionName}"`);
|
||||
}
|
||||
let params = Object.assign({}, req.body, req.query);
|
||||
params = parseParams(params);
|
||||
params = parseParams(params, req.config);
|
||||
const request = {
|
||||
params: params,
|
||||
master: req.auth && req.auth.isMaster,
|
||||
|
||||
@@ -125,7 +125,7 @@ export class PagesRouter extends PromiseRouter {
|
||||
|
||||
const userController = config.userController;
|
||||
|
||||
return userController.resendVerificationEmail(username).then(
|
||||
return userController.resendVerificationEmail(username, req).then(
|
||||
() => {
|
||||
return this.goToPage(req, pages.emailVerificationSendSuccess);
|
||||
},
|
||||
|
||||
@@ -63,7 +63,7 @@ export class PublicAPIRouter extends PromiseRouter {
|
||||
|
||||
const userController = config.userController;
|
||||
|
||||
return userController.resendVerificationEmail(username).then(
|
||||
return userController.resendVerificationEmail(username, req).then(
|
||||
() => {
|
||||
return Promise.resolve({
|
||||
status: 302,
|
||||
|
||||
@@ -447,7 +447,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
}
|
||||
}
|
||||
|
||||
handleVerificationEmailRequest(req) {
|
||||
async handleVerificationEmailRequest(req) {
|
||||
this._throwOnBadEmailConfig(req);
|
||||
|
||||
const { email } = req.body;
|
||||
@@ -461,25 +461,25 @@ export class UsersRouter extends ClassesRouter {
|
||||
);
|
||||
}
|
||||
|
||||
return req.config.database.find('_User', { email: email }).then(results => {
|
||||
if (!results.length || results.length < 1) {
|
||||
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `No user found with email ${email}`);
|
||||
}
|
||||
const user = results[0];
|
||||
const results = await req.config.database.find('_User', { email: email });
|
||||
if (!results.length || results.length < 1) {
|
||||
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `No user found with email ${email}`);
|
||||
}
|
||||
const user = results[0];
|
||||
|
||||
// remove password field, messes with saving on postgres
|
||||
delete user.password;
|
||||
// remove password field, messes with saving on postgres
|
||||
delete user.password;
|
||||
|
||||
if (user.emailVerified) {
|
||||
throw new Parse.Error(Parse.Error.OTHER_CAUSE, `Email ${email} is already verified.`);
|
||||
}
|
||||
if (user.emailVerified) {
|
||||
throw new Parse.Error(Parse.Error.OTHER_CAUSE, `Email ${email} is already verified.`);
|
||||
}
|
||||
|
||||
const userController = req.config.userController;
|
||||
return userController.regenerateEmailVerifyToken(user).then(() => {
|
||||
userController.sendVerificationEmail(user);
|
||||
return { response: {} };
|
||||
});
|
||||
});
|
||||
const userController = req.config.userController;
|
||||
const send = await userController.regenerateEmailVerifyToken(user, req.auth.isMaster);
|
||||
if (send) {
|
||||
userController.sendVerificationEmail(user, req);
|
||||
}
|
||||
return { response: {} };
|
||||
}
|
||||
|
||||
async handleChallenge(req) {
|
||||
|
||||
Reference in New Issue
Block a user