API method: user.delete(id).

This commit is contained in:
Chris Allard 2013-07-11 11:19:11 +02:00 committed by Julien Fontanet
parent 00f0fee211
commit d3ec9a0669
2 changed files with 32 additions and 3 deletions

View File

@ -225,8 +225,34 @@ Api.fn.user = {
});
},
'delete': function () {
throw Api.err.NOT_IMPLEMENTED;
'delete': function (session, req) {
var p_id = req.params.id;
if (undefined === p_id)
{
throw Api.err.INVALID_PARAMS;
}
var user_id = session.get('user_id');
if (undefined === user_id)
{
throw Api.err.UNAUTHORIZED;
}
return this.users.get(user_id).then(function (user) {
if (!user.hasPermission('admin'))
{
throw Api.err.UNAUTHORIZED;
}
return this.users.remove(p_id).then(function (success) {
if (!success)
{
throw Api.err.NO_SUCH_OBJECT;
}
return true;
});
});
},
'changePassword': function () {
@ -274,6 +300,8 @@ Api.fn.user = {
return users.get(p_id);
}).then(function (user) {
// @todo Check user exists.
// Gets the user to update.
// @todo Check undefined value are ignored.
@ -327,6 +355,7 @@ Api.fn.token = {
throw Api.err.INVALID_PARAMS;
}
// @todo Returns NO_SUCH_OBJECT if the token does not exists.
return tokens.remove(p_token).then(true);
});
},

View File

@ -116,7 +116,7 @@ Collection.prototype.remove = function (ids) {
// @todo Maybe return a more meaningful value.
/* jshint newcap: false */
return Q(true);
return Q(true); // @todo Returns false if it fails.
};
/**