diff --git a/iap_mail_domain_blacklist/README.rst b/iap_mail_domain_blacklist/README.rst new file mode 100644 index 0000000000..5e9a504665 --- /dev/null +++ b/iap_mail_domain_blacklist/README.rst @@ -0,0 +1,115 @@ +========================= +IAP Mail Domain BlackList +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:32efbaf237a882dc1ba36f3ba442a685dccaa511868f26c2e5662a3332a47d7f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/15.0/iap_mail_domain_blacklist + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-15-0/social-15-0-iap_mail_domain_blacklist + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows adding domains to the mail domain blacklist to prevent Odoo from assuming +that users with the same domain belong to the same organization. + +Blacklisted domains are shared across all effective databases on the server. +When the db_name parameter is set, the effective databases are assumed to be the +values of that parameter. If db_name is not set and list_db is true, all +databases on the instance are considered effective databases. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +Odoo can't add certain domains to the _MAIL_DOMAIN_BLACKLIST, which can result in incorrectly +assuming that users with one of these specific domains belong to the same organization. + +For example, since outlook.jp is not part of _MAIL_DOMAIN_BLACKLIST, when partners have this +same domain and create helpdesk tickets, they may end up sharing partners and mistakenly +assuming ownership of each other's tickets. + +Configuration +============= + +1. Go to Settings > General Settings. +2. Search for "Mail Domain Blacklist" and enter the domains you want to blacklist, separated + by commas. + +Note: Every time you update the "Mail Domain Blacklist," you need to restart the Odoo server +for the change to take effect. + +Known issues / Roadmap +====================== + +Due to a technical limitation, http.db_list() cannot be used during module +loading to respect dbfilter, because the HTTP layer is not initialized at +that stage. As a result, the module must rely on config.get('db_name') or +db.list_dbs() instead. Consequently, if list_db = True is enabled without +explicitly setting db_name in odoo.conf, blacklist domains from inactive +databases may incorrectly affect active databases. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Quartile + +Contributors +~~~~~~~~~~~~ + +* `Quartile `_ + + * Aung Ko Ko Lin + * Yoshi Tashiro + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/iap_mail_domain_blacklist/__init__.py b/iap_mail_domain_blacklist/__init__.py new file mode 100644 index 0000000000..5bf67492bc --- /dev/null +++ b/iap_mail_domain_blacklist/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_load_hook diff --git a/iap_mail_domain_blacklist/__manifest__.py b/iap_mail_domain_blacklist/__manifest__.py new file mode 100644 index 0000000000..2d4761de6c --- /dev/null +++ b/iap_mail_domain_blacklist/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2025 Quartile +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "IAP Mail Domain BlackList", + "version": "15.0.1.0.0", + "author": "Quartile, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/social", + "license": "AGPL-3", + "depends": ["iap"], + "data": [ + "data/config_parameter.xml", + "views/res_config_settings_views.xml", + ], + "post_load": "post_load_hook", + "installable": True, +} diff --git a/iap_mail_domain_blacklist/data/config_parameter.xml b/iap_mail_domain_blacklist/data/config_parameter.xml new file mode 100644 index 0000000000..d63ce02dc6 --- /dev/null +++ b/iap_mail_domain_blacklist/data/config_parameter.xml @@ -0,0 +1,7 @@ + + + + iap_mail_domain_blacklist.mail_domain_blacklist + replace_this_with_real_domains + + diff --git a/iap_mail_domain_blacklist/hooks.py b/iap_mail_domain_blacklist/hooks.py new file mode 100644 index 0000000000..c3bb34a721 --- /dev/null +++ b/iap_mail_domain_blacklist/hooks.py @@ -0,0 +1,53 @@ +# Copyright 2025 Quartile +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging + +from odoo.exceptions import AccessDenied +from odoo.service import db +from odoo.sql_db import db_connect +from odoo.tools import config + +from odoo.addons.iap.tools import iap_tools + +_logger = logging.getLogger(__name__) + + +def update_mail_domain_blacklist(cr): + cr.execute( + """ + SELECT EXISTS ( + SELECT 1 FROM information_schema.tables + WHERE table_name = 'ir_config_parameter' + ) + """ + ) + table_exists = cr.fetchone()[0] + if not table_exists: + return + cr.execute( + "SELECT value FROM ir_config_parameter WHERE key = %s", + ("iap_mail_domain_blacklist.mail_domain_blacklist",), + ) + param_value = cr.fetchone() + if param_value and param_value[0]: + additional_domains = {domain.strip() for domain in param_value[0].split(",")} + iap_tools._MAIL_DOMAIN_BLACKLIST.update(additional_domains) + + +def _db_names(): + if config.get("db_name"): + return [n.strip() for n in config["db_name"].split(",") if n.strip()] + try: + return db.list_dbs() + except AccessDenied: + return [] + + +def post_load_hook(): + for db_name in _db_names(): + try: + with db_connect(db_name).cursor() as cr: + update_mail_domain_blacklist(cr) + except Exception: + _logger.error(f"Skipping database {db_name} due to an issue connecting.") diff --git a/iap_mail_domain_blacklist/models/__init__.py b/iap_mail_domain_blacklist/models/__init__.py new file mode 100644 index 0000000000..0deb68c468 --- /dev/null +++ b/iap_mail_domain_blacklist/models/__init__.py @@ -0,0 +1 @@ +from . import res_config_settings diff --git a/iap_mail_domain_blacklist/models/res_config_settings.py b/iap_mail_domain_blacklist/models/res_config_settings.py new file mode 100644 index 0000000000..d64b4ff808 --- /dev/null +++ b/iap_mail_domain_blacklist/models/res_config_settings.py @@ -0,0 +1,12 @@ +# Copyright 2025 Quartile +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + mail_domain_blacklist = fields.Char( + config_parameter="iap_mail_domain_blacklist.mail_domain_blacklist" + ) diff --git a/iap_mail_domain_blacklist/readme/CONFIGURE.rst b/iap_mail_domain_blacklist/readme/CONFIGURE.rst new file mode 100644 index 0000000000..4816137467 --- /dev/null +++ b/iap_mail_domain_blacklist/readme/CONFIGURE.rst @@ -0,0 +1,6 @@ +1. Go to Settings > General Settings. +2. Search for "Mail Domain Blacklist" and enter the domains you want to blacklist, separated + by commas. + +Note: Every time you update the "Mail Domain Blacklist," you need to restart the Odoo server +for the change to take effect. diff --git a/iap_mail_domain_blacklist/readme/CONTEXT.rst b/iap_mail_domain_blacklist/readme/CONTEXT.rst new file mode 100644 index 0000000000..d371a2812d --- /dev/null +++ b/iap_mail_domain_blacklist/readme/CONTEXT.rst @@ -0,0 +1,6 @@ +Odoo can't add certain domains to the _MAIL_DOMAIN_BLACKLIST, which can result in incorrectly +assuming that users with one of these specific domains belong to the same organization. + +For example, since outlook.jp is not part of _MAIL_DOMAIN_BLACKLIST, when partners have this +same domain and create helpdesk tickets, they may end up sharing partners and mistakenly +assuming ownership of each other's tickets. diff --git a/iap_mail_domain_blacklist/readme/CONTRIBUTORS.rst b/iap_mail_domain_blacklist/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..0f2857ade0 --- /dev/null +++ b/iap_mail_domain_blacklist/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Quartile `_ + + * Aung Ko Ko Lin + * Yoshi Tashiro diff --git a/iap_mail_domain_blacklist/readme/DESCRIPTION.rst b/iap_mail_domain_blacklist/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..98df39cda2 --- /dev/null +++ b/iap_mail_domain_blacklist/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +This module allows adding domains to the mail domain blacklist to prevent Odoo from assuming +that users with the same domain belong to the same organization. + +Blacklisted domains are shared across all effective databases on the server. +When the db_name parameter is set, the effective databases are assumed to be the +values of that parameter. If db_name is not set and list_db is true, all +databases on the instance are considered effective databases. diff --git a/iap_mail_domain_blacklist/readme/ROADMAP.rst b/iap_mail_domain_blacklist/readme/ROADMAP.rst new file mode 100644 index 0000000000..4d8b650a5b --- /dev/null +++ b/iap_mail_domain_blacklist/readme/ROADMAP.rst @@ -0,0 +1,6 @@ +Due to a technical limitation, http.db_list() cannot be used during module +loading to respect dbfilter, because the HTTP layer is not initialized at +that stage. As a result, the module must rely on config.get('db_name') or +db.list_dbs() instead. Consequently, if list_db = True is enabled without +explicitly setting db_name in odoo.conf, blacklist domains from inactive +databases may incorrectly affect active databases. diff --git a/iap_mail_domain_blacklist/static/description/index.html b/iap_mail_domain_blacklist/static/description/index.html new file mode 100644 index 0000000000..ae159ee206 --- /dev/null +++ b/iap_mail_domain_blacklist/static/description/index.html @@ -0,0 +1,462 @@ + + + + + +IAP Mail Domain BlackList + + + +
+

