mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-09-25 19:19:00 +02:00
API method: user.delete(id).
This commit is contained in:
parent
00f0fee211
commit
d3ec9a0669
33
src/api.js
33
src/api.js
@ -225,8 +225,34 @@ Api.fn.user = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
'delete': function () {
|
'delete': function (session, req) {
|
||||||
throw Api.err.NOT_IMPLEMENTED;
|
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 () {
|
'changePassword': function () {
|
||||||
@ -274,6 +300,8 @@ Api.fn.user = {
|
|||||||
|
|
||||||
return users.get(p_id);
|
return users.get(p_id);
|
||||||
}).then(function (user) {
|
}).then(function (user) {
|
||||||
|
// @todo Check user exists.
|
||||||
|
|
||||||
// Gets the user to update.
|
// Gets the user to update.
|
||||||
|
|
||||||
// @todo Check undefined value are ignored.
|
// @todo Check undefined value are ignored.
|
||||||
@ -327,6 +355,7 @@ Api.fn.token = {
|
|||||||
throw Api.err.INVALID_PARAMS;
|
throw Api.err.INVALID_PARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @todo Returns NO_SUCH_OBJECT if the token does not exists.
|
||||||
return tokens.remove(p_token).then(true);
|
return tokens.remove(p_token).then(true);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -116,7 +116,7 @@ Collection.prototype.remove = function (ids) {
|
|||||||
|
|
||||||
// @todo Maybe return a more meaningful value.
|
// @todo Maybe return a more meaningful value.
|
||||||
/* jshint newcap: false */
|
/* jshint newcap: false */
|
||||||
return Q(true);
|
return Q(true); // @todo Returns false if it fails.
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user