javascript all done and test

This commit is contained in:
Benoît Vézina 2023-07-02 07:40:23 -04:00
parent cf124a758f
commit ea05972fee
13 changed files with 146 additions and 144 deletions

View file

@ -19,7 +19,7 @@ Main Features:
""", """,
'sequence': 10, 'sequence': 10,
'license': 'OPL-1', 'license': 'OPL-1',
'author': 'BeMade', 'author': 'Bemade',
'website': 'https://www.bemade.org', 'website': 'https://www.bemade.org',
'depends': ['hr', 'mail', 'bemade_user_password_bundle'], 'depends': ['hr', 'mail', 'bemade_user_password_bundle'],
'data': [ 'data': [
@ -33,14 +33,10 @@ Main Features:
], ],
"assets": { "assets": {
"web.assets_backend": [ "web.assets_backend": [
"bemade_mailcow_blacklist/static/src/js/mailcow_mailbox.js", "bemade_mailcow_blacklist/static/src/js/mailcow.js",
"bemade_mailcow_blacklist/static/src/js/mailcow_alias.js",
"bemade_mailcow_blacklist/static/src/js/mailcow_blacklist.js",
], ],
"web.assets_qweb": [ "web.assets_qweb": [
"bemade_mailcow_blacklist/static/src/xml/mailcow_mailbox.xml", "bemade_mailcow_blacklist/static/src/xml/mailcow_templates.xml",
"bemade_mailcow_blacklist/static/src/xml/mailcow_alias.xml",
"bemade_mailcow_blacklist/static/src/xml/mailcow_blacklist.xml",
], ],
}, },
'demo': [], 'demo': [],

View file