IAP Mail Domain BlackList

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

This module allows adding domains to the mail domain blacklist to prevent Odoo from assuming +that users with the same domain belong to the same organization.

+

Blacklisted domains are shared across all effective databases on the server. +When the db_name parameter is set, the effective databases are assumed to be the +values of that parameter. If db_name is not set and list_db is true, all +databases on the instance are considered effective databases.

+

Table of contents

+ +
+

Use Cases / Context

+

Odoo can’t add certain domains to the _MAIL_DOMAIN_BLACKLIST, which can result in incorrectly +assuming that users with one of these specific domains belong to the same organization.

+

For example, since outlook.jp is not part of _MAIL_DOMAIN_BLACKLIST, when partners have this +same domain and create helpdesk tickets, they may end up sharing partners and mistakenly +assuming ownership of each other’s tickets.

+
+
+

Configuration

+
    +
  1. Go to Settings > General Settings.
  2. +
  3. Search for “Mail Domain Blacklist” and enter the domains you want to blacklist, separated +by commas.
  4. +
+

Note: Every time you update the “Mail Domain Blacklist,” you need to restart the Odoo server +for the change to take effect.

+
+
+

Known issues / Roadmap

+

Due to a technical limitation, http.db_list() cannot be used during module +loading to respect dbfilter, because the HTTP layer is not initialized at +that stage. As a result, the module must rely on config.get(‘db_name’) or +db.list_dbs() instead. Consequently, if list_db = True is enabled without +explicitly setting db_name in odoo.conf, blacklist domains from inactive +databases may incorrectly affect active databases.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile
  • +
