Add route to make user local
This commit is contained in:
@@ -11,6 +11,7 @@ exports = module.exports = {
|
||||
setGroups,
|
||||
setGhost,
|
||||
makeOwner,
|
||||
makeLocal,
|
||||
|
||||
getPasswordResetLink,
|
||||
sendPasswordResetEmail,
|
||||
@@ -215,6 +216,20 @@ async function makeOwner(req, res, next) {
|
||||
next(new HttpSuccess(204));
|
||||
}
|
||||
|
||||
async function makeLocal(req, res, next) {
|
||||
assert.strictEqual(typeof req.resource, 'object');
|
||||
|
||||
if (users.compareRoles(req.user.role, req.resource.role) < 0) return next(new HttpError(403, `role '${req.resource.role}' is required but user has only '${req.user.role}'`));
|
||||
|
||||
let [error] = await safe(users.update(req.resource, { source: '', inviteToken: '' }, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
[error] = await safe(users.sendPasswordResetEmail(req.resource, req.resource.fallbackEmail || req.resource.email, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204, {}));
|
||||
}
|
||||
|
||||
// This will always return a reset link, if none is set or expired a new one will be created
|
||||
async function getPasswordResetLink(req, res, next) {
|
||||
assert.strictEqual(typeof req.resource, 'object');
|
||||
|
||||
Reference in New Issue
Block a user