2 more modules to test

This commit is contained in:
Benoît Vézina 2023-07-02 15:07:33 -04:00
parent b58ff52597
commit 83dc8d346e
18 changed files with 313 additions and 14 deletions

View file

@ -0,0 +1 @@
from . import models

View file

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
{
'name': 'Helpdesk Mailcow Blacklist',
'version': '1.0.0',
'category': 'Administration',
'summary': 'Module for adding blacklist functionality to the helpdesk.',
'description': """
Helpdesk Mailcow Blacklist
==========================
This module extends the functionality of the Helpdesk and Mailcow Blacklist modules by adding an action to blacklist the sender of a Helpdesk ticket.
Main Features:
--------------
- Adds a button on Helpdesk tickets to blacklist the email sender.
- This button is only visible when an email is associated with the ticket.
- Blacklisting an email sender automatically moves the Helpdesk ticket to a new 'Spam' stage, which is marked as closed.
- The 'Spam' stage is automatically created by this module.
""",
'sequence': 10,
'license': 'GPL-3',
'author': 'Bemade',
'website': 'https://www.bemade.org',
'depends': ['helpdesk', 'bemade_mailcow_blacklist'],
'data': [
'security/ir.model.access.csv',
'data/helpdesk_stages.xml',
'views/helpdesk_ticket_views.xml',
],
'demo': [
'demo/demo.xml'
],
'installable': True,
'application': False,
'auto_install': False
}

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="helpdesk_stage_spam" model="helpdesk.stage">
<field name="name">Spam</field>
<field name="sequence">50</field>
<field name="is_closed">True</field>
</record>
</data>
</odoo>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data noupdate="1">
<!-- Demo User -->
<record id="demo_user_1" model="res.users">
<field name="name">Demo User</field>
<field name="login">demo_user</field>
<field name="password">demo_user</field>
<field name="email">demo_user@example.com</field>
</record>
<!-- Demo Helpdesk Team -->
<record id="demo_helpdesk_team_1" model="helpdesk.team">
<field name="name">Demo Helpdesk Team</field>
</record>
<!-- Demo Helpdesk Ticket -->
<record id="demo_helpdesk_ticket_1" model="helpdesk.ticket">
<field name="name">Demo Helpdesk Ticket</field>
<field name="team_id" ref="demo_helpdesk_team_1"/>
<field name="user_id" ref="demo_user_1"/>
<field name="partner_email">demo_sender@example.com</field>
<field name="partner_id" ref="base.res_partner_1"/>
<field name="description">This is a demo ticket for testing the blacklist feature.</field>
</record>
</data>
</odoo>

View file

@ -0,0 +1 @@
from . import helpdesk_ticket

View file

@ -0,0 +1,24 @@
from odoo import api, fields, models
from odoo.exceptions import UserError
class HelpdeskTicket(models.Model):
_inherit = 'helpdesk.ticket'
def add_blacklist(self):
self.ensure_one()
# Create a new blacklist record
blacklist = self.env['mailcow.blacklist'].create({
'email': self.email,
})
# Assign 'spam' as a closed stage
spam_stage = self.env.ref('bemade_helpdesk_mailcow_blacklist.helpdesk_stage_spam')
if spam_stage:
self.stage_id = spam_stage.id
else:
raise UserError(_('The Spam stage does not exist.'))
return True

View file

@ -0,0 +1,11 @@
from odoo import models, api
class ResPartner(models.Model):
_inherit = 'res.partner'
@api.multi
def send_validation_email(self):
for partner in self:
if not partner.email_validated:
# Assuming you have a method called send_validation_email that sends the validation email.
partner.send_validation_email()

View file

