[FIX] website: generate routing map without request

This fix allows generating the sitemap (via `website.search_pages`) via
RPC. The changes are necessary as since #99667 the `request` object is
no more available to RPC-executed functions.

See also: the `test_search` test case of `website.tests.test_page`.

closes odoo/odoo#104567

X-original-commit: 8f4e214417cfb1aed7e595b8d6ab71f33a347b29
Signed-off-by: Julien Castiaux <juc@odoo.com>
This commit is contained in:
Julien Castiaux
2022-10-29 04:51:02 +02:00
parent 1e57ad2076
commit 7d9f117505
4 changed files with 18 additions and 8 deletions
+6 -1
View File
@@ -64,7 +64,8 @@ class Http(models.AbstractModel):
@classmethod
def routing_map(cls, key=None):
key = key or (request and request.website_routing)
if not key and request:
key = request.website_routing
return super(Http, cls).routing_map(key=key)
@classmethod
@@ -82,6 +83,10 @@ class Http(models.AbstractModel):
@classmethod
def _generate_routing_rules(cls, modules, converters):
if not request:
yield from super()._generate_routing_rules(modules, converters)
return
website_id = request.website_routing
logger.debug("_generate_routing_rules for website: %s", website_id)
domain = [('redirect_type', 'in', ('308', '404')), '|', ('website_id', '=', False), ('website_id', '=', website_id)]
+1 -1
View File
@@ -1098,7 +1098,7 @@ class Website(models.Model):
of the same.
:rtype: list({name: str, url: str})
"""
router = http.root.get_db_router(request.db)
router = self.env['ir.http'].routing_map()
url_set = set()
sitemap_endpoint_done = set()
+4 -1
View File
@@ -11,6 +11,7 @@ import os
import re
import sys
import traceback
import threading
import werkzeug
import werkzeug.exceptions
@@ -21,6 +22,7 @@ import odoo
from odoo import api, http, models, tools, SUPERUSER_ID
from odoo.exceptions import AccessDenied, AccessError, MissingError
from odoo.http import request, Response, ROUTING_KEYS, Stream
from odoo.modules.registry import Registry
from odoo.service import security
from odoo.tools import consteq, submap
from odoo.tools.translate import code_translations
@@ -172,7 +174,8 @@ class IrHttp(models.AbstractModel):
if key not in cls._routing_map:
_logger.info("Generating routing map for key %s" % str(key))
installed = request.env.registry._init_modules.union(odoo.conf.server_wide_modules)
registry = Registry(threading.current_thread().dbname)
installed = registry._init_modules.union(odoo.conf.server_wide_modules)
if tools.config['test_enable'] and odoo.modules.module.current_test:
installed.add(odoo.modules.module.current_test)
mods = sorted(installed)
+7 -5
View File
@@ -85,12 +85,14 @@ class TestHttpMisc(TestHttpBase):
]
}})
res = self.nodb_url_open('/jsonrpc', data=payload, headers=CT_JSON)
res.raise_for_status()
for method in (self.db_url_open, self.nodb_url_open):
with self.subTest(method=method.__name__):
res = method('/jsonrpc', data=payload, headers=CT_JSON)
res.raise_for_status()
res_rpc = res.json()
self.assertNotIn('error', res_rpc.keys(), res_rpc.get('error', {}).get('data', {}).get('message'))
self.assertIn(milky_way.name, res_rpc['result'], "QWeb template was correctly rendered")
res_rpc = res.json()
self.assertNotIn('error', res_rpc.keys(), res_rpc.get('error', {}).get('data', {}).get('message'))
self.assertIn(milky_way.name, res_rpc['result'], "QWeb template was correctly rendered")
@tagged('post_install', '-at_install')