Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Routers/FunctionsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class FunctionsRouter extends PromiseRouter {
},
};
}
static handleCloudFunction(req) {
static async handleCloudFunction(req) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this without making functions async and using await

const functionName = req.params.functionName;
const applicationId = req.config.applicationId;
const theFunction = triggers.getFunction(functionName, applicationId);
Expand All @@ -127,6 +127,7 @@ export class FunctionsRouter extends PromiseRouter {
}
let params = Object.assign({}, req.body, req.query);
params = parseParams(params, req.config);
const roles = req.auth ? await req.auth.getUserRoles() : [];
const request = {
params: params,
master: req.auth && req.auth.isMaster,
Expand All @@ -137,6 +138,7 @@ export class FunctionsRouter extends PromiseRouter {
ip: req.config.ip,
functionName,
context: req.info.context,
roles,
};

return new Promise(function (resolve, reject) {
Expand Down
2 changes: 2 additions & 0 deletions src/cloud-code/Parse.Cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ module.exports = ParseCloud;
* @property {Boolean} master If true, means the master key was used.
* @property {Parse.User} user If set, the user that made the request.
* @property {Parse.Query} query The query triggering the hook.
* @property {Array<String>} roles The roles of the user making the request (e.g. `['role:Administrator']`).
* @property {String} ip The IP address of the client making the request.
* @property {Object} headers The original HTTP headers for the request.
* @property {String} triggerName The name of the trigger (`beforeSave`, `afterSave`, ...)
Expand All @@ -742,6 +743,7 @@ module.exports = ParseCloud;
* @property {Boolean} master If true, means the master key was used.
* @property {Parse.User} user If set, the user that made the request.
* @property {Object} params The params passed to the cloud function.
* @property {Array<String>} roles The roles of the user making the request (e.g. `['role:Administrator']`).
*/

/**
Expand Down
9 changes: 6 additions & 3 deletions src/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export function getRequestObject(
return request;
}

export function getRequestQueryObject(triggerType, auth, query, count, config, context, isGet) {
export function getRequestQueryObject(triggerType, auth, query, count, config, context, isGet, roles) {
isGet = !!isGet;

var request = {
Expand All @@ -312,6 +312,7 @@ export function getRequestQueryObject(triggerType, auth, query, count, config, c
headers: config.headers,
ip: config.ip,
context: context || {},
roles: roles || [],
};

if (!auth) {
Expand Down Expand Up @@ -503,7 +504,7 @@ export function maybeRunAfterFindTrigger(
});
}

export function maybeRunQueryTrigger(
export async function maybeRunQueryTrigger(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too

triggerType,
className,
restWhere,
Expand All @@ -530,14 +531,16 @@ export function maybeRunQueryTrigger(
if (restOptions) {
count = !!restOptions.count;
}
const roles = auth ? await auth.getUserRoles() : [];
const requestObject = getRequestQueryObject(
triggerType,
auth,
parseQuery,
count,
config,
context,
isGet
isGet,
roles
);
return Promise.resolve()
.then(() => {
Expand Down
Loading