Propagate installationId in all Cloud Code triggers.

This commit is contained in:
Nikita Lutsenko
2016-03-02 20:59:25 -08:00
parent 1053adf01d
commit c4fa3f0ee0
5 changed files with 34 additions and 35 deletions

View File

@@ -86,7 +86,7 @@ describe('Parse Role testing', () => {
return createRole(rolesNames[2], anotherRole, user);
}).then( (lastRole) => {
roleIds[lastRole.get("name")] = lastRole.id;
var auth = new Auth(new Config("test") , true, user);
var auth = new Auth({ config: new Config("test"), isMaster: true, user: user });
return auth._loadRoles();
})
}).then( (roles) => {

View File

@@ -7,10 +7,11 @@ import cache from './cache';
// An Auth object tells you who is requesting something and whether
// the master key was used.
// userObject is a Parse.User and can be null if there's no user.
function Auth(config, isMaster, userObject) {
function Auth({ config, isMaster = false, user, installationId } = {}) {
this.config = config;
this.installationId = installationId;
this.isMaster = isMaster;
this.user = userObject;
this.user = user;
// Assuming a users roles won't change during a single request, we'll
// only load them once.
@@ -33,19 +34,19 @@ Auth.prototype.couldUpdateUserId = function(userId) {
// A helper to get a master-level Auth object
function master(config) {
return new Auth(config, true, null);
return new Auth({ config, isMaster: true });
}
// A helper to get a nobody-level Auth object
function nobody(config) {
return new Auth(config, false, null);
return new Auth({ config, isMaster: false });
}
// Returns a promise that resolves to an Auth object
var getAuthForSessionToken = function(config, sessionToken) {
var getAuthForSessionToken = function({ config, sessionToken, installationId } = {}) {
var cachedUser = cache.users.get(sessionToken);
if (cachedUser) {
return Promise.resolve(new Auth(config, false, cachedUser));
return Promise.resolve(new Auth({ config, isMaster: false, installationId, user: cachedUser }));
}
var restOptions = {
limit: 1,
@@ -67,7 +68,7 @@ var getAuthForSessionToken = function(config, sessionToken) {
obj['sessionToken'] = sessionToken;
let userObject = Parse.Object.fromJSON(obj);
cache.users.set(sessionToken, userObject);
return new Auth(config, false, userObject);
return new Auth({ config, isMaster: false, installationId, user: userObject });
});
};

View File

@@ -38,7 +38,6 @@ export class UserController extends AdaptableController {
}
}
verifyEmail(username, token) {
if (!this.shouldVerifyEmails) {
// Trying to verify email when not enabled

View File

@@ -89,7 +89,7 @@ function handleParseHeaders(req, res, next) {
var isMaster = (info.masterKey === req.config.masterKey);
if (isMaster) {
req.auth = new auth.Auth(req.config, true);
req.auth = new auth.Auth({ config: req.config, installationId: info.installationId, isMaster: true });
next();
return;
}
@@ -114,23 +114,23 @@ function handleParseHeaders(req, res, next) {
}
if (!info.sessionToken) {
req.auth = new auth.Auth(req.config, false);
req.auth = new auth.Auth({ config: req.config, installationId: info.installationId, isMaster: false });
next();
return;
}
return auth.getAuthForSessionToken(
req.config, info.sessionToken).then((auth) => {
return auth.getAuthForSessionToken({ config: req.config, installationId: info.installationId, sessionToken: info.sessionToken })
.then((auth) => {
if (auth) {
req.auth = auth;
next();
}
}).catch((error) => {
})
.catch((error) => {
// TODO: Determine the correct error scenario.
console.log(error);
throw new Parse.Error(Parse.Error.UNKNOWN_ERROR, error);
});
}
var allowCrossDomain = function(req, res, next) {

View File

@@ -110,12 +110,11 @@ export function getRequestObject(triggerType, auth, parseObject, originalParseOb
if (auth.user) {
request['user'] = auth.user;
}
// TODO: Add installation to Auth?
if (auth.installationId) {
request['installationId'] = auth.installationId;
}
return request;
};
}
// Creates the response object, and uses the request object to pass data
// The API will call this with REST API formatted objects, this will