-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from akretion/14.0-mail_env_white_list
mail_send override
- Loading branch information
Showing
7 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo noupdate="1"> | ||
<record id="test_env_email_to_whitelist" model="ir.config_parameter"> | ||
<field name="key">mail_env_whitelist.test_env_email_to_whitelist</field> | ||
<field name="value" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import ir_mail_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2023 Akretion (https://www.akretion.com). | ||
# @author Matthieu SAISON <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import re | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import UserError | ||
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" | ||
) | ||
if not whitelist: | ||
raise UserError( | ||
_( | ||
"Whitelist is not configured. Configure the following parameter " | ||
"'mail_env_whitelist.test_env_email_to_whitelist'" | ||
) | ||
) | ||
for key in ["To", "cc", "Bcc"]: | ||
if message[key]: | ||
for email in message[key].split(";"): | ||
match = re.search("<(.*)>", email) | ||
if match: | ||
# in case of full syntax "foo" <[email protected]> | ||
# extract the email | ||
email = match.group(1) | ||
email = email.lower() | ||
if email not in whitelist: | ||
raise UserError( | ||
_("Test env: following mail is not allowed %s") % email | ||
) | ||
return super().send_email(message, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../mail_env_whitelist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |