Built motion from commit c56b56e.|0.0.125
[motion.git] / server / models / mail_account.js
1 /**
2  * Chat Website Model
3  */
4
5 module.exports = function(sequelize, DataTypes) {
6
7         var MailAccount = sequelize.define('MailAccount', {
8                 description: DataTypes.STRING,
9                 name: {
10                         type: DataTypes.STRING
11                 },
12                 address: {
13                         type: DataTypes.STRING,
14                         unique: true,
15                         isEmail: true,
16                         set: function(address) {
17                                 if (address) {
18                                         this.setDataValue('address', address.toLowerCase());
19                                 }
20                         },
21                 },
22                 fidelity: {
23                         type: DataTypes.BOOLEAN,
24                         defaultValue: false
25                 },
26                 timeout: {
27                         type: DataTypes.INTEGER,
28                         defaultValue: 0
29                 },
30                 whiteLabel: {
31                         type: DataTypes.STRING
32                 },
33                 acceptUrl: {
34                         type: DataTypes.STRING
35                 },
36                 rejectUrl: {
37                         type: DataTypes.STRING
38                 },
39                 acceptMethod: {
40                         type: DataTypes.ENUM('GET', 'POST')
41                 },
42                 rejectMethod: {
43                         type: DataTypes.ENUM('GET', 'POST')
44                 },
45                 actions: {
46                         type: DataTypes.STRING,
47                         get: function() {
48                                 return this.getDataValue('actions') ? JSON.parse(this.getDataValue('actions')) : [];
49                         },
50                         set: function(val) {
51                                 return this.setDataValue('actions', JSON.stringify(val));
52                         }
53                 }
54         }, {
55                 tableName: 'mail_accounts',
56                 associate: function(models) {
57                         // RELATIONS
58                         MailAccount.belongsTo(models.List);
59                         MailAccount.belongsTo(models.Template);
60                         MailAccount.hasMany(models.MailRoom);
61                         MailAccount.hasMany(models.MailDisposition);
62                         MailAccount.hasMany(models.MailApplication);
63                         MailAccount.hasOne(models.MailServerIn, {
64                                 onDelete: 'cascade',
65                                 hooks: true
66                         });
67                         MailAccount.hasOne(models.MailServerOut, {
68                                 onDelete: 'cascade',
69                                 hooks: true
70                         });
71
72                         // SCOPES
73                         MailAccount.addScope('default', {
74                                 include: [{
75                                         model: models.MailServerIn,
76                                         attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'delete', 'filter', 'state', 'mailbox', 'connTimeout', 'authTimeout', 'keepalive', 'source']
77                                 }, {
78                                         model: models.MailServerOut,
79                                         attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'service', 'state', 'source']
80                                 }, {
81                                         model: models.MailApplication,
82                                         include: [{
83                                                 model: models.User,
84                                                 attributes: ['id',
85                                                         'name',
86                                                         'email',
87                                                         'internal',
88                                                         'fullname'
89                                                 ]
90                                         }, {
91                                                 model: models.MailQueue
92                                         }]
93                                 }]
94                         });
95                 }
96         });
97
98         return MailAccount;
99 };