@ -8,7 +8,7 @@ _logger = logging.getLogger(__name__)
class MailcowAlias(models.Model): class MailcowAlias(models.Model):
_name = 'mail.mailcow.alias' _name = 'mail.mailcow.alias'
_description = 'Mailcow Alias' _description = 'Mailcow Alias'
_inherit = ['mail.thread', 'mail.activity.mixin'] _inherit = ['mail.mailcow', 'mail.thread', 'mail.activity.mixin']
_rec_name = 'address' _rec_name = 'address'
address = fields.Char(string='Alias Address', required=True, tracking=True) address = fields.Char(string='Alias Address', required=True, tracking=True)
@ -16,6 +16,9 @@ class MailcowAlias(models.Model):
active = fields.Boolean(string='Active', default=True, tracking=True) active = fields.Boolean(string='Active', default=True, tracking=True)
catchall = fields.Boolean(string='Catchall', default=False, tracking=True) catchall = fields.Boolean(string='Catchall', default=False, tracking=True)
alias_id = fields.Many2one(comodel_name='mail.alias', string='Alias') alias_id = fields.Many2one(comodel_name='mail.alias', string='Alias')
create_date_mailcow = fields.Datetime(string='Created on Mailcow', readonly=True)
modify_date_mailcow = fields.Datetime(string='Modified on Mailcow', readonly=True)
mc_id = fields.Integer(string='Mailcow ID', readonly=True)
_sql_constraints = [ _sql_constraints = [
('address_unique', 'UNIQUE(address)', 'The alias address must be unique!'), ('address_unique', 'UNIQUE(address)', 'The alias address must be unique!'),
@ -27,8 +30,9 @@ class MailcowAlias(models.Model):
if 'mc_id' not in vals: if 'mc_id' not in vals:
data = { data = {
"active": str(int(alias.active)), "active": bool(alias.active),
"address": alias.address, "address": alias.address,
"catchall": bool(alias.catchall),
"goto": alias.goto, "goto": alias.goto,
"private_comment": f"Created by {self.env.user.name} on {fields.Datetime.now()}", "private_comment": f"Created by {self.env.user.name} on {fields.Datetime.now()}",
"public_comment": "Alias created in Odoo" "public_comment": "Alias created in Odoo"
@ -84,16 +88,21 @@ class MailcowAlias(models.Model):
alias_domain = self.env['ir.config_parameter'].sudo().get_param('mail.catchall.domain') alias_domain = self.env['ir.config_parameter'].sudo().get_param('mail.catchall.domain')
if domain == alias_domain: if domain == alias_domain:
alias = self.search([('address', '=', mc_alias['address'])], limit=1) alias = self.search([('mc_id', '=', mc_alias['id'])], limit=1)
if not alias: if not alias:
self.create({ self.create({
'address': mc_alias['address'], 'address': mc_alias['address'],
'active': mc_alias['active'] == '1', 'active': bool(mc_alias['active']),
'goto': mc_alias['goto'], 'goto': mc_alias['goto'],
'domain': mc_alias['domain'] 'mc_id': mc_alias['id'],
'create_date_mailcow': mc_alias['created'],
'modify_date_mailcow': mc_alias['modified'],
}) })
else: else:
alias.write({ alias.write({
'active': mc_alias['active'] == '1', 'address': mc_alias['address'],
'goto': mc_alias['goto'] 'active': bool(mc_alias['active']),
'goto': mc_alias['goto'],
'create_date_mailcow': mc_alias['created'],
'modify_date_mailcow': mc_alias['modified'],
}) })

View file

@ -0,0 +1,89 @@
/** @odoo-module **/
import ListController from 'web.ListController';
import ListView from 'web.ListView';
const viewRegistry = require('web.view_registry');
const AliasesListController = ListController.extend({
// buttons_template must match the t-name on the template for the button (static xml)
buttons_template: 'mail.mailcow_aliases_list_view_buttons',
events: _.extend({}, ListController.prototype.events, {
'click .o_button_sync_aliases': '_onSyncAliases',
}),
// This may need to be async function() if there needs to be an await this._rpc({ ... }); call to not reload early
_onSyncAliases: function () {
this._rpc({
model: 'mail.mailcow.alias',
method: 'sync_aliases',
args: [],
}).then(() => {
this.reload();
});
// Couldn't test this for real, but it runs the action. May need a this.reload()
},
});
const AliasesListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: AliasesListController,
}),
});
// key must match with the js_class attribute of the tree view you want to modify
viewRegistry.add('mail_mailcow_aliases_tree', AliasesListView);
const BlacklistListController = ListController.extend({
// buttons_template must match the t-name on the template for the button (static xml)
buttons_template: 'mail.mailcow_blacklist_list_view_buttons',
events: _.extend({}, ListController.prototype.events, {
'click .o_button_sync_blacklist': '_onSyncBlacklist',
}),
// This may need to be async function() if there needs to be an await this._rpc({ ... }); call to not reload early
_onSyncBlacklist: function () {
this._rpc({
model: 'mail.mailcow.blacklist',
method: 'sync_blacklist',
args: [],
}).then(() => {
this.reload();
});
// Couldn't test this for real, but it runs the action. May need a this.reload()
},
});
const BlacklistListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: BlacklistListController,
}),
});
// key must match with the js_class attribute of the tree view you want to modify
viewRegistry.add('mail_mailcow_blacklist_tree', BlacklistListView);
const MailboxesListController = ListController.extend({
// buttons_template must match the t-name on the template for the button (static xml)
buttons_template: 'mail.mailcow_mailbox_list_view_buttons',
events: _.extend({}, ListController.prototype.events, {
'click .o_button_sync_mailboxes': '_onSyncMailboxes',
}),
// This may need to be async function() if there needs to be an await this._rpc({ ... }); call to not reload early
_onSyncMailboxes: function () {
this._rpc({
model: 'mail.mailcow.mailbox',
method: 'sync_mailboxes',
args: [],
}).then(() => {
this.reload();
});
// Couldn't test this for real, but it runs the action. May need a this.reload()
},
});
const MailboxesListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: MailboxesListController,
}),
});
// key must match with the js_class attribute of the tree view you want to modify
viewRegistry.add('mail_mailcow_mailbox_tree', MailboxesListView);

