Built motion from commit 503e72f.|0.0.143
[motion.git] / server / models / user.js
index 053b022..409fdd9 100644 (file)
@@ -23,6 +23,7 @@ module.exports = function(sequelize, DataTypes) {
     fullname: {
       type: DataTypes.STRING,
       allowNull: false,
+      unique: true
     },
     email: {
       type: DataTypes.STRING,
@@ -47,8 +48,7 @@ module.exports = function(sequelize, DataTypes) {
       set: function(password) {
         this.salt = this.makeSalt();
         this.setDataValue('password', this.encryptPassword(password));
-        this.setDataValue('md5secret', this.md5Password(this.name +
-          ':asterisk:' + password));
+        this.setDataValue('md5secret', this.md5Password(this.name + ':asterisk:' + password));
       }
     },
     provider: {
@@ -118,12 +118,10 @@ module.exports = function(sequelize, DataTypes) {
         this.setDataValue('voicePause', voicePause);
         if (voicePause) {
           this.setDataValue('queueStatus', 'paused');
-          this.setDataValue('queueStatusAt', moment().format(
-            "YYYY-MM-DD HH:mm:ss"));
+          this.setDataValue('queueStatusAt', moment().format("YYYY-MM-DD HH:mm:ss"));
         } else {
           this.setDataValue('queueStatus', 'complete');
-          this.setDataValue('queueStatusAt', moment().format(
-            "YYYY-MM-DD HH:mm:ss"));
+          this.setDataValue('queueStatusAt', moment().format("YYYY-MM-DD HH:mm:ss"));
         }
       }
     },
@@ -143,6 +141,10 @@ module.exports = function(sequelize, DataTypes) {
       type: DataTypes.BOOLEAN,
       defaultValue: false
     },
+    openchannelPause: {
+      type: DataTypes.BOOLEAN,
+      defaultValue: false
+    },
     pauseType: {
       type: DataTypes.STRING,
       defaultValue: 'Default Pause'
@@ -166,6 +168,10 @@ module.exports = function(sequelize, DataTypes) {
       type: DataTypes.INTEGER,
       defaultValue: 0
     },
+    openchannelCapacity: {
+      type: DataTypes.INTEGER,
+      defaultValue: 0
+    },
     phoneBarAutoAnswer: {
       type: DataTypes.BOOLEAN,
       defaultValue: false
@@ -223,7 +229,7 @@ module.exports = function(sequelize, DataTypes) {
     },
     phoneBarExpires: {
       type: DataTypes.INTEGER(5),
-      defaultValue: 3600
+      defaultValue: 120
     },
     phoneBarNameServer: {
       type: DataTypes.STRING,
@@ -235,7 +241,7 @@ module.exports = function(sequelize, DataTypes) {
     },
     phoneBarVADEnabled: {
       type: DataTypes.BOOLEAN,
-      defaultValue: true
+      defaultValue: false
     },
     phoneBarNoUDP: {
       type: DataTypes.BOOLEAN,
@@ -253,6 +259,14 @@ module.exports = function(sequelize, DataTypes) {
       type: DataTypes.BOOLEAN,
       defaultValue: false
     },
+    phoneBarRemoteControl: {
+      type: DataTypes.BOOLEAN,
+      defaultValue: false
+    },
+    phoneBarRemoteControlPort: {
+      type: DataTypes.INTEGER,
+      defaultValue: 9888
+    },
     chanspy: {
       type: DataTypes.BOOLEAN,
       defaultValue: false
@@ -261,6 +275,11 @@ module.exports = function(sequelize, DataTypes) {
       type: DataTypes.STRING,
       allowNull: true,
     },
+    host: {
+      type: DataTypes.STRING,
+      allowNull: true,
+      defaultValue: 'dynamic'
+    },
     ipaddr: { //REALTIME ASTERISK
       type: DataTypes.STRING,
       allowNull: true,
@@ -385,15 +404,15 @@ module.exports = function(sequelize, DataTypes) {
       type: DataTypes.STRING,
       allowNull: true
     },
-    allow: {
+    disallow: {
       type: DataTypes.STRING,
       allowNull: true,
-      defaultValue: 'alaw;ulaw;gsm'
+      defaultValue: 'all'
     },
-    disallow: {
+    allow: {
       type: DataTypes.STRING,
       allowNull: true,
-      defaultValue: null
+      defaultValue: 'alaw;ulaw;gsm'
     },
     autoframing: {
       type: DataTypes.ENUM('yes', 'no'),
@@ -526,11 +545,6 @@ module.exports = function(sequelize, DataTypes) {
       type: DataTypes.STRING,
       allowNull: true,
     },
-    host: {
-      type: DataTypes.STRING,
-      allowNull: true,
-      defaultValue: 'dynamic'
-    },
     qualify: {
       type: DataTypes.ENUM('yes', 'no'),
       allowNull: true,
@@ -682,7 +696,7 @@ module.exports = function(sequelize, DataTypes) {
     call_limit: {
       type: DataTypes.INTEGER(11),
       allowNull: true,
-      defaultValue: null
+      defaultValue: 10
     },
     registertrying: { //Send a 100 Trying when the device registers.
       type: DataTypes.ENUM('yes', 'no'),
@@ -713,6 +727,20 @@ module.exports = function(sequelize, DataTypes) {
       allowNull: true,
       defaultValue: 'no'
     },
+    loginInPause: {
+      type: DataTypes.BOOLEAN,
+      defaultValue: false
+    },
+    resetPasswordToken: {
+      type: DataTypes.STRING
+    },
+    resetPasswordExpires: {
+      type: DataTypes.DATE
+    },
+    phoneBarEnableRecording: {
+      type: DataTypes.BOOLEAN,
+      defaultValue: false
+    }
   }, {
     tableName: 'users',
     instanceMethods: {
@@ -779,6 +807,12 @@ module.exports = function(sequelize, DataTypes) {
       User.belongsToMany(models.SmsRoom, {
         through: 'user_has_sms_rooms'
       });
+      User.belongsToMany(models.OpenchannelRoom, {
+        through: 'user_has_openchannel_rooms'
+      });
+      User.belongsToMany(models.FaxRoom, {
+        through: 'user_has_fax_rooms'
+      });
       User.belongsToMany(models.Team, {
         through: models.UserHasTeam
       });
@@ -802,7 +836,14 @@ module.exports = function(sequelize, DataTypes) {
         through: models.UserHasSmsQueuePermit,
         as: 'PSmsQueues'
       });
-
+      User.belongsToMany(models.OpenchannelQueue, {
+        through: models.UserHasOpenchannelQueue,
+        required: false
+      });
+      User.belongsToMany(models.OpenchannelQueue, {
+        through: models.UserHasOpenchannelQueuePermit,
+        as: 'POpenchannelQueues'
+      });
       User.belongsToMany(models.MailQueue, {
         through: models.UserHasMailQueuePermit,
         as: 'PMailQueues'
@@ -837,6 +878,32 @@ module.exports = function(sequelize, DataTypes) {
       });
 
       // SCOPES MANAGEMENT
+      User.addScope('all', {
+        attributes: ['id',
+          'name',
+          'email',
+          'internal',
+          'fullname',
+          'role',
+          'online',
+          'userpic',
+          'accountcode',
+          'transport',
+          'host',
+          'role',
+          'nat',
+          'type',
+          'allow',
+          'lastLoginAt',
+          'ipaddr',
+          'fullcontact',
+          'port',
+          'lastms',
+          'description'
+        ]
+      });
+
+      // SCOPES MANAGEMENT
       User.addScope('user', {
         where: {
           role: {
@@ -848,6 +915,7 @@ module.exports = function(sequelize, DataTypes) {
           'email',
           'internal',
           'fullname',
+          'role',
           'userpic',
           'accountcode',
           'transport',
@@ -861,7 +929,7 @@ module.exports = function(sequelize, DataTypes) {
           'fullcontact',
           'port',
           'lastms',
-          'description'
+          'description',
         ]
       });
       User.addScope('agent', {
@@ -873,6 +941,7 @@ module.exports = function(sequelize, DataTypes) {
           'email',
           'internal',
           'fullname',
+          'role',
           'userpic',
           'accountcode',
           'transport',
@@ -884,6 +953,7 @@ module.exports = function(sequelize, DataTypes) {
           'mailCapacity',
           'faxCapacity',
           'smsCapacity',
+          'openchannelCapacity',
           'online',
           'lastLoginAt',
           'phoneBarAutoAnswer',
@@ -895,12 +965,17 @@ module.exports = function(sequelize, DataTypes) {
           'phoneBarNoReplyNumber',
           'phoneBarBusyNumber',
           'phoneBarListenPort',
+          'phoneBarExpires',
+          'phoneBarRemoteControl',
+          'phoneBarRemoteControlPort',
+          'phoneBarEnableRecording',
           'chanspy',
           'voicePause',
           'mailPause',
           'faxPause',
           'chatPause',
           'smsPause',
+          'openchannelPause',
           'pauseType',
           'lastPauseAt',
           'status',
@@ -913,7 +988,8 @@ module.exports = function(sequelize, DataTypes) {
           'fullcontact',
           'port',
           'lastms',
-          'description'
+          'description',
+          'loginInPause'
         ]
       });
       User.addScope('telephone', {
@@ -923,7 +999,7 @@ module.exports = function(sequelize, DataTypes) {
       });
       User.addScope('queues', {
         include: [models.VoiceQueue, models.ChatQueue, models.MailQueue,
-          models.FaxQueue, models.SmsQueue
+          models.FaxQueue, models.SmsQueue, models.OpenchannelQueue
         ]
       });
 
@@ -951,6 +1027,10 @@ module.exports = function(sequelize, DataTypes) {
           scope.where.smsPause = (query.smsPause === 'true') ?
             true : false;
           delete query.smsPause;
+        } else if (query.openchannelPause) {
+          scope.where.openchannelPause = (query.openchannelPause === 'true') ?
+            true : false;
+          delete query.openchannelPause;
         }
         return scope;
       });