javascipt working
This commit is contained in:
parent
e17f32dfaf
commit
cf124a758f
9 changed files with 150 additions and 34 deletions
|
|
@ -34,9 +34,13 @@ 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_mailbox.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_mailbox.xml",
|
||||||
|
"bemade_mailcow_blacklist/static/src/xml/mailcow_alias.xml",
|
||||||
|
"bemade_mailcow_blacklist/static/src/xml/mailcow_blacklist.xml",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
'demo': [],
|
'demo': [],
|
||||||
|
|
|
||||||
|
|
@ -34,17 +34,18 @@ class MailcowMailbox(models.Model):
|
||||||
"""
|
"""
|
||||||
endpoint = '/api/v1/get/mailbox/all'
|
endpoint = '/api/v1/get/mailbox/all'
|
||||||
data = self.api_request(endpoint)
|
data = self.api_request(endpoint)
|
||||||
|
domain = self.env['ir.config_parameter'].sudo().get_param('mail.catchall.domain')
|
||||||
if data:
|
if data:
|
||||||
for item in data:
|
for item in data:
|
||||||
domain = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
|
||||||
if item['domain'] == domain:
|
if item['domain'] == domain:
|
||||||
self.create({
|
mailbox = self.env['mail.mailcow.mailbox'].search([('address', '=', f"{item['local_part']}@{item['domain']}")])
|
||||||
'name': item['name'],
|
if not mailbox:
|
||||||
'local_part': item['local_part'],
|
self.create({
|
||||||
'domain': item['domain'],
|
'name': item['name'],
|
||||||
'active': item['active'],
|
'local_part': item['local_part'],
|
||||||
'password': item['password'],
|
'domain': item['domain'],
|
||||||
})
|
'active': item['active'],
|
||||||
|
})
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
|
|
@ -101,9 +102,15 @@ class MailcowMailbox(models.Model):
|
||||||
"""
|
"""
|
||||||
Override the unlink function to delete a Mailcow mailbox whenever a user is deleted in Odoo.
|
Override the unlink function to delete a Mailcow mailbox whenever a user is deleted in Odoo.
|
||||||
"""
|
"""
|
||||||
endpoint = f'/api/v1/delete/mailbox/{self.address}'
|
|
||||||
self.api_request(endpoint, method='POST')
|
for mailbox in self:
|
||||||
_logger.info(f'Mailbox {self.address} has been deleted on Mailcow server')
|
data = {
|
||||||
|
'username': mailbox.address
|
||||||
|
}
|
||||||
|
|
||||||
|
endpoint = f'/api/v1/delete/mailbox'
|
||||||
|
mailbox.api_request(endpoint, method='POST', data=data)
|
||||||
|
_logger.info(f'Mailbox {mailbox.address} has been deleted on Mailcow server')
|
||||||
|
|
||||||
return super().unlink()
|
return super().unlink()
|
||||||
|
|
||||||
|
|
|
||||||
31
bemade_mailcow_blacklist/static/src/js/mailcow_alias.js
Normal file
31
bemade_mailcow_blacklist/static/src/js/mailcow_alias.js
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/** @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);
|
||||||
31
bemade_mailcow_blacklist/static/src/js/mailcow_blacklist.js
Normal file
31
bemade_mailcow_blacklist/static/src/js/mailcow_blacklist.js
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/** @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);
|
||||||
10
bemade_mailcow_blacklist/static/src/xml/mailcow_alias.xml
Normal file
10
bemade_mailcow_blacklist/static/src/xml/mailcow_alias.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?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>
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?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>
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="mailcow_alias_action" model="ir.actions.act_window">
|
<record id="action_mailcow_alias" model="ir.actions.act_window">
|
||||||
<field name="name">Aliases</field>
|
<field name="name">Aliases</field>
|
||||||
<field name="type">ir.actions.act_window</field>
|
<field name="type">ir.actions.act_window</field>
|
||||||
<field name="res_model">mail.mailcow.alias</field>
|
<field name="res_model">mail.mailcow.alias</field>
|
||||||
|
|
@ -53,6 +53,21 @@
|
||||||
<menuitem id="mailcow_menu_alias"
|
<menuitem id="mailcow_menu_alias"
|
||||||
name="Aliases"
|
name="Aliases"
|
||||||
parent="mailcow_menu"
|
parent="mailcow_menu"
|
||||||
action="mailcow_alias_action"
|
action="action_mailcow_alias"
|
||||||
sequence="20"/>
|
sequence="20"/>
|
||||||
|
|
||||||
|
<record id="action_server_sync_aliases" model="ir.actions.server">
|
||||||
|
<field name="name">Sync Aliases</field>
|
||||||
|
<field name="model_id" ref="model_mail_mailcow_alias"/>
|
||||||
|
<field name="state">code</field>
|
||||||
|
<field name="code">model.sync_aliases()</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_sync_aliases" model="ir.actions.act_window.view">
|
||||||
|
<field name="sequence" eval="10"/>
|
||||||
|
<field name="view_mode">tree</field>
|
||||||
|
<field name="act_window_id" ref="action_mailcow_alias"/>
|
||||||
|
<field name="view_id" ref="mailcow_alias_view_tree"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="mailcow_blacklist_action" model="ir.actions.act_window">
|
<record id="action_mailcow_blacklist" model="ir.actions.act_window">
|
||||||
<field name="name">Blacklist</field>
|
<field name="name">Blacklist</field>
|
||||||
<field name="type">ir.actions.act_window</field>
|
<field name="type">ir.actions.act_window</field>
|
||||||
<field name="res_model">mail.mailcow.blacklist</field>
|
<field name="res_model">mail.mailcow.blacklist</field>
|
||||||
|
|
@ -47,6 +47,20 @@
|
||||||
<menuitem id="mailcow_menu_blacklist"
|
<menuitem id="mailcow_menu_blacklist"
|
||||||
name="Blacklist"
|
name="Blacklist"
|
||||||
parent="mailcow_menu"
|
parent="mailcow_menu"
|
||||||
action="mailcow_blacklist_action"
|
action="action_mailcow_blacklist"
|
||||||
sequence="30"/>
|
sequence="30"/>
|
||||||
|
|
||||||
|
<record id="action_server_sync_blacklist" model="ir.actions.server">
|
||||||
|
<field name="name">Sync Blacklist</field>
|
||||||
|
<field name="model_id" ref="model_mail_mailcow_blacklist"/>
|
||||||
|
<field name="state">code</field>
|
||||||
|
<field name="code">model.sync_blacklist()</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_sync_blacklist" model="ir.actions.act_window.view">
|
||||||
|
<field name="sequence" eval="10"/>
|
||||||
|
<field name="view_mode">tree</field>
|
||||||
|
<field name="act_window_id" ref="action_mailcow_blacklist"/>
|
||||||
|
<field name="view_id" ref="mailcow_blacklist_view_form"/>
|
||||||
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
||||||
|
|
@ -5,35 +5,29 @@
|
||||||
<field name="model">res.config.settings</field>
|
<field name="model">res.config.settings</field>
|
||||||
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
|
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//div[hasclass('settings')]" position="inside">
|
<div id="emails" position='after'>
|
||||||
<div class="app_settings_block" data-string="Mailcow" string="Mailcow" data-key="mailcow" groups="base.group_system">
|
<div id="mailcow">
|
||||||
<h2>Mailcow Settings</h2>
|
<h2>Mailcow Settings</h2>
|
||||||
<div class="row mt16 o_settings_container">
|
<div class="row mt16 o_settings_container">
|
||||||
<div class="col-12 col-lg-6 o_setting_box">
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
<div class="o_setting_left_pane">
|
<label for="mailcow_base_url" string="Mailcow URL"/>
|
||||||
<field name="mailcow_api_key"/>
|
<div class="text-muted">
|
||||||
|
Base URL for Mailcow server
|
||||||
</div>
|
</div>
|
||||||
<div class="o_setting_right_pane">
|
<div class="content-group">
|
||||||
<label for="mailcow_api_key"/>
|
|
||||||
<div class="text-muted">
|
|
||||||
API key for Mailcow server
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-12 col-lg-6 o_setting_box">
|
|
||||||
<div class="o_setting_left_pane">
|
|
||||||
<field name="mailcow_base_url"/>
|
<field name="mailcow_base_url"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="o_setting_right_pane">
|
<label for="mailcow_api_key" string="API Key"/>
|
||||||
<label for="mailcow_base_url"/>
|
<div class="text-muted">
|
||||||
<div class="text-muted">
|
Mailcow API Key
|
||||||
Base URL for Mailcow server
|
</div>
|
||||||
</div>
|
<div class="content-group">
|
||||||
|
<field name="mailcow_api_key"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</div>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue