From c42a16726306de3df93f938fda4b1781203f4466 Mon Sep 17 00:00:00 2001 From: Nils Hamerlinck Date: Thu, 26 Jul 2018 22:56:55 +0700 Subject: [PATCH] [FIX] dbfilter_from_header: prevent autoloading --- dbfilter_from_header/README.rst | 9 ++++++--- dbfilter_from_header/__init__.py | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dbfilter_from_header/README.rst b/dbfilter_from_header/README.rst index 5107a5b2c..73c8f9c62 100644 --- a/dbfilter_from_header/README.rst +++ b/dbfilter_from_header/README.rst @@ -16,10 +16,10 @@ 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 ``load`` parameter in ``/etc/odoo.conf`` or with the -``--load`` command-line parameter +This can be done with the ``server_wide_modules`` parameter in ``/etc/odoo.conf`` +or with the ``--load`` command-line parameter -``load = "web, web_kanban, dbfilter_from_header"`` +``server_wide_modules = "web, web_kanban, dbfilter_from_header"`` Configuration ============= @@ -39,6 +39,9 @@ applied before looking at the regular expression in the header. ``RequestHeader set X-Odoo-dbfilter [your filter regex]`` +And make sure that proxy mode is enabled in Odoo's configuration file: + +``proxy_mode = True`` Bug Tracker =========== diff --git a/dbfilter_from_header/__init__.py b/dbfilter_from_header/__init__.py index 4d7ba003e..6b4160fba 100644 --- a/dbfilter_from_header/__init__.py +++ b/dbfilter_from_header/__init__.py @@ -3,8 +3,10 @@ # © 2014 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import logging import re from odoo import http +from odoo.tools import config db_filter_org = http.db_filter @@ -17,4 +19,8 @@ def db_filter(dbs, httprequest=None): dbs = [db for db in dbs if re.match(db_filter_hdr, db)] return dbs -http.db_filter = db_filter +if config.get('proxy_mode') and \ + 'dbfilter_from_header' in config.get('server_wide_modules'): + _logger = logging.getLogger(__name__) + _logger.info('monkey patching http.db_filter') + http.db_filter = db_filter