+
+
+

Contributors

+
    +
  • Quartile
      +
    • Aung Ko Ko Lin
    • +
    • Yoshi Tashiro
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/iap_mail_domain_blacklist/tests/__init__.py b/iap_mail_domain_blacklist/tests/__init__.py new file mode 100644 index 0000000000..49f3e9291d --- /dev/null +++ b/iap_mail_domain_blacklist/tests/__init__.py @@ -0,0 +1 @@ +from . import test_iap_mail_domain_blacklist diff --git a/iap_mail_domain_blacklist/tests/test_iap_mail_domain_blacklist.py b/iap_mail_domain_blacklist/tests/test_iap_mail_domain_blacklist.py new file mode 100644 index 0000000000..7c3bc8ed09 --- /dev/null +++ b/iap_mail_domain_blacklist/tests/test_iap_mail_domain_blacklist.py @@ -0,0 +1,35 @@ +# Copyright 2025 Quartile +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import TransactionCase + +from odoo.addons.iap.tools import iap_tools + +from ..hooks import update_mail_domain_blacklist + + +class TestMailDomainBlacklist(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.config_param = cls.env["ir.config_parameter"] + cls.predefined_domains = {"outlook.jp", "test.jp"} + cls.original_blacklist = iap_tools._MAIL_DOMAIN_BLACKLIST.copy() + + @classmethod + def tearDownClass(cls): + iap_tools._MAIL_DOMAIN_BLACKLIST.clear() + iap_tools._MAIL_DOMAIN_BLACKLIST.update(cls.original_blacklist) + super().tearDownClass() + + def test_domains_blacklist(self): + for domain in self.predefined_domains: + self.assertNotIn(domain, iap_tools._MAIL_DOMAIN_BLACKLIST) + self.config_param.set_param( + "iap_mail_domain_blacklist.mail_domain_blacklist", + ",".join(self.predefined_domains), + ) + with self.env.cr.savepoint(): + update_mail_domain_blacklist(self.env.cr) + for domain in self.predefined_domains: + self.assertIn(domain, iap_tools._MAIL_DOMAIN_BLACKLIST) diff --git a/iap_mail_domain_blacklist/views/res_config_settings_views.xml b/iap_mail_domain_blacklist/views/res_config_settings_views.xml new file mode 100644 index 0000000000..3f5273c8db --- /dev/null +++ b/iap_mail_domain_blacklist/views/res_config_settings_views.xml @@ -0,0 +1,29 @@ + + + + res.config.settings.view.form.inherit + res.config.settings + + + +
+
+
+ + +
+ Enter domains to blacklist, separated by commas +
+
+
+
+
+
+
+
diff --git a/setup/iap_mail_domain_blacklist/odoo/addons/iap_mail_domain_blacklist b/setup/iap_mail_domain_blacklist/odoo/addons/iap_mail_domain_blacklist new file mode 120000 index 0000000000..09af758e72 --- /dev/null +++ b/setup/iap_mail_domain_blacklist/odoo/addons/iap_mail_domain_blacklist @@ -0,0 +1 @@ +../../../../iap_mail_domain_blacklist \ No newline at end of file diff --git a/setup/iap_mail_domain_blacklist/setup.py b/setup/iap_mail_domain_blacklist/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/iap_mail_domain_blacklist/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)