View file

@ -1,31 +0,0 @@
/** @odoo-module **/
import ListController from 'web.ListController';
import ListView from 'web.ListView';
const viewRegistry = require('web.view_registry');
const AliasesListController = ListController.extend({
// buttons_template must match the t-name on the template for the button (static xml)
buttons_template: 'mail.mailcow_aliases_list_view_buttons',
events: _.extend({}, ListController.prototype.events, {
'click .o_button_sync_aliases': '_onSyncAliases',
}),
// This may need to be async function() if there needs to be an await this._rpc({ ... }); call to not reload early
_onSyncAliases: function () {
this._rpc({
model: 'mail.mailcow.alias',
method: 'sync_aliases',
args: [],
});
// Couldn't test this for real, but it runs the action. May need a this.reload()
},
});
const AliasesListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: AliasesListController,
}),
});
// key must match with the js_class attribute of the tree view you want to modify
viewRegistry.add('mail_mailcow_aliases_tree', AliasesListView);

View file

@ -1,31 +0,0 @@
/** @odoo-module **/
import ListController from 'web.ListController';
import ListView from 'web.ListView';
const viewRegistry = require('web.view_registry');
const MailboxesListController = ListController.extend({
// buttons_template must match the t-name on the template for the button (static xml)
buttons_template: 'mail.mailcow_mailbox_list_view_buttons',
events: _.extend({}, ListController.prototype.events, {
'click .o_button_sync_mailboxes': '_onSyncMailboxes',
}),
// This may need to be async function() if there needs to be an await this._rpc({ ... }); call to not reload early
_onSyncMailboxes: function () {
this._rpc({
model: 'mail.mailcow.mailbox',
method: 'sync_mailboxes',
args: [],
});
// Couldn't test this for real, but it runs the action. May need a this.reload()
},
});
const MailboxesListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: MailboxesListController,
}),
});
// key must match with the js_class attribute of the tree view you want to modify
viewRegistry.add('mail_mailcow_mailbox_tree', MailboxesListView);

View file

@ -1,31 +0,0 @@
/** @odoo-module **/
import ListController from 'web.ListController';
import ListView from 'web.ListView';
const viewRegistry = require('web.view_registry');
const MailboxesListController = ListController.extend({
// buttons_template must match the t-name on the template for the button (static xml)
buttons_template: 'mail.mailcow_mailbox_list_view_buttons',
events: _.extend({}, ListController.prototype.events, {
'click .o_button_sync_mailboxes': '_onSyncMailboxes',
}),
// This may need to be async function() if there needs to be an await this._rpc({ ... }); call to not reload early
_onSyncMailboxes: function () {
this._rpc({
model: 'mail.mailcow.mailbox',
method: 'sync_mailboxes',
args: [],
});
// Couldn't test this for real, but it runs the action. May need a this.reload()
},
});
const MailboxesListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: MailboxesListController,
}),
});
// key must match with the js_class attribute of the tree view you want to modify
viewRegistry.add('mail_mailcow_mailbox_tree', MailboxesListView);

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-extend="ListView.buttons" t-name="mail.mailcow_alias_list_view_buttons"> <!-- t-name must match with js controller button template -->
<t t-jquery="button.o_list_button_add" t-operation="after">
<button type="button"
class="btn btn-primary ml4 o_button_sync_aliases"
title="Sync Aliases"> Sync Aliases </button>
</t>
</t>
</templates>

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-extend="ListView.buttons" t-name="mail.mailcow_blacklist_list_view_buttons"> <!-- t-name must match with js controller button template -->
<t t-jquery="button.o_list_button_add" t-operation="after">
<button type="button"
class="btn btn-primary ml4 o_button_sync_blacklist"
title="Sync Blacklist"> Sync Blacklist </button>
</t>
</t>
</templates>

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-extend="ListView.buttons" t-name="mail.mailcow_mailbox_list_view_buttons"> <!-- t-name must match with js controller button template -->
<t t-jquery="button.o_list_button_add" t-operation="after">
<button type="button"
class="btn btn-primary ml4 o_button_sync_mailboxes"
title="Sync Mailboxes"> Sync Mailboxes </button>
</t>
</t>
</templates>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-extend="ListView.buttons" t-name="mail.mailcow_aliases_list_view_buttons"> <!-- t-name must match with js controller button template -->
<t t-jquery="button.o_list_button_add" t-operation="after">
<button type="button"
class="btn btn-primary ml4 o_button_sync_aliases"
title="Sync Aliases"> Sync Aliases </button>
</t>
</t>
<t t-extend="ListView.buttons" t-name="mail.mailcow_blacklist_list_view_buttons"> <!-- t-name must match with js controller button template -->
<t t-jquery="button.o_list_button_add" t-operation="after">
<button type="button"
class="btn btn-primary ml4 o_button_sync_blacklist"
title="Sync Blacklist"> Sync Blacklist </button>
</t>
</t>
<t t-extend="ListView.buttons" t-name="mail.mailcow_mailbox_list_view_buttons"> <!-- t-name must match with js controller button template -->
<t t-jquery="button.o_list_button_add" t-operation="after">
<button type="button"
class="btn btn-primary ml4 o_button_sync_mailboxes"
title="Sync Mailboxes"> Sync Mailboxes </button>
</t>
</t>
</templates>

