diff --git a/bemade_helpdesk_mailcow_blacklist/__init__.py b/bemade_helpdesk_mailcow_blacklist/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/bemade_helpdesk_mailcow_blacklist/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/bemade_helpdesk_mailcow_blacklist/__manifest__.py b/bemade_helpdesk_mailcow_blacklist/__manifest__.py new file mode 100644 index 0000000..72bdabf --- /dev/null +++ b/bemade_helpdesk_mailcow_blacklist/__manifest__.py @@ -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 +} diff --git a/bemade_helpdesk_mailcow_blacklist/data/helpdesk_stages.xml b/bemade_helpdesk_mailcow_blacklist/data/helpdesk_stages.xml new file mode 100644 index 0000000..3656b40 --- /dev/null +++ b/bemade_helpdesk_mailcow_blacklist/data/helpdesk_stages.xml @@ -0,0 +1,10 @@ + + + + + Spam + 50 + True + + + diff --git a/bemade_helpdesk_mailcow_blacklist/demo/demo.xml b/bemade_helpdesk_mailcow_blacklist/demo/demo.xml new file mode 100644 index 0000000..b8f2a97 --- /dev/null +++ b/bemade_helpdesk_mailcow_blacklist/demo/demo.xml @@ -0,0 +1,27 @@ + + + + + + Demo User + demo_user + demo_user + demo_user@example.com + + + + + Demo Helpdesk Team + + + + + Demo Helpdesk Ticket + + + demo_sender@example.com + + This is a demo ticket for testing the blacklist feature. + + + diff --git a/bemade_helpdesk_mailcow_blacklist/models/__init__.py b/bemade_helpdesk_mailcow_blacklist/models/__init__.py new file mode 100644 index 0000000..deff245 --- /dev/null +++ b/bemade_helpdesk_mailcow_blacklist/models/__init__.py @@ -0,0 +1 @@ +from . import helpdesk_ticket \ No newline at end of file diff --git a/bemade_helpdesk_mailcow_blacklist/models/helpdesk_ticket.py b/bemade_helpdesk_mailcow_blacklist/models/helpdesk_ticket.py new file mode 100644 index 0000000..5ca307f --- /dev/null +++ b/bemade_helpdesk_mailcow_blacklist/models/helpdesk_ticket.py @@ -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 diff --git a/bemade_helpdesk_mailcow_blacklist/models/res_partner.py b/bemade_helpdesk_mailcow_blacklist/models/res_partner.py new file mode 100644 index 0000000..b11a071 --- /dev/null +++ b/bemade_helpdesk_mailcow_blacklist/models/res_partner.py @@ -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() diff --git a/bemade_helpdesk_mailcow_blacklist/security/ir.model.access.csv b/bemade_helpdesk_mailcow_blacklist/security/ir.model.access.csv new file mode 100644 index 0000000..4d035d4 --- /dev/null +++ b/bemade_helpdesk_mailcow_blacklist/security/ir.model.access.csv @@ -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 diff --git a/bemade_helpdesk_mailcow_blacklist/views/helpdesk_ticket_views.xml b/bemade_helpdesk_mailcow_blacklist/views/helpdesk_ticket_views.xml new file mode 100644 index 0000000..fb2fde7 --- /dev/null +++ b/bemade_helpdesk_mailcow_blacklist/views/helpdesk_ticket_views.xml @@ -0,0 +1,13 @@ + + + + helpdesk.ticket.form.mailcow + helpdesk.ticket + + +
+
+
+
+
diff --git a/bemade_mailcow_blacklist/__manifest__.py b/bemade_mailcow_blacklist/__manifest__.py index cdb0e36..a076e1a 100644 --- a/bemade_mailcow_blacklist/__manifest__.py +++ b/bemade_mailcow_blacklist/__manifest__.py @@ -2,23 +2,23 @@ { 'name': 'Mailcow Integration', 'version': '1.0.0', - 'category': 'Extra Tools', + 'category': 'Administration', 'summary': 'Module for integrating Mailcow email server with Odoo.', '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: --------------- -* Synchronize Mailcow mailboxes with Odoo users. -* Synchronize Mailcow email aliases with Odoo. -* Configuration of Mailcow API credentials in Odoo settings. -* Automatically create and manage mailboxes and aliases in Mailcow when they are created in Odoo. -""", + Main Features: + -------------- + * Synchronize Mailcow mailboxes with Odoo users. + * Synchronize Mailcow email aliases with Odoo. + * Configuration of Mailcow API credentials in Odoo settings. + * Automatically create and manage mailboxes and aliases in Mailcow when they are created in Odoo. + """, 'sequence': 10, - 'license': 'OPL-1', + 'license': 'GPL-3', 'author': 'Bemade', 'website': 'https://www.bemade.org', 'depends': ['hr', 'mail', 'bemade_user_password_bundle'], @@ -29,7 +29,6 @@ Main Features: 'views/mailcow_alias_views.xml', 'views/mailcow_blacklist_views.xml', 'views/res_users_views.xml', - ], "assets": { "web.assets_backend": [ @@ -42,5 +41,5 @@ Main Features: 'demo': [], 'installable': True, 'application': False, - 'auto_install': False, + 'auto_install': False } diff --git a/bemade_mailcow_blacklist/controllers/controllers.py b/bemade_mailcow_blacklist/controllers/controllers.py new file mode 100644 index 0000000..bd69c50 --- /dev/null +++ b/bemade_mailcow_blacklist/controllers/controllers.py @@ -0,0 +1,13 @@ +from odoo import http +from odoo.http import request + +class EmailValidationController(http.Controller): + + @http.route('/email_validation//', 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." diff --git a/bemade_partner_email_validation/__manifest__.py b/bemade_partner_email_validation/__manifest__.py new file mode 100644 index 0000000..032e2e4 --- /dev/null +++ b/bemade_partner_email_validation/__manifest__.py @@ -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 +} \ No newline at end of file diff --git a/bemade_partner_email_validation/controllers/controllers.py b/bemade_partner_email_validation/controllers/controllers.py new file mode 100644 index 0000000..e502460 --- /dev/null +++ b/bemade_partner_email_validation/controllers/controllers.py @@ -0,0 +1,12 @@ +from odoo import http +from odoo.http import request + +class ValidateEmailController(http.Controller): + + @http.route(['/validate_email//'], 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", {}) diff --git a/bemade_partner_email_validation/data/mail_template_data.xml b/bemade_partner_email_validation/data/mail_template_data.xml new file mode 100644 index 0000000..20eb1fb --- /dev/null +++ b/bemade_partner_email_validation/data/mail_template_data.xml @@ -0,0 +1,34 @@ + + + + + + Email Validation + + Please validate your email address + + Dear ${object.name},

+

+ 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. +

+

+ Click here to validate your email +

+

+ 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. +

+

+ Thank you! +

+ ]]> +
+ ${object.company_id.email} + ${object.email} + +
+
+
diff --git a/bemade_partner_email_validation/models/mail_mail.py b/bemade_partner_email_validation/models/mail_mail.py new file mode 100644 index 0000000..0e70353 --- /dev/null +++ b/bemade_partner_email_validation/models/mail_mail.py @@ -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) diff --git a/bemade_partner_email_validation/models/res_partner.py b/bemade_partner_email_validation/models/res_partner.py new file mode 100644 index 0000000..7cb7198 --- /dev/null +++ b/bemade_partner_email_validation/models/res_partner.py @@ -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) diff --git a/bemade_partner_email_validation/security/ir.model.access.csv b/bemade_partner_email_validation/security/ir.model.access.csv new file mode 100644 index 0000000..c7f3453 --- /dev/null +++ b/bemade_partner_email_validation/security/ir.model.access.csv @@ -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 diff --git a/bemade_partner_email_validation/views/res_partner_views.xml b/bemade_partner_email_validation/views/res_partner_views.xml new file mode 100644 index 0000000..f90e613 --- /dev/null +++ b/bemade_partner_email_validation/views/res_partner_views.xml @@ -0,0 +1,36 @@ + + + + res.partner.form.email.validated + res.partner + + + + +