mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-04-08 20:55:02 +02:00
API method: user.getAll().
This commit is contained in:
parent
1c61ec3bd3
commit
93bb0e9097
24
src/api.js
24
src/api.js
@ -289,8 +289,28 @@ Api.fn.user = {
|
||||
},
|
||||
|
||||
|
||||
'getAll': function () {
|
||||
throw Api.err.NOT_IMPLEMENTED;
|
||||
'getAll': function (session) {
|
||||
var user_id = session.get('user_id');
|
||||
if (undefined === user_id)
|
||||
{
|
||||
throw Api.err.UNAUTHORIZED;
|
||||
}
|
||||
|
||||
var users = this.users;
|
||||
return users.get(user_id).then(function (user) {
|
||||
if (!user.hasPermission('admin'))
|
||||
{
|
||||
throw Api.err.UNAUTHORIZED;
|
||||
}
|
||||
|
||||
return users.where();
|
||||
}).then(function (all_users) {
|
||||
_.each(all_users, function (user, i) {
|
||||
all_users[i] = _.pick(user, 'id', 'email', 'permission');
|
||||
});
|
||||
|
||||
return all_users;
|
||||
});
|
||||
},
|
||||
|
||||
'set': function (session, request) {
|
||||
|
@ -89,7 +89,7 @@ Collection.prototype.exists = function (id) {
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Find the first model which has a given set of properties.
|
||||
*/
|
||||
Collection.prototype.findWhere = function (properties) {
|
||||
/* jshint newcap: false */
|
||||
@ -99,6 +99,32 @@ Collection.prototype.findWhere = function (properties) {
|
||||
return Q(model ? new this.model(model) : null);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Find all models which have a given set of properties.
|
||||
*
|
||||
* /!\: Does not return instance of this.model.
|
||||
*/
|
||||
Collection.prototype.where = function (properties) {
|
||||
/* jshint newcap: false */
|
||||
if (_.isEmpty(properties))
|
||||
{
|
||||
return Q(this.models.slice());
|
||||
}
|
||||
|
||||
return Q(_.filter(this.models, function (model) {
|
||||
for (var property in properties)
|
||||
{
|
||||
if (model[property] !== properties[property])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Removes models from this collection.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user