View file

@ -4,11 +4,14 @@
<field name="name">mailcow.alias.view.tree</field> <field name="name">mailcow.alias.view.tree</field>
<field name="model">mail.mailcow.alias</field> <field name="model">mail.mailcow.alias</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Alias" decoration-info="active == False"> <tree string="Alias" decoration-info="active == False" js_class="mail_mailcow_aliases_tree">
<field name="active"/>
<field name="address"/> <field name="address"/>
<field name="goto"/>
<field name="alias_id"/> <field name="alias_id"/>
<field name="goto"/>
<field name="create_date_mailcow"/>
<field name="modify_date_mailcow"/>
<field name="mc_id"/>
<field name="active"/>
</tree> </tree>
</field> </field>
</record> </record>

View file

@ -4,7 +4,7 @@
<field name="name">mailcow.blacklist.view.tree</field> <field name="name">mailcow.blacklist.view.tree</field>
<field name="model">mail.mailcow.blacklist</field> <field name="model">mail.mailcow.blacklist</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Blacklist"> <tree string="Blacklist" js_class="mail_mailcow_blacklist_tree">
<field name="email"/> <field name="email"/>
</tree> </tree>
</field> </field>
@ -61,6 +61,6 @@
<field name="sequence" eval="10"/> <field name="sequence" eval="10"/>
<field name="view_mode">tree</field> <field name="view_mode">tree</field>
<field name="act_window_id" ref="action_mailcow_blacklist"/> <field name="act_window_id" ref="action_mailcow_blacklist"/>
<field name="view_id" ref="mailcow_blacklist_view_form"/> <field name="view_id" ref="mailcow_blacklist_view_tree"/>
</record> </record>
</odoo> </odoo>

View file

@ -4,13 +4,13 @@
<field name="name">mailcow.mailbox.view.tree</field> <field name="name">mailcow.mailbox.view.tree</field>
<field name="model">mail.mailcow.mailbox</field> <field name="model">mail.mailcow.mailbox</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Mailbox" decoration-info="active == False" js_class="mail_mailcow_mailbox_tree"> <!-- js_class must match the name added to the viewRegistry in js --> <tree string="Mailbox" js_class="mail_mailcow_mailbox_tree"> <!-- js_class must match the name added to the viewRegistry in js -->
<field name="active"/>
<field name="name"/> <field name="name"/>
<field name="local_part"/> <field name="local_part"/>
<field name="domain"/> <field name="domain"/>
<field name="address"/> <field name="address"/>
<field name="user_id"/> <field name="user_id"/>
<field name="active"/>
</tree> </tree>
</field> </field>
</record> </record>