Built motion from commit b33b832.|1.0.17
[motion.git] / server / models / mail_account.js
index 1ec8826..10228b0 100644 (file)
@@ -1 +1,131 @@
-var _0x5960=["\x65\x78\x70\x6F\x72\x74\x73","\x4D\x61\x69\x6C\x41\x63\x63\x6F\x75\x6E\x74","\x53\x54\x52\x49\x4E\x47","\x6D\x61\x69\x6C\x5F\x61\x63\x63\x6F\x75\x6E\x74\x73","\x68\x61\x73\x4D\x61\x6E\x79","\x63\x61\x73\x63\x61\x64\x65","\x68\x61\x73\x4F\x6E\x65","\x64\x65\x66\x69\x6E\x65"];module[_0x5960[0]]=function(_0x7bdfx1,_0x7bdfx2){var _0x7bdfx3=_0x7bdfx1[_0x5960[7]](_0x5960[1],{description:_0x7bdfx2[_0x5960[2]],name:{type:_0x7bdfx2[_0x5960[2]],unique:true},address:_0x7bdfx2[_0x5960[2]]},{tableName:_0x5960[3],associate:function(_0x7bdfx4){_0x7bdfx3[_0x5960[4]](_0x7bdfx4.MailRoom);_0x7bdfx3[_0x5960[4]](_0x7bdfx4.MailTemplate);_0x7bdfx3[_0x5960[4]](_0x7bdfx4.MailApplication);_0x7bdfx3[_0x5960[6]](_0x7bdfx4.MailServerIn,{onDelete:_0x5960[5],hooks:true});_0x7bdfx3[_0x5960[6]](_0x7bdfx4.MailServerOut,{onDelete:_0x5960[5],hooks:true});}});return _0x7bdfx3;};
\ No newline at end of file
+'use strict';
+
+const _ = require('lodash');
+
+module.exports = function(sequelize, DataTypes) {
+       var MailAccount = sequelize.define('MailAccount', {
+               description: DataTypes.STRING,
+               name: {
+                       type: DataTypes.STRING
+               },
+               address: {
+                       type: DataTypes.STRING,
+                       unique: 'address',
+                       isEmail: true,
+                       set: function(address) {
+                               if (address) {
+                                       this.setDataValue('address', address.toLowerCase());
+                               }
+                       }
+               },
+               fidelity: {
+                       type: DataTypes.BOOLEAN,
+                       defaultValue: false
+               },
+               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',
+                               hooks: true
+                       });
+                       MailAccount.hasOne(models.MailServerOut, {
+                               onDelete: 'cascade',
+                               hooks: true
+                       });
+
+                       // SCOPES
+                       MailAccount.addScope('default', function(query) {
+                               var opt = {
+                                       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,
+                                               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;
+                       });
+               }
+       });
+
+       return MailAccount;
+};