diff --git a/src/routes/users.js b/src/routes/users.js index 04f3621b8..46a1cf757 100644 --- a/src/routes/users.js +++ b/src/routes/users.js @@ -10,8 +10,7 @@ exports = module.exports = { verifyPassword: verifyPassword, createInvite: createInvite, sendInvite: sendInvite, - setGroups: setGroups, - setActive: setActive + setGroups: setGroups }; var assert = require('assert'), @@ -70,6 +69,8 @@ function update(req, res, next) { if (req.user.id === req.params.userId && !req.body.admin) return next(new HttpError(409, 'Cannot remove admin flag on self')); } + if ('active' in req.body && typeof req.body.active !== 'boolean') return next(new HttpError(400, 'active must be a boolean')); + users.update(req.params.userId, req.body, auditSource.fromRequest(req), function (error) { if (error && error.reason === UsersError.BAD_FIELD) return next(new HttpError(400, error.message)); if (error && error.reason === UsersError.ALREADY_EXISTS) return next(new HttpError(409, error.message)); @@ -193,17 +194,3 @@ function changePassword(req, res, next) { next(new HttpSuccess(204)); }); } - -function setActive(req, res, next) { - assert.strictEqual(typeof req.body, 'object'); - assert.strictEqual(typeof req.params.userId, 'string'); - - if (typeof req.body.active !== 'boolean') return next(new HttpError(400, 'active must be a boolean')); - - users.setPassword(req.params.userId, req.body.active, function (error) { - if (error && error.reason === UsersError.NOT_FOUND) return next(new HttpError(404, 'User not found')); - if (error) return next(new HttpError(500, error)); - - next(new HttpSuccess(200)); - }); -} diff --git a/src/server.js b/src/server.js index 58c012954..8cc81d78b 100644 --- a/src/server.js +++ b/src/server.js @@ -174,7 +174,6 @@ function initializeExpressSync() { router.put ('/api/v1/users/:userId/groups', usersManageScope, routes.users.setGroups); router.post('/api/v1/users/:userId/send_invite', usersManageScope, routes.users.sendInvite); router.post('/api/v1/users/:userId/create_invite', usersManageScope, routes.users.createInvite); - router.post('/api/v1/users/:userId/active', usersManageScope, routes.users.setActive); // Group management router.get ('/api/v1/groups', usersReadScope, routes.groups.list); diff --git a/src/users.js b/src/users.js index 6a38f93b0..54b2a950a 100644 --- a/src/users.js +++ b/src/users.js @@ -30,8 +30,6 @@ exports = module.exports = { enableTwoFactorAuthentication: enableTwoFactorAuthentication, disableTwoFactorAuthentication: disableTwoFactorAuthentication, - setActive: setActive, - count: count }; @@ -408,7 +406,7 @@ function updateUser(userId, data, auditSource, callback) { assert.strictEqual(typeof callback, 'function'); var error; - data = _.pick(data, 'email', 'fallbackEmail', 'displayName', 'username', 'admin'); + data = _.pick(data, 'email', 'fallbackEmail', 'displayName', 'username', 'admin', 'active'); if (_.isEmpty(data)) return callback(); @@ -447,7 +445,8 @@ function updateUser(userId, data, auditSource, callback) { eventlog.add(eventlog.ACTION_USER_UPDATE, auditSource, { userId: userId, user: removePrivateFields(result), - adminStatusChanged: ((result.admin && !oldUser.admin) || (!result.admin && oldUser.admin)) + adminStatusChanged: ((result.admin && !oldUser.admin) || (!result.admin && oldUser.admin)), + activeStatusChanged: ((result.active && !oldUser.active) || (!result.active && oldUser.active)) }); }); }); @@ -661,15 +660,3 @@ function disableTwoFactorAuthentication(userId, callback) { callback(null); }); } - -function setActive(userId, active, callback) { - assert.strictEqual(typeof userId, 'string'); - assert.strictEqual(typeof callback, 'function'); - - userdb.update(userId, { active: active }, function (error) { - if (error) return callback(new UsersError(UsersError.INTERNAL_ERROR, error)); - if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new UsersError(UsersError.NOT_FOUND, error)); - - callback(null); - }); -}