Built motion from commit a0baffd.|1.0.1
[motion.git] / server / models / mail_account.js
index d9c86ef..2d23363 100644 (file)
@@ -91,30 +91,36 @@ module.exports = function(sequelize, DataTypes) {
                        });
 
                        // SCOPES
-                       MailAccount.addScope('default', {
-                               where: {
-                                       custom: false,
-                               },
-                               include: [{
-                                       model: models.MailServerIn,
-                                       attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'delete', 'filter', 'state', 'mailbox', 'connTimeout', 'authTimeout', 'keepalive', 'source', 'polling', 'pollingTimeout']
-                               }, {
-                                       model: models.MailServerOut,
-                                       attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'state', 'source', 'description']
-                               }, {
-                                       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;
                        });
                }
        });