Built motion from commit b33b832.|1.0.17
[motion.git] / server / models / mail_account.js
index 4e69e7b..10228b0 100644 (file)
@@ -1,9 +1,8 @@
-/**
- * Chat Website Model
- */
+'use strict';
 
-module.exports = function(sequelize, DataTypes) {
+const _ = require('lodash');
 
+module.exports = function(sequelize, DataTypes) {
        var MailAccount = sequelize.define('MailAccount', {
                description: DataTypes.STRING,
                name: {
@@ -11,13 +10,13 @@ module.exports = function(sequelize, DataTypes) {
                },
                address: {
                        type: DataTypes.STRING,
-                       unique: true,
+                       unique: 'address',
                        isEmail: true,
                        set: function(address) {
                                if (address) {
                                        this.setDataValue('address', address.toLowerCase());
                                }
-                       },
+                       }
                },
                fidelity: {
                        type: DataTypes.BOOLEAN,
@@ -26,12 +25,61 @@ module.exports = function(sequelize, DataTypes) {
                timeout: {
                        type: DataTypes.INTEGER,
                        defaultValue: 0
+               },
+               whiteLabel: {
+                       type: DataTypes.STRING
+               },
+               acceptUrl: {
+                       type: DataTypes.STRING
+               },
+               rejectUrl: {
+                       type: DataTypes.STRING
+               },
+               acceptMethod: {
+                       type: DataTypes.ENUM('GET', 'POST')
+               },
+               rejectMethod: {
+                       type: DataTypes.ENUM('GET', 'POST')
+               },
+               actions: {
+                       type: DataTypes.STRING,
+                       get: function() {
+                               return this.getDataValue('actions') ? JSON.parse(this.getDataValue('actions')) : [];
+                       },
+                       set: function(val) {
+                               return this.setDataValue('actions', JSON.stringify(val));
+                       }
+               },
+               closeUrl: {
+                       type: DataTypes.STRING
+               },
+               closeMethod: {
+                       type: DataTypes.ENUM('GET', 'POST')
+               },
+               signature: {
+                       type: DataTypes.BLOB,
+                       get: function() {
+                               if (this.getDataValue('signature')) {
+                                       return _.toString(this.getDataValue('signature'));
+                               }
+                       }
+               },
+               custom: {
+                       type: DataTypes.BOOLEAN,
+                       defaultValue: false
+               },
+               service: {
+                       type: DataTypes.BOOLEAN,
+                       defaultValue: false
                }
        }, {
                tableName: 'mail_accounts',
                associate: function(models) {
                        // RELATIONS
+                       MailAccount.belongsTo(models.List);
+                       MailAccount.belongsTo(models.Template);
                        MailAccount.hasMany(models.MailRoom);
+                       MailAccount.hasMany(models.MailDisposition);
                        MailAccount.hasMany(models.MailApplication);
                        MailAccount.hasOne(models.MailServerIn, {
                                onDelete: 'cascade',
@@ -43,27 +91,38 @@ module.exports = function(sequelize, DataTypes) {
                        });
 
                        // SCOPES
-                       MailAccount.addScope('default', {
-                               include: [{
-                                       model: models.MailServerIn,
-                                       attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'delete', 'filter', 'state', 'mailbox', 'connTimeout', 'authTimeout', 'keepalive']
-                               }, {
-                                       model: models.MailServerOut,
-                                       attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'service', 'state']
-                               }, {
-                                       model: models.MailApplication,
+                       MailAccount.addScope('default', function(query) {
+                               var opt = {
                                        include: [{
-                                               model: models.User,
-                                               attributes: ['id',
-                                                       'name',
-                                                       'email',
-                                                       'internal',
-                                                       'fullname'
+                                               model: models.MailServerIn,
+                                               attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'delete', 'filter', 'state', 'mailbox', 'connTimeout', 'authTimeout', 'keepalive', 'source', 'polling',
+                                                       'pollingTimeout'
                                                ]
                                        }, {
-                                               model: models.MailQueue
+                                               model: models.MailServerOut,
+                                               attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'state', 'source', 'description']
+                                       }, {
+                                               model: models.MailApplication,
+                                               include: [{
+                                                       model: models.User,
+                                                       attributes: ['id',
+                                                               'name',
+                                                               'email',
+                                                               'internal',
+                                                               'fullname'
+                                                       ]
+                                               }, {
+                                                       model: models.MailQueue
+                                               }]
                                        }]
-                               }]
+                               };
+                               if (query && !query.custom) {
+                                       opt.where = {
+                                               custom: false,
+                                       };
+                                       delete query.custom;
+                               }
+                               return opt;
                        });
                }
        });