From c394040d4894fc2d1aba59f1f61b0bd61fa79a9f Mon Sep 17 00:00:00 2001 From: "matthieu.saison" Date: Mon, 25 Sep 2023 08:53:37 +0200 Subject: [PATCH] mail_send override --- mail_env_whitelist/__init__.py | 1 + mail_env_whitelist/__manifest__.py | 13 ++++++++++ .../data/ir_config_parameter_data.xml | 7 ++++++ mail_env_whitelist/models/__init__.py | 1 + mail_env_whitelist/models/ir_mail_server.py | 25 +++++++++++++++++++ .../odoo/addons/mail_env_whitelist | 1 + setup/mail_env_whitelist/setup.py | 6 +++++ 7 files changed, 54 insertions(+) create mode 100644 mail_env_whitelist/__init__.py create mode 100644 mail_env_whitelist/__manifest__.py create mode 100644 mail_env_whitelist/data/ir_config_parameter_data.xml create mode 100644 mail_env_whitelist/models/__init__.py create mode 100644 mail_env_whitelist/models/ir_mail_server.py create mode 120000 setup/mail_env_whitelist/odoo/addons/mail_env_whitelist create mode 100644 setup/mail_env_whitelist/setup.py diff --git a/mail_env_whitelist/__init__.py b/mail_env_whitelist/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mail_env_whitelist/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_env_whitelist/__manifest__.py b/mail_env_whitelist/__manifest__.py new file mode 100644 index 000000000..76fceb97c --- /dev/null +++ b/mail_env_whitelist/__manifest__.py @@ -0,0 +1,13 @@ +{ + "name": "Mail env whitelist", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "author": "Akretion", + "website": "https://github.com/akretion/ak-odoo-incubator", + "category": "Custom", + "summary": "send email on stagging env when the receiver is in the whitelist", + "depends": ["mail"], + "data": [ + "data/ir_config_parameter_data.xml", + ], +} diff --git a/mail_env_whitelist/data/ir_config_parameter_data.xml b/mail_env_whitelist/data/ir_config_parameter_data.xml new file mode 100644 index 000000000..225c791a0 --- /dev/null +++ b/mail_env_whitelist/data/ir_config_parameter_data.xml @@ -0,0 +1,7 @@ + + + + mail_env_whitelist.test_env_email_to_whitelist + + + diff --git a/mail_env_whitelist/models/__init__.py b/mail_env_whitelist/models/__init__.py new file mode 100644 index 000000000..abbcb50bd --- /dev/null +++ b/mail_env_whitelist/models/__init__.py @@ -0,0 +1 @@ +from . import ir_mail_server diff --git a/mail_env_whitelist/models/ir_mail_server.py b/mail_env_whitelist/models/ir_mail_server.py new file mode 100644 index 000000000..aabd9b2e1 --- /dev/null +++ b/mail_env_whitelist/models/ir_mail_server.py @@ -0,0 +1,25 @@ +# Copyright 2023 Akretion (https://www.akretion.com). +# @author Matthieu SAISON +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import re + +from odoo import api, models +from odoo.tools.config import config + + +class IrMailServer(models.Model): + _inherit = "ir.mail_server" + + @api.model + def send_email(self, message, *args, **kwargs): + if config["running_env"] != "prod": + whitelist = self.env["ir.config_parameter"].get_param( + "mail_env_whitelist.test_env_email_to_whitelist" + ) + for email in message["To"].split(";"): + email = re.search("<(.*)>", email).group(1) + if email not in whitelist: + continue + else: + super().send_email(message, *args, **kwargs) diff --git a/setup/mail_env_whitelist/odoo/addons/mail_env_whitelist b/setup/mail_env_whitelist/odoo/addons/mail_env_whitelist new file mode 120000 index 000000000..3642a68db --- /dev/null +++ b/setup/mail_env_whitelist/odoo/addons/mail_env_whitelist @@ -0,0 +1 @@ +../../../../mail_env_whitelist \ No newline at end of file diff --git a/setup/mail_env_whitelist/setup.py b/setup/mail_env_whitelist/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mail_env_whitelist/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)