Built motion from commit b33b832.|1.0.17
[motion.git] / server / models / mail_account.js
index fc936de..10228b0 100644 (file)
@@ -1,11 +1,8 @@
-/**
- * Chat Website Model
- */
+'use strict';
 
-var _ = require('lodash');
+const _ = require('lodash');
 
 module.exports = function(sequelize, DataTypes) {
-
        var MailAccount = sequelize.define('MailAccount', {
                description: DataTypes.STRING,
                name: {
@@ -13,7 +10,7 @@ module.exports = function(sequelize, DataTypes) {
                },
                address: {
                        type: DataTypes.STRING,
-                       unique: true,
+                       unique: 'address',
                        isEmail: true,
                        set: function(address) {
                                if (address) {
@@ -66,6 +63,14 @@ module.exports = function(sequelize, DataTypes) {
                                        return _.toString(this.getDataValue('signature'));
                                }
                        }
+               },
+               custom: {
+                       type: DataTypes.BOOLEAN,
+                       defaultValue: false
+               },
+               service: {
+                       type: DataTypes.BOOLEAN,
+                       defaultValue: false
                }
        }, {
                tableName: 'mail_accounts',
@@ -86,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', 'source']
-                               }, {
-                                       model: models.MailServerOut,
-                                       attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'service', 'state', 'source']
-                               }, {
-                                       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;
                        });
                }
        });