@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_bemade_helpdesk_mailcow_blacklist,access_bemade_helpdesk_mailcow_blacklist,model_bemade_helpdesk_mailcow_blacklist,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_bemade_helpdesk_mailcow_blacklist access_bemade_helpdesk_mailcow_blacklist model_bemade_helpdesk_mailcow_blacklist base.group_user 1 1 1 1

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_ticket_form_inherit_mailcow" model="ir.ui.view">
<field name="name">helpdesk.ticket.form.mailcow</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk.helpdesk_ticket_view_form"/>
<field name="arch" type="xml">
<header position="inside">
<button name="action_add_blacklist" type="object" string="Add to Blacklist" class="oe_highlight" attrs="{'invisible': [('email_from', '=', False)]}"/>
</header>
</field>
</record>
</odoo>

View file

@ -2,23 +2,23 @@
{ {
'name': 'Mailcow Integration', 'name': 'Mailcow Integration',
'version': '1.0.0', 'version': '1.0.0',
'category': 'Extra Tools', 'category': 'Administration',
'summary': 'Module for integrating Mailcow email server with Odoo.', 'summary': 'Module for integrating Mailcow email server with Odoo.',
'description': """ 'description': """
Mailcow Integration Mailcow Integration
=================== ===================
This module integrates the Mailcow email server with Odoo, providing a seamless email communication solution for your Odoo instance. It allows for syncing of mailboxes and email aliases from Mailcow to Odoo and vice versa. This module integrates the Mailcow email server with Odoo, providing a seamless email communication solution for your Odoo instance. It allows for syncing of mailboxes and email aliases from Mailcow to Odoo and vice versa.
Main Features: Main Features:
-------------- --------------
* Synchronize Mailcow mailboxes with Odoo users. * Synchronize Mailcow mailboxes with Odoo users.
* Synchronize Mailcow email aliases with Odoo. * Synchronize Mailcow email aliases with Odoo.
* Configuration of Mailcow API credentials in Odoo settings. * Configuration of Mailcow API credentials in Odoo settings.
* Automatically create and manage mailboxes and aliases in Mailcow when they are created in Odoo. * Automatically create and manage mailboxes and aliases in Mailcow when they are created in Odoo.
""", """,
'sequence': 10, 'sequence': 10,
'license': 'OPL-1', 'license': 'GPL-3',
'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'],
@ -29,7 +29,6 @@ Main Features:
'views/mailcow_alias_views.xml', 'views/mailcow_alias_views.xml',
'views/mailcow_blacklist_views.xml', 'views/mailcow_blacklist_views.xml',
'views/res_users_views.xml', 'views/res_users_views.xml',
], ],
"assets": { "assets": {
"web.assets_backend": [ "web.assets_backend": [
@ -42,5 +41,5 @@ Main Features:
'demo': [], 'demo': [],
'installable': True, 'installable': True,
'application': False, 'application': False,
'auto_install': False, 'auto_install': False
} }

View file

@ -0,0 +1,13 @@
from odoo import http
from odoo.http import request
class EmailValidationController(http.Controller):
@http.route('/email_validation/<int:partner_id>/<token>', type='http', auth='public', website=True)
def email_validation(self, partner_id, token):
partner = request.env['res.partner'].sudo().browse(partner_id)
if partner and partner.validation_token == token:
partner.sudo().write({'email_validated': True})
return "Email validated!"
else:
return "Invalid validation link."

View file

@ -0,0 +1,32 @@
{
'name': 'Validate Partner Email',
'version': '1.0.0',
'category': 'Extra Tools',
'summary': 'Module to validate the email addresses of partners.',
'description': """
Validate Partner Email
===================
This module adds a functionality to validate the email addresses of partners in Odoo. A new boolean field 'email_validated' is added to the 'res.partner' model. When an email address is entered or changed, 'email_validated' is set to False and a validation email is sent to the new email address. If the recipient clicks the link in the validation email, 'email_validated' is set to True. Before sending an email to a partner, the system checks whether the partner's email is validated and if not, a message is posted in the chatter.
Main Features:
--------------
* Add 'email_validated' field to 'res.partner'.
* Send validation email when 'email_validated' is False.
* Post message in chatter when trying to send email to partner with unvalidated email.
""",
'sequence': 10,
'license': 'GPL-3',
'author': 'Bemade',
'website': 'https://www.bemade.org',
'depends': ['base', 'mail'],
'data': [
'security/ir.model.access.csv',
'views/res_partner_views.xml',
'data/mail_template_data.xml'
],
'demo': ['demo/res_partner_demo.xml'],
'installable': True,
'application': False,
'auto_install': False
}

View file

@ -0,0 +1,12 @@
from odoo import http
from odoo.http import request
class ValidateEmailController(http.Controller):
@http.route(['/validate_email/<model("res.partner"):partner>/<token>'], type='http', auth="public", website=True)
def validate_email(self, partner, token, **kw):
if partner.email_validation_token != token:
return request.render("bemade_validate_partner_email.invalid_token", {})
else:
partner.sudo().write({'email_validated': True})
return request.render("bemade_validate_partner_email.email_validated", {})

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Email template for the email validation -->
<record id="email_template_validation" model="mail.template">
<field name="name">Email Validation</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="subject">Please validate your email address</field>
<field name="body_html">
<![CDATA[
<p>Dear ${object.name},</p>
<p>
We have recently received a request to validate your email address
for our records. Please click on the link below to confirm that
this is your email address.
</p>
<p>
<a href="/validate_email/${object.id}/${object.email_validation_token}">Click here to validate your email</a>
</p>
<p>
If you have received this email in error, no action is required.
Your email address will not be validated if you do not click the link.
</p>
<p>
Thank you!
</p>
]]>
</field>
<field name="email_from">${object.company_id.email}</field>
<field name="email_to">${object.email}</field>
<field name="auto_delete" eval="True"/>
</record>
</data>
</odoo>

View file

@ -0,0 +1,16 @@
from odoo import models, exceptions, _
class Mail(models.Model):
_inherit = 'mail.mail'
def send(self, auto_commit=False, raise_exception=False):
for mail in self:
if mail.email_to:
partner = self.env['res.partner'].search([('email', '=', mail.email_to)], limit=1)
if partner and not partner.email_validated:
model = self.env[mail.model].browse(mail.res_id)
model.message_post(body=_('Cannot send email because the recipient\'s email address is not validated.'))
if raise_exception:
raise exceptions.UserError(_('Cannot send email because the recipient\'s email address is not validated.'))
continue
return super().send(auto_commit=auto_commit, raise_exception=raise_exception)

View file

@ -0,0 +1,30 @@
from odoo import models, fields, api, _
class Partner(models.Model):
_inherit = 'res.partner'
email_validated = fields.Boolean(string='Email Validated', default=False)
email_validation_token = fields.Char(string="Email Validation Token", copy=False)
@api.model
def create(self, vals):
if'Email' in vals:
vals['email_validated'] = False
partner = super().create(vals)
partner._send_validation_email()
return partner
def write(self, vals):
if 'email' in vals:
vals['email_validated'] = False
res = super().write(vals)
for partner in self:
partner._send_validation_email()
return res
def send_validation_email(self):
for partner in self:
token = misc.generate_tracking_token()
partner.email_validation_token = token
partner.validation_email_template_id.send_mail(partner.id)

View file

@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_res_partner_validate_email,access_res_partner_validate_email,model_res_partner,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_res_partner_validate_email access_res_partner_validate_email model_res_partner base.group_user 1 1 1 1

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form.email.validated</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='email']" position="after">
<field name="email_validated"/>
<button name="send_validation_email" type="object" string="Resend Validation Email" attrs="{'invisible': [('email_validated', '=', True)]}"/>
</xpath>
</field>
</record>
<record id="action_send_validation_emails" model="ir.actions.server">
<field name="name">Send Validation Emails</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="state">code</field>
<field name="code">model.send_validation_email()</field>
</record>
<record id="res_partner_view_tree" model="ir.ui.view">
<field name="name">res.partner.tree</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<tree position="attributes">
<attribute name="decoration-muted">email_validated == True</attribute>
</tree>
<xpath expr="//field[@name='email']" position="after">
<field name="email_validated"/>
</xpath>
</field>
</record>
</odoo>
```