Various updates.

This commit is contained in:
Julien Fontanet 2013-07-11 10:51:55 +02:00
parent 16667e0d40
commit c9cd1ebee2
5 changed files with 15 additions and 11 deletions

View File

@ -112,6 +112,8 @@ Collection.prototype.remove = function (ids) {
delete this.models[id];
}, this);
this.emit('remove', ids);
// @todo Maybe return a more meaningful value.
/* jshint newcap: false */
return Q(true);

View File

@ -66,7 +66,7 @@ function json_api_call(session, message)
function (error) {
if (error instanceof Error)
{
console.error(error);
console.error(error.stack);
return format_error(Api.err.SERVER_ERROR);
}

View File

@ -46,7 +46,7 @@ Model.prototype.get = function (property, def) {
* Checks if a property exists.
*/
Model.prototype.has = function (property) {
return (undefined !== this.get(property));
return (undefined !== this.properties[property]);
};
/**
@ -64,7 +64,6 @@ Model.prototype.set = function (properties, value) {
var model = this;
_.each(properties, function (value, key) {
var prev = model.get(key);
// New value.

View File

@ -14,8 +14,8 @@ var Session = Model.extend({
// If the user associated to this session is deleted or
// disabled, the session must close.
this.on('change:user_id', function (user_id) {
var event = 'user.revoked'+ user_id;
this.on('change:user_id', function () {
var event = 'user.revoked:'+ this.get('user_id');
xo.on(event, close);
@ -27,8 +27,8 @@ var Session = Model.extend({
// If the token associated to this session is deleted, the
// session must close.
this.on('change:token_id', function (token_id) {
var event = 'token.revoked'+ token_id;
this.on('change:token_id', function () {
var event = 'token.revoked:'+ this.get('token_id');
xo.on(event, close);

View File

@ -1,6 +1,8 @@
var _ = require('underscore');
var crypto = require('crypto');
var hashy = require('hashy');
var Q = require('q');
var Collection = require('./collection');
var Model = require('./model');
@ -149,14 +151,15 @@ function Xo()
// This events are used to automatically close connections if the
// associated credentials are invalidated.
var self = this;
this.tokens.on('remove', function (token_ids) {
token_ids.each(function (token_id) {
this.emit('token.revoked:'+ token_id);
_.each(token_ids, function (token_id) {
self.emit('token.revoked:'+ token_id);
});
});
this.users.on('remove', function (user_ids) {
user_ids.each(function (user_id) {
this.emit('user.revoked:'+ user_id);
_.each(user_ids, function (user_id) {
self.emit('user.revoked:'+ user_id);
});
});
}