mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-07-29 08:54:44 +02:00
API method: server.getAll().
This commit is contained in:
parent
bcc400c7d7
commit
9adfec28cf
29
src/api.js
29
src/api.js
@ -119,6 +119,10 @@ Api.err = {
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Helper functions that should be written:
|
||||||
|
// - checkParams(req.params, param1, ..., paramN).then(...)
|
||||||
|
// - isAuthorized(session, [permission]).then(...)
|
||||||
|
|
||||||
Api.fn = {};
|
Api.fn = {};
|
||||||
|
|
||||||
Api.fn.api = {
|
Api.fn.api = {
|
||||||
@ -303,7 +307,6 @@ Api.fn.user = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
'getAll': function (session) {
|
'getAll': function (session) {
|
||||||
var user_id = session.get('user_id');
|
var user_id = session.get('user_id');
|
||||||
if (undefined === user_id)
|
if (undefined === user_id)
|
||||||
@ -497,6 +500,30 @@ Api.fn.server = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'getAll': function (session) {
|
||||||
|
var user_id = session.get('user_id');
|
||||||
|
if (undefined === user_id)
|
||||||
|
{
|
||||||
|
throw Api.err.UNAUTHORIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
var servers = this.servers;
|
||||||
|
return this.users.get(user_id).then(function (user) {
|
||||||
|
if (!user.hasPermission('admin'))
|
||||||
|
{
|
||||||
|
throw Api.err.UNAUTHORIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return servers.where();
|
||||||
|
}).then(function (all_servers) {
|
||||||
|
_.each(all_servers, function (server, i) {
|
||||||
|
all_servers[i] = _.pick(server, 'id', 'host', 'username');
|
||||||
|
});
|
||||||
|
|
||||||
|
return all_servers;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
'connect': function () {
|
'connect': function () {
|
||||||
throw Api.err.NOT_IMPLEMENTED;
|
throw Api.err.NOT_IMPLEMENTED;
|
||||||
},
|
},
|
||||||
|
@ -3,6 +3,19 @@ var Q = require('q');
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// @todo Maybe we should generalize the getter methods (get,
|
||||||
|
// findWhere, where) to two methods: get([properties]) &
|
||||||
|
// first([properties]).
|
||||||
|
//
|
||||||
|
// Each of these methods accept optionnal properties to filter its
|
||||||
|
// results.
|
||||||
|
//
|
||||||
|
// get() returns any models that match while first() returns only the
|
||||||
|
// one.
|
||||||
|
//
|
||||||
|
// These method should also accept a scalar value as a matching value
|
||||||
|
// for the “id” property.
|
||||||
|
|
||||||
// @todo Add events.
|
// @todo Add events.
|
||||||
function Collection(models)
|
function Collection(models)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user