updateUser
)
-router.delete('/:username',
+router.delete('/:id',
oAuth.authenticate,
admin.ensureIsAdmin,
validatorsUsers.usersRemove,
function removeUser (req, res, next) {
waterfall([
function getUser (callback) {
- User.loadByUsername(req.params.username, callback)
+ User.loadById(req.params.id, callback)
},
function getVideos (user, callback) {
}
function usersRemove (req, res, next) {
- req.checkParams('username', 'Should have a valid username').isUserUsernameValid()
+ req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
logger.debug('Checking usersRemove parameters', { parameters: req.params })
checkErrors(req, res, function () {
- User.loadByUsername(req.params.username, function (err, user) {
+ User.loadById(req.params.id, function (err, user) {
if (err) {
logger.error('Error in usersRemove request validator.', { error: err })
return res.sendStatus(500)
}
function usersUpdate (req, res, next) {
+ req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
// Add old password verification
req.checkBody('password', 'Should have a valid password').isUserPasswordValid()
UserSchema.statics = {
getByUsernameAndPassword: getByUsernameAndPassword,
list: list,
+ loadById: loadById,
loadByUsername: loadByUsername
}
return this.find(callback)
}
+function loadById (id, callback) {
+ return this.findById(id, callback)
+}
+
function loadByUsername (username, callback) {
return this.findOne({ username: username }, callback)
}
})
describe('When removing an user', function () {
- it('Should fail with an incorrect username', function (done) {
+ it('Should fail with an incorrect id', function (done) {
request(server.url)
.delete(path + 'bla-bla')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(400, done)
})
- it('Should return 404 with a non existing username', function (done) {
+ it('Should return 404 with a non existing id', function (done) {
request(server.url)
- .delete(path + 'qzzerg')
+ .delete(path + '579f982228c99c221d8092b8')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(404, done)
})
it('Should success with the correct parameters', function (done) {
request(server.url)
- .delete(path + 'user1')
+ .delete(path + userId)
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(204, done)
})
})
it('Should be able to remove this user', function (done) {
- usersUtils.removeUser(server.url, accessToken, 'user_1', done)
+ usersUtils.removeUser(server.url, userId, accessToken, done)
})
it('Should not be able to login with this user', function (done) {
.end(end)
}
-function removeUser (url, token, username, expectedStatus, end) {
+function removeUser (url, userId, accessToken, expectedStatus, end) {
if (!end) {
end = expectedStatus
expectedStatus = 204
const path = '/api/v1/users'
request(url)
- .delete(path + '/' + username)
+ .delete(path + '/' + userId)
.set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + token)
+ .set('Authorization', 'Bearer ' + accessToken)
.expect(expectedStatus)
.end(end)
}