diff --git a/dbfilter_from_header/README.rst b/dbfilter_from_header/README.rst index 63bb62189d6..b21a8af68cb 100644 --- a/dbfilter_from_header/README.rst +++ b/dbfilter_from_header/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + ==================== dbfilter_from_header ==================== @@ -13,7 +17,7 @@ dbfilter_from_header .. |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 +.. |badge2| image:: https://img.shields.io/badge/license-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%2Fserver--tools-lightgray.png?logo=github @@ -122,6 +126,14 @@ 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. +.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px + :target: https://github.com/hbrunn + :alt: hbrunn + +Current `maintainer `__: + +|maintainer-hbrunn| + This module is part of the `OCA/server-tools `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/dbfilter_from_header/__manifest__.py b/dbfilter_from_header/__manifest__.py index db1321a9388..c35d1ad7225 100644 --- a/dbfilter_from_header/__manifest__.py +++ b/dbfilter_from_header/__manifest__.py @@ -12,6 +12,7 @@ "license": "AGPL-3", "category": "Tools", "depends": ["web"], + "maintainers": ["hbrunn"], "auto_install": False, "installable": True, } diff --git a/dbfilter_from_header/override.py b/dbfilter_from_header/override.py index 43294d8180b..f759575b169 100644 --- a/dbfilter_from_header/override.py +++ b/dbfilter_from_header/override.py @@ -13,13 +13,11 @@ def db_filter(dbs, host=None): - dbs_orig = db_filter_org(dbs, host) + dbs = db_filter_org(dbs, host) httprequest = http.request.httprequest db_filter_hdr = httprequest.environ.get("HTTP_X_ODOO_DBFILTER") if db_filter_hdr: dbs = [db for db in dbs if re.match(db_filter_hdr, db)] - else: - dbs = dbs_orig return dbs diff --git a/dbfilter_from_header/static/description/index.html b/dbfilter_from_header/static/description/index.html index 2a2f039a2bf..6080e1cbb9f 100644 --- a/dbfilter_from_header/static/description/index.html +++ b/dbfilter_from_header/static/description/index.html @@ -3,15 +3,16 @@ -dbfilter_from_header +README.rst -
-

dbfilter_from_header

+
+ + +Odoo Community Association + +
+

dbfilter_from_header

-

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

+

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

This addon lets you pass a dbfilter as a HTTP header.

This is interesting for setups where database names can’t be mapped to proxied host names.

Table of contents

@@ -387,7 +393,7 @@

dbfilter_from_header

-

Installation

+

Installation

To install this module, you only need to add it to your addons, and load it as a server-wide module.

This can be done with the server_wide_modules parameter in /etc/odoo.conf @@ -395,7 +401,7 @@

Installation

server_wide_modules = base,web,dbfilter_from_header

-

Configuration

+

Configuration

Please keep in mind that the standard odoo dbfilter configuration is still applied before looking at the regular expression in the header.

-

Usage

+

Usage

To use this module, you need to complete installation and configuration parts.

-

Bug Tracker

+

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 @@ -426,15 +432,15 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Therp BV
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +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.

+

Current maintainer:

+

hbrunn

This module is part of the OCA/server-tools project on GitHub.

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

+
diff --git a/dbfilter_from_header/tests/__init__.py b/dbfilter_from_header/tests/__init__.py new file mode 100644 index 00000000000..4fbe3d58e9f --- /dev/null +++ b/dbfilter_from_header/tests/__init__.py @@ -0,0 +1 @@ +from . import test_dbfilter_from_header diff --git a/dbfilter_from_header/tests/test_dbfilter_from_header.py b/dbfilter_from_header/tests/test_dbfilter_from_header.py new file mode 100644 index 00000000000..289f042466c --- /dev/null +++ b/dbfilter_from_header/tests/test_dbfilter_from_header.py @@ -0,0 +1,58 @@ +import importlib + +from odoo import http +from odoo.tests.common import TransactionCase +from odoo.tools import config + +from odoo.addons.website.tools import MockRequest + +from .. import override + + +class TestDbfilterFromHeader(TransactionCase): + def setUp(self): + super().setUp() + self.config_org = {} + for key in ("proxy_mode", "server_wide_modules", "dbfilter", "db_name"): + self.config_org[key] = config[key] + self.db_filter_org = http.db_filter + config["dbfilter"] = "^db1|db2$" + config["proxy_mode"] = True + config["server_wide_modules"] = "dbfilter_from_header" + importlib.reload(override) + + def test_dbfilter_with_header(self): + """ + Test that with a dbfilter set in config, it restricts what is selectable + via the header + """ + with MockRequest(self.env) as mock_request: + mock_request.httprequest.environ["HTTP_X_ODOO_DBFILTER"] = "^db2|db3$" + filtered_dbs = http.db_filter(["db1", "db2", "db3"]) + self.assertEqual(filtered_dbs, ["db2"]) + + def test_dbfilter_without_header(self): + """ + Test that with a dbfilter set in config and no header added, standard behavior + is applied + """ + with MockRequest(self.env): + filtered_dbs = http.db_filter(["db1", "db2", "db3"]) + self.assertEqual(filtered_dbs, ["db1", "db2"]) + + def test_no_dbfilter_with_header(self): + """ + Test that with no dbfilter set in config, filter from header is unrestricted + """ + config["dbfilter"] = "" + config["db_name"] = "" + with MockRequest(self.env) as mock_request: + mock_request.httprequest.environ["HTTP_X_ODOO_DBFILTER"] = "^db2|db3$" + filtered_dbs = http.db_filter(["db1", "db2", "db3"]) + self.assertEqual(filtered_dbs, ["db2", "db3"]) + + def tearDown(self): + super().tearDown() + for key, value in self.config_org.items(): + config[key] = value + http.db_filter = self.db_filter_org