Built motion from commit ae98c6c.|0.0.149
[motion.git] / server / models / user.js
index df6ccb2..4341c9c 100644 (file)
@@ -4,7 +4,6 @@ var crypto = require('crypto');
 var md5 = require('md5');
 var _ = require('lodash');
 var moment = require('moment');
-var VoiceQueue = require('.').VoiceQueue;
 
 module.exports = function(sequelize, DataTypes) {
   var User = sequelize.define('User', {
@@ -114,16 +113,16 @@ module.exports = function(sequelize, DataTypes) {
     voicePause: {
       type: DataTypes.BOOLEAN,
       defaultValue: false,
-      set: function(voicePause) {
-        this.setDataValue('voicePause', voicePause);
-        if (voicePause) {
-          this.setDataValue('queueStatus', 'paused');
-          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"));
-        }
-      }
+      // set: function(voicePause) {
+      //   this.setDataValue('voicePause', voicePause);
+      //   if (voicePause) {
+      //     this.setDataValue('queueStatus', 'paused');
+      //     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"));
+      //   }
+      // }
     },
     chatPause: {
       type: DataTypes.BOOLEAN,
@@ -275,6 +274,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,
@@ -399,15 +403,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'),
@@ -540,11 +544,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,
@@ -696,7 +695,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'),
@@ -736,6 +735,10 @@ module.exports = function(sequelize, DataTypes) {
     },
     resetPasswordExpires: {
       type: DataTypes.DATE
+    },
+    phoneBarEnableRecording: {
+      type: DataTypes.BOOLEAN,
+      defaultValue: false
     }
   }, {
     tableName: 'users',
@@ -964,6 +967,7 @@ module.exports = function(sequelize, DataTypes) {
           'phoneBarExpires',
           'phoneBarRemoteControl',
           'phoneBarRemoteControlPort',
+          'phoneBarEnableRecording',
           'chanspy',
           'voicePause',
           'mailPause',
@@ -1060,6 +1064,53 @@ module.exports = function(sequelize, DataTypes) {
         }
         return scope;
       });
+
+      User.addScope('me', function(userId) {
+        var scope = {
+          where: {
+            id: userId
+          },
+          attributes: ['id', 'fullname', 'name', 'email', 'role', 'userpic', 'lastLoginAt', 'voicePause',
+            'mailPause',
+            'chatPause',
+            'faxPause',
+            'smsPause',
+            'openchannelPause',
+            'lastPauseAt',
+            'pauseType',
+            'phoneBarRemoteControl',
+            'phoneBarRemoteControlPort',
+            'loginInPause'
+          ],
+          include: [{
+            model: models.Module,
+            include: [{
+              model: models.Module,
+              as: 'SubModules',
+              required: false,
+              include: [{
+                all: true
+              }]
+            }]
+          }, {
+            model: models.VoiceQueue,
+            as: 'PVoiceQueues'
+          }, {
+            model: models.ChatQueue,
+            as: 'PChatQueues'
+          }, {
+            model: models.MailQueue,
+            as: 'PMailQueues'
+          }, {
+            model: models.FaxQueue,
+            as: 'PFaxQueues'
+          }, {
+            model: models.SmsQueue,
+            as: 'PSmsQueues'
+          }]
+        };
+        return scope;
+      });
     }
   });