From: Daniele Cinti <daniele.cinti@xcally.com>
Date: Tue, 13 Sep 2016 13:51:52 +0000 (+0200)
Subject: Built motion from commit 5fb560b.|0.0.141
X-Git-Tag: 20/10/16~78
X-Git-Url: http://repos.xcallymotion.com/base/%22http:/www.gravatar.com/avatar/101010010101010010hash%20%20%20%20%20%200%20%20%20%20%20%200//%27?a=commitdiff_plain;h=c1afd52db3be8f052d683bcbf863006a173497cf;p=motion.git

Built motion from commit 5fb560b.|0.0.141
---

diff --git a/release-notes/changelog_0.0.141.txt b/release-notes/changelog_0.0.141.txt
index f805e39..9e208ed 100644
--- a/release-notes/changelog_0.0.141.txt
+++ b/release-notes/changelog_0.0.141.txt
@@ -1,5 +1,7 @@
 # xCALLY MOTION Changelog
 
+- * 5fb560b - 2016-09-13: server side config/ami + config/tools update 
+- * 51d6d3e - 2016-09-13: server side update 
 - * 9750695 - 2016-09-13: fix duplicate events 
 - * 0cbc254 - 2016-09-13: server side models interval + user 
 - * 0c84ddb - 2016-09-13: sever side update tools + app.js 
diff --git a/server/api/mail_account/mail_account.controller.js b/server/api/mail_account/mail_account.controller.js
index fe294ee..31adb32 100644
--- a/server/api/mail_account/mail_account.controller.js
+++ b/server/api/mail_account/mail_account.controller.js
@@ -20,7 +20,6 @@ var Interval = require('../../models').Interval;
 
 // Get list of mailAccounts
 exports.index = function(req, res) {
-  console.log('index');
   return MailAccount
     .scope('default')
     .findAndCountAll(Util.getQuery(req.query))
diff --git a/server/config/ami/acw.js b/server/config/ami/acw.js
index 397d55f..b62591f 100644
--- a/server/config/ami/acw.js
+++ b/server/config/ami/acw.js
@@ -9,13 +9,14 @@ var VoiceQueue = require('../../models').VoiceQueue;
 var Agent = require('../../models').User;
 var Action = require('../../models').Action;
 var ReportAgent = require('../../models').ReportAgent;
+
 var _voiceQueues;
 var _agents;
 var activeAcw = {};
 
 function ACW(ami) {
   console.log('ACW Initialization...');
-  return VoiceQueue
+  VoiceQueue
     .findAll()
     .then(function(voiceQueues) {
       _voiceQueues = voiceQueues;
diff --git a/server/config/ami/call.js b/server/config/ami/call.js
index addcd41..f655c32 100644
--- a/server/config/ami/call.js
+++ b/server/config/ami/call.js
@@ -22,7 +22,6 @@ function create(evt) {
       defaults: evt
     })
     .spread(function(call, created) {
-      console.log('call', call);
       if (!created) {
 
         if (evt.answertime) {
diff --git a/server/config/tools/user.js b/server/config/tools/user.js
index dc22113..3ac3cce 100644
--- a/server/config/tools/user.js
+++ b/server/config/tools/user.js
@@ -23,33 +23,37 @@ function User() {
   });
 
   emitter.on('User.beforeUpdate', function(doc, options) {
-    if (doc.changed('internal')) {
+    if (options.changed.internal) {
       throw new Error('You can\'t modify the internal of a User/Agent/Telephone');
     }
   });
 
   emitter.on('User.afterUpdate', function(doc, options) {
-    if (!doc.changed('status') && !doc.changed('queueStatus') && !doc.changed('callerid') && !doc.changed('lastLoginAt') && !doc.changed('online')) {
+    if (!options.changed.status &&
+      !options.changed.queueStatus &&
+      !options.changed.callerid &&
+      !options.changed.lastLoginAt &&
+      !options.changed.online) {
       return Promise
         .all([])
         .then(createCallerID(doc, options))
         .then(function() {
-          if ((doc.chanspy && doc.changed('chanspy'))) {
+          if (doc.chanspy && options.changed.chanspy) {
             return createChanspy(doc, options);
           }
         })
         .then(function() {
-          if (doc.chanspy && !doc.changed('chanspy') && doc.changed('name')) {
+          if (doc.chanspy && !options.changed.chanspy && options.changed.name) {
             return deleteChanSpy(doc, options);
           }
         })
         .then(function() {
-          if (doc.chanspy && !doc.changed('chanspy') && doc.changed('name')) {
+          if (doc.chanspy && !options.changed.chanspy && options.changed.name) {
             return createChanspy(doc, options);
           }
         })
         .then(function() {
-          if (!doc.chanspy && doc.changed('chanspy')) {
+          if (!doc.chanspy && options.changed.chanspy) {
             return deleteChanSpy(doc, options);
           }
         })
@@ -141,7 +145,7 @@ function deleteChanSpy(doc, options) {
 function createCallerID(doc, options) {
   return function() {
     // devo aspettare che ci siano entrambi i campi
-    if (doc.fullname && doc.internal && doc.changed('fullname')) {
+    if (doc.fullname && doc.internal && options.changed.fullname) {
       console.log('Creating callerID...');
       doc.callerid = util.format('"%s" <%s>', doc.fullname, doc.internal);
       return doc.save({
diff --git a/server/models/user.js b/server/models/user.js
index 440a54a..3877344 100644
--- a/server/models/user.js
+++ b/server/models/user.js
@@ -744,17 +744,6 @@ module.exports = function(sequelize, DataTypes) {
     }
   }, {
     tableName: 'users',
-    hooks: {
-      afterCreate: function(doc) {
-        emitter.to(['master']).emit('User.afterCreate', doc);
-      },
-      afterUpdate: function(doc) {
-        emitter.to(['master']).emit('User.afterUpdate', doc);
-      },
-      afterDestroy: function(doc) {
-        emitter.to(['master']).emit('User.afterDestroy', doc);
-      }
-    },
     instanceMethods: {
       /**
        * Authenticate - check if the passwords are the same
@@ -1078,16 +1067,20 @@ module.exports = function(sequelize, DataTypes) {
         return scope;
       });
     },
-    afterCreate: function(doc, options) {
-      emitter.to(['master']).emit('User.afterCreate', doc, {
-        body: options.body
-      });
-    },
-    afterUpdate: function(doc, options) {
-      emitter.to(['master']).emit('User.afterUpdate', doc);
-    },
-    afterDestroy: function(doc, options) {
-      emitter.to(['master']).emit('User.afterDestroy', doc);
+    hooks: {
+      afterCreate: function(doc, options) {
+        emitter.to(['master']).emit('User.afterCreate', doc, {
+          body: options.body
+        });
+      },
+      afterUpdate: function(doc, options) {
+        emitter.to(['master']).emit('User.afterUpdate', doc, {
+          changed: _.keyBy(doc.changed())
+        });
+      },
+      afterDestroy: function(doc, options) {
+        emitter.to(['master']).emit('User.afterDestroy', doc);
+      }
     }
   });