Skip to content

Commit

Permalink
mail_send override
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu.saison committed Sep 25, 2023
1 parent 6805049 commit c394040
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions mail_env_whitelist/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions mail_env_whitelist/__manifest__.py
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",
],
}
7 changes: 7 additions & 0 deletions mail_env_whitelist/data/ir_config_parameter_data.xml
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>
1 change: 1 addition & 0 deletions mail_env_whitelist/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ir_mail_server
25 changes: 25 additions & 0 deletions mail_env_whitelist/models/ir_mail_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.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(

Check warning on line 17 in mail_env_whitelist/models/ir_mail_server.py

View check run for this annotation

Codecov / codecov/patch

mail_env_whitelist/models/ir_mail_server.py#L17

Added line #L17 was not covered by tests
"mail_env_whitelist.test_env_email_to_whitelist"
)
for email in message["To"].split(";"):
email = re.search("<(.*)>", email).group(1)

Check warning on line 21 in mail_env_whitelist/models/ir_mail_server.py

View check run for this annotation

Codecov / codecov/patch

mail_env_whitelist/models/ir_mail_server.py#L21

Added line #L21 was not covered by tests
if email not in whitelist:
continue

Check warning on line 23 in mail_env_whitelist/models/ir_mail_server.py

View check run for this annotation

Codecov / codecov/patch

mail_env_whitelist/models/ir_mail_server.py#L23

Added line #L23 was not covered by tests
else:
super().send_email(message, *args, **kwargs)

Check warning on line 25 in mail_env_whitelist/models/ir_mail_server.py

View check run for this annotation

Codecov / codecov/patch

mail_env_whitelist/models/ir_mail_server.py#L25

Added line #L25 was not covered by tests
1 change: 1 addition & 0 deletions setup/mail_env_whitelist/odoo/addons/mail_env_whitelist
6 changes: 6 additions & 0 deletions setup/mail_env_whitelist/setup.py
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,
)

0 comments on commit c394040

Please sign in to comment.