Skip to content

Commit 0b9d6a4

Browse files
[ADD] iap_mail_domain_blacklist
1 parent 4ad2262 commit 0b9d6a4

18 files changed

Lines changed: 770 additions & 0 deletions

File tree

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
=========================
2+
IAP Mail Domain BlackList
3+
=========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:32efbaf237a882dc1ba36f3ba442a685dccaa511868f26c2e5662a3332a47d7f
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
20+
:target: https://github.com/OCA/social/tree/15.0/iap_mail_domain_blacklist
21+
:alt: OCA/social
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/social-15-0/social-15-0-iap_mail_domain_blacklist
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=15.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows adding domains to the mail domain blacklist to prevent Odoo from assuming
32+
that users with the same domain belong to the same organization.
33+
34+
Blacklisted domains are shared across all effective databases on the server.
35+
When the db_name parameter is set, the effective databases are assumed to be the
36+
values of that parameter. If db_name is not set and list_db is true, all
37+
databases on the instance are considered effective databases.
38+
39+
**Table of contents**
40+
41+
.. contents::
42+
:local:
43+
44+
Use Cases / Context
45+
===================
46+
47+
Odoo can't add certain domains to the _MAIL_DOMAIN_BLACKLIST, which can result in incorrectly
48+
assuming that users with one of these specific domains belong to the same organization.
49+
50+
For example, since outlook.jp is not part of _MAIL_DOMAIN_BLACKLIST, when partners have this
51+
same domain and create helpdesk tickets, they may end up sharing partners and mistakenly
52+
assuming ownership of each other's tickets.
53+
54+
Configuration
55+
=============
56+
57+
1. Go to Settings > General Settings.
58+
2. Search for "Mail Domain Blacklist" and enter the domains you want to blacklist, separated
59+
by commas.
60+
61+
Note: Every time you update the "Mail Domain Blacklist," you need to restart the Odoo server
62+
for the change to take effect.
63+
64+
Known issues / Roadmap
65+
======================
66+
67+
Due to a technical limitation, http.db_list() cannot be used during module
68+
loading to respect dbfilter, because the HTTP layer is not initialized at
69+
that stage. As a result, the module must rely on config.get('db_name') or
70+
db.list_dbs() instead. Consequently, if list_db = True is enabled without
71+
explicitly setting db_name in odoo.conf, blacklist domains from inactive
72+
databases may incorrectly affect active databases.
73+
74+
Bug Tracker
75+
===========
76+
77+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
78+
In case of trouble, please check there if your issue has already been reported.
79+
If you spotted it first, help us to smash it by providing a detailed and welcomed
80+
`feedback <https://github.com/OCA/social/issues/new?body=module:%20iap_mail_domain_blacklist%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
81+
82+
Do not contact contributors directly about support or help with technical issues.
83+
84+
Credits
85+
=======
86+
87+
Authors
88+
~~~~~~~
89+
90+
* Quartile
91+
92+
Contributors
93+
~~~~~~~~~~~~
94+
95+
* `Quartile <https://www.quartile.co>`_
96+
97+
* Aung Ko Ko Lin
98+
* Yoshi Tashiro
99+
100+
Maintainers
101+
~~~~~~~~~~~
102+
103+
This module is maintained by the OCA.
104+
105+
.. image:: https://odoo-community.org/logo.png
106+
:alt: Odoo Community Association
107+
:target: https://odoo-community.org
108+
109+
OCA, or the Odoo Community Association, is a nonprofit organization whose
110+
mission is to support the collaborative development of Odoo features and
111+
promote its widespread use.
112+
113+
This module is part of the `OCA/social <https://github.com/OCA/social/tree/15.0/iap_mail_domain_blacklist>`_ project on GitHub.
114+
115+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from .hooks import post_load_hook
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2025 Quartile
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
{
5+
"name": "IAP Mail Domain BlackList",
6+
"version": "15.0.1.0.0",
7+
"author": "Quartile, Odoo Community Association (OCA)",
8+
"website": "https://github.com/OCA/social",
9+
"license": "AGPL-3",
10+
"depends": ["iap"],
11+
"data": [
12+
"data/config_parameter.xml",
13+
"views/res_config_settings_views.xml",
14+
],
15+
"post_load": "post_load_hook",
16+
"installable": True,
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo noupdate="1">
3+
<record id="param_iap_mail_domain_blacklist" model="ir.config_parameter">
4+
<field name="key">iap_mail_domain_blacklist.mail_domain_blacklist</field>
5+
<field name="value">replace_this_with_real_domains</field>
6+
</record>
7+
</odoo>

iap_mail_domain_blacklist/hooks.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2025 Quartile
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
import logging
5+
6+
from odoo.exceptions import AccessDenied
7+
from odoo.service import db
8+
from odoo.sql_db import db_connect
9+
from odoo.tools import config
10+
11+
from odoo.addons.iap.tools import iap_tools
12+
13+
_logger = logging.getLogger(__name__)
14+
15+
16+
def update_mail_domain_blacklist(cr):
17+
cr.execute(
18+
"""
19+
SELECT EXISTS (
20+
SELECT 1 FROM information_schema.tables
21+
WHERE table_name = 'ir_config_parameter'
22+
)
23+
"""
24+
)
25+
table_exists = cr.fetchone()[0]
26+
if not table_exists:
27+
return
28+
cr.execute(
29+
"SELECT value FROM ir_config_parameter WHERE key = %s",
30+
("iap_mail_domain_blacklist.mail_domain_blacklist",),
31+
)
32+
param_value = cr.fetchone()
33+
if param_value and param_value[0]:
34+
additional_domains = {domain.strip() for domain in param_value[0].split(",")}
35+
iap_tools._MAIL_DOMAIN_BLACKLIST.update(additional_domains)
36+
37+
38+
def _db_names():
39+
if config.get("db_name"):
40+
return [n.strip() for n in config["db_name"].split(",") if n.strip()]
41+
try:
42+
return db.list_dbs()
43+
except AccessDenied:
44+
return []
45+
46+
47+
def post_load_hook():
48+
for db_name in _db_names():
49+
try:
50+
with db_connect(db_name).cursor() as cr:
51+
update_mail_domain_blacklist(cr)
52+
except Exception:
53+
_logger.error(f"Skipping database {db_name} due to an issue connecting.")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import res_config_settings
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2025 Quartile
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
mail_domain_blacklist = fields.Char(
11+
config_parameter="iap_mail_domain_blacklist.mail_domain_blacklist"
12+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1. Go to Settings > General Settings.
2+
2. Search for "Mail Domain Blacklist" and enter the domains you want to blacklist, separated
3+
by commas.
4+
5+
Note: Every time you update the "Mail Domain Blacklist," you need to restart the Odoo server
6+
for the change to take effect.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Odoo can't add certain domains to the _MAIL_DOMAIN_BLACKLIST, which can result in incorrectly
2+
assuming that users with one of these specific domains belong to the same organization.
3+
4+
For example, since outlook.jp is not part of _MAIL_DOMAIN_BLACKLIST, when partners have this
5+
same domain and create helpdesk tickets, they may end up sharing partners and mistakenly
6+
assuming ownership of each other's tickets.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* `Quartile <https://www.quartile.co>`_
2+
3+
* Aung Ko Ko Lin
4+
* Yoshi Tashiro

0 commit comments

Comments
 (0)