Skip to content
Merged
52 changes: 52 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2968,4 +2968,56 @@ describe('afterLogin hook', () => {
obj.set("obj2", obj2);
await obj.save(null, { context: { a: 'a' } });
});

it('should have access to context as saveAll argument', async () => {
Parse.Cloud.beforeSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.afterSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
const obj = new TestObject();
await Parse.Object.saveAll([obj], { context: { a: 'a' }});
});

it('should have access to context as destroyAll argument', async () => {
Parse.Cloud.beforeDelete('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.afterDelete('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
const obj = new TestObject();
await Parse.Object.saveAll([obj]);
await Parse.Object.destroyAll([obj], { context: { a: 'a' } });
});

it('should have access to context as destroy a object', async () => {
Parse.Cloud.beforeDelete('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.afterDelete('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
const obj = new TestObject();
await obj.save();
await obj.destroy({ context: { a: 'a' } });
});

it('should have access to context in beforeFind hook', async () => {
Parse.Cloud.beforeFind('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
const query = new Parse.Query('TestObject');
return query.find({ context: { a: 'a' } });
});

it('should have access to context when cloud function is called.', async () => {
Parse.Cloud.define('contextTest', async (req) => {
expect(req.context.a).toEqual('a');
return {};
});

await Parse.Cloud.run('contextTest', {}, { context: { a: 'a' } });
});
});
2 changes: 1 addition & 1 deletion spec/ParseACL.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,6 @@ describe('Parse.ACL', () => {
}
});

rest.create(config, auth.nobody(config), '_User', anonUser);
rest.create(config, auth.nobody(config), '_User', anonUser, null, {});
});
});
2 changes: 1 addition & 1 deletion spec/RestQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ describe('RestQuery.each', () => {
});

rest
.create(config, nobody, 'TestObject2', { todelete: true, tokeep: true })
.create(config, nobody, 'TestObject2', { todelete: true, tokeep: true }, null, {})
.then(response => {
expect(response.response.toadd).toBeTruthy();
expect(response.response.tokeep).toBeTruthy();
Expand Down
6 changes: 4 additions & 2 deletions spec/rest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('rest create', () => {
});

rest
.create(config, auth.nobody(config), 'MyClass', obj)
.create(config, auth.nobody(config), 'MyClass', obj, null, {})
.then(() => database.adapter.find('MyClass', { fields: {} }, {}, {}))
.then((results) => {
expect(results.length).toEqual(1);
Expand All @@ -199,7 +199,9 @@ describe('rest create', () => {
auth.nobody(config),
'MyClass',
{ objectId: mob.objectId },
obj
obj,
null,
{}
);
})
.then(() => database.adapter.find('MyClass', { fields: {} }, {}, {}))
Expand Down
5 changes: 4 additions & 1 deletion src/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ const createSession = function(
master(config),
'_Session',
null,
sessionData
sessionData,
null,
null,
{}
).execute(),
};
};
Expand Down
10 changes: 8 additions & 2 deletions src/Controllers/PushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export class PushController {
master(config),
'_Installation',
restQuery.restWhere,
restUpdate
restUpdate,
null,
null,
{}
);
write.runOptions.many = true;
return write.execute();
Expand Down Expand Up @@ -115,7 +118,10 @@ export class PushController {
master(config),
'_Audience',
{ objectId: audienceId },
updateAudience
updateAudience,
null,
null,
{}
);
write.execute();
}
Expand Down
6 changes: 4 additions & 2 deletions src/Controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class UserController extends AdaptableController {
if (result.results.length) {
return Promise.resolve(result.results.length[0]);
}
return rest.update(this.config, masterAuth, '_User', query, updateFields);
return rest.update(this.config, masterAuth, '_User', query, updateFields, null, {});
});
}

Expand Down Expand Up @@ -298,7 +298,9 @@ function updateUserPassword(userId, password, config) {
{ objectId: userId },
{
password: password,
}
},
null,
{}
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/GraphQL/helpers/objectsMutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const createObject = async (className, fields, config, auth, info) => {
fields = {};
}

return (await rest.create(config, auth, className, fields, info.clientSDK))
return (await rest.create(config, auth, className, fields, info.clientSDK, info.context))
.response;
};

Expand All @@ -27,12 +27,13 @@ const updateObject = async (
className,
{ objectId },
fields,
info.clientSDK
info.clientSDK,
info.context
)).response;
};

const deleteObject = async (className, objectId, config, auth, info) => {
await rest.del(config, auth, className, objectId, info.clientSDK);
await rest.del(config, auth, className, objectId, info.context);
return true;
};

Expand Down
9 changes: 6 additions & 3 deletions src/GraphQL/helpers/objectsQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const getObject = async (
className,
objectId,
options,
info.clientSDK
info.clientSDK,
info.context
);

if (!response.results || response.results.length == 0) {
Expand Down Expand Up @@ -142,7 +143,8 @@ const findObjects = async (
className,
where,
preCountOptions,
info.clientSDK
info.clientSDK,
info.context
)
).count;
if ((skip || 0) + limit < preCount) {
Expand Down Expand Up @@ -222,7 +224,8 @@ const findObjects = async (
className,
where,
options,
info.clientSDK
info.clientSDK,
info.context
);
results = findResult.results;
count = findResult.count;
Expand Down
3 changes: 2 additions & 1 deletion src/GraphQL/loaders/usersQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const getUserFromSessionToken = async (
'_Session',
{ sessionToken },
options,
info.clientVersion
info.clientVersion,
info.context,
);
if (
!response.results ||
Expand Down
1 change: 1 addition & 0 deletions src/ParseServerRESTController.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function ParseServerRESTController(applicationId, router) {
info: {
applicationId: applicationId,
sessionToken: options.sessionToken,
context: options.context || {}, // Add context
},
query,
};
Expand Down
2 changes: 1 addition & 1 deletion src/Push/PushQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class PushQueue {
return rest.find(config, auth, '_Installation', where, {
limit: 0,
count: true,
});
}, null, {});
})
.then(({ results, count }) => {
if (!results || count == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Push/PushWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class PushWorker {
delete query.where;
pushStatus = pushStatusHandler(config, pushStatus.objectId);
return rest
.find(config, auth, '_Installation', where, query)
.find(config, auth, '_Installation', where, query, null, {})
.then(({ results }) => {
if (results.length == 0) {
return;
Expand Down
9 changes: 2 additions & 7 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function RestWrite(
data,
originalData,
clientSDK,
context,
action
) {
if (auth.isReadOnly) {
Expand All @@ -46,18 +47,12 @@ function RestWrite(
this.clientSDK = clientSDK;
this.storage = {};
this.runOptions = {};
this.context = {};
this.context = context;

if (action) {
this.runOptions.action = action;
}

// Parse context
if (data._context && data._context instanceof Object) {
this.context = data._context;
delete data._context;
}

if (!query) {
if (this.config.allowCustomObjectId) {
if (
Expand Down
3 changes: 2 additions & 1 deletion src/Routers/AggregateRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export class AggregateRouter extends ClassesRouter {
this.className(req),
body.where,
options,
req.info.clientSDK
req.info.clientSDK,
req.info.context,
)
.then(response => {
for (const result of response.results) {
Expand Down
3 changes: 2 additions & 1 deletion src/Routers/AudiencesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export class AudiencesRouter extends ClassesRouter {
'_Audience',
body.where,
options,
req.info.clientSDK
req.info.clientSDK,
req.info.context,
)
.then(response => {
response.results.forEach(item => {
Expand Down
11 changes: 7 additions & 4 deletions src/Routers/ClassesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class ClassesRouter extends PromiseRouter {
this.className(req),
body.where,
options,
req.info.clientSDK
req.info.clientSDK,
req.info.context,
)
.then(response => {
return { response: response };
Expand Down Expand Up @@ -120,7 +121,8 @@ export class ClassesRouter extends PromiseRouter {
req.auth,
this.className(req),
req.body,
req.info.clientSDK
req.info.clientSDK,
req.info.context
);
}

Expand All @@ -132,7 +134,8 @@ export class ClassesRouter extends PromiseRouter {
this.className(req),
where,
req.body,
req.info.clientSDK
req.info.clientSDK,
req.info.context
);
}

Expand All @@ -143,7 +146,7 @@ export class ClassesRouter extends PromiseRouter {
req.auth,
this.className(req),
req.params.objectId,
req.info.clientSDK
req.info.context
)
.then(() => {
return { response: {} };
Expand Down
13 changes: 8 additions & 5 deletions src/Routers/CloudCodeRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CloudCodeRouter extends PromiseRouter {

static getJobs(req) {
return rest
.find(req.config, req.auth, '_JobSchedule', {}, {})
.find(req.config, req.auth, '_JobSchedule', {}, {}, null, {})
.then(scheduledJobs => {
return {
response: scheduledJobs.results,
Expand All @@ -69,7 +69,7 @@ export class CloudCodeRouter extends PromiseRouter {
const config = req.config;
const jobs = triggers.getJobs(config.applicationId) || {};
return rest
.find(req.config, req.auth, '_JobSchedule', {}, {})
.find(req.config, req.auth, '_JobSchedule', {}, {}, null, {})
.then(scheduledJobs => {
return {
response: {
Expand All @@ -88,7 +88,8 @@ export class CloudCodeRouter extends PromiseRouter {
req.auth,
'_JobSchedule',
formatJobSchedule(job_schedule),
req.client
req.client,
req.info.context,
);
}

Expand All @@ -102,7 +103,9 @@ export class CloudCodeRouter extends PromiseRouter {
req.auth,
'_JobSchedule',
{ objectId },
formatJobSchedule(job_schedule)
formatJobSchedule(job_schedule),
null,
req.info.context,
)
.then(response => {
return {
Expand All @@ -114,7 +117,7 @@ export class CloudCodeRouter extends PromiseRouter {
static deleteJob(req) {
const { objectId } = req.params;
return rest
.del(req.config, req.auth, '_JobSchedule', objectId)
.del(req.config, req.auth, '_JobSchedule', objectId, req.info.context)
.then(response => {
return {
response,
Expand Down
1 change: 1 addition & 0 deletions src/Routers/FunctionsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export class FunctionsRouter extends PromiseRouter {
headers: req.config.headers,
ip: req.config.ip,
functionName,
context: req.info.context,
};

if (theValidator && typeof theValidator === 'function') {
Expand Down
3 changes: 2 additions & 1 deletion src/Routers/IAPValidationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ function getFileForProductIdentifier(productIdentifier, req) {
'_Product',
{ productIdentifier: productIdentifier },
undefined,
req.info.clientSDK
req.info.clientSDK,
req.info.context,
)
.then(function(result) {
const products = result.results;
Expand Down
Loading