Add route to transfer ownership
This commit is contained in:
@@ -13,6 +13,7 @@ exports = module.exports = {
|
||||
setGroups,
|
||||
setAvatar,
|
||||
clearAvatar,
|
||||
makeOwner,
|
||||
|
||||
load
|
||||
};
|
||||
@@ -216,3 +217,19 @@ function clearAvatar(req, res, next) {
|
||||
next(new HttpSuccess(202, {}));
|
||||
});
|
||||
}
|
||||
|
||||
// This route transfers ownership from token user to user specified in path param
|
||||
function makeOwner(req, res, next) {
|
||||
assert.strictEqual(typeof req.resource, 'object');
|
||||
|
||||
// first make new one owner, then devote current one
|
||||
users.update(req.resource, { role: users.ROLE_OWNER }, auditSource.fromRequest(req), function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
users.update(req.user, { role: users.ROLE_USER }, auditSource.fromRequest(req), function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user