Fix beforeQuery trigger when getting objects through GET API (#3862)

This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2017-06-21 09:24:51 -03:00
committed by Florent Vilmart
parent a0d1a3517f
commit 422723fa31
3 changed files with 43 additions and 6 deletions

View File

@@ -37,9 +37,14 @@ function find(config, auth, className, restWhere, restOptions, clientSDK) {
// get is just like find but only queries an objectId.
const get = (config, auth, className, objectId, restOptions, clientSDK) => {
var restWhere = { objectId };
enforceRoleSecurity('get', className, auth);
const query = new RestQuery(config, auth, className, { objectId }, restOptions, clientSDK);
return query.execute();
return triggers.maybeRunQueryTrigger(triggers.Types.beforeFind, className, restWhere, restOptions, config, auth, true).then((result) => {
restWhere = result.restWhere || restWhere;
restOptions = result.restOptions || restOptions;
const query = new RestQuery(config, auth, className, restWhere, restOptions, clientSDK);
return query.execute();
});
}
// Returns a promise that doesn't resolve to any useful value.

View File

@@ -155,13 +155,16 @@ export function getRequestObject(triggerType, auth, parseObject, originalParseOb
return request;
}
export function getRequestQueryObject(triggerType, auth, query, count, config) {
export function getRequestQueryObject(triggerType, auth, query, count, config, isGet) {
isGet = !!isGet;
var request = {
triggerName: triggerType,
query,
master: false,
count,
log: config.loggerController
log: config.loggerController,
isGet
};
if (!auth) {
@@ -286,7 +289,7 @@ export function maybeRunAfterFindTrigger(triggerType, auth, className, objects,
});
}
export function maybeRunQueryTrigger(triggerType, className, restWhere, restOptions, config, auth) {
export function maybeRunQueryTrigger(triggerType, className, restWhere, restOptions, config, auth, isGet) {
const trigger = getTrigger(className, triggerType, config.applicationId);
if (!trigger) {
return Promise.resolve({
@@ -312,7 +315,7 @@ export function maybeRunQueryTrigger(triggerType, className, restWhere, restOpti
}
count = !!restOptions.count;
}
const requestObject = getRequestQueryObject(triggerType, auth, parseQuery, count, config);
const requestObject = getRequestQueryObject(triggerType, auth, parseQuery, count, config, isGet);
return Promise.resolve().then(() => {
return trigger(requestObject);
}).then((result) => {