diff options
| author | Jeremy Kersten <jke@odoo.com> | 2021-01-21 13:32:17 +0000 |
|---|---|---|
| committer | Jeremy Kersten <jke@odoo.com> | 2021-01-25 13:36:30 +0000 |
| commit | 62ee506a94b9fc4a6198c87cb8a2f186ed8bc6d3 (patch) | |
| tree | 74fcdeaada668e3ed1f9c44635ae15146800b00c /addons/website/models | |
| parent | 13364672745e66563646d47aaecac59460cbf89a (diff) | |
[FIX] website: handle RequestUID case in slug
Before this commit, a 308 on a route with a modelconverter for a model
that have a seo_name field will crash with an exception:
Cannot iterate on RequestUID
Another simplest solution was to use a with_user(SUPERUSER_ID) but in this case
it bypass the security set and display the name of the record even if not yet
published.
How to reproduce:
Create a 308 from /shop/<product> to /mag/<product>
Unpublish product 10
Try to access /shop/product-10
You have an unmanaged '500 internal error"
because slug_matching -> build -> to_url -> slug with a record with Requestuid
as env._uid.
Diffstat (limited to 'addons/website/models')
| -rw-r--r-- | addons/website/models/ir_http.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index b3482177b7c..a5b78da22ff 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -19,7 +19,6 @@ from odoo import registry, SUPERUSER_ID from odoo.http import request from odoo.tools.safe_eval import safe_eval from odoo.osv.expression import FALSE_DOMAIN - from odoo.addons.http_routing.models.ir_http import ModelConverter, _guess_mimetype from odoo.addons.portal.controllers.portal import _build_url_w_params @@ -75,7 +74,7 @@ class Http(models.AbstractModel): def _slug_matching(cls, adapter, endpoint, **kw): for arg in kw: if isinstance(kw[arg], models.BaseModel): - kw[arg] = kw[arg].sudo() + kw[arg] = kw[arg].with_context(slug_matching=True) qs = request.httprequest.query_string.decode('utf-8') try: return adapter.build(endpoint, kw) + (qs and '?%s' % qs or '') @@ -423,6 +422,11 @@ class Http(models.AbstractModel): class ModelConverter(ModelConverter): + def to_url(self, value): + if value.env.context.get('slug_matching'): + return value.env.context.get('_converter_value', str(value.id)) + return super().to_url(value) + def generate(self, uid, dom=None, args=None): Model = request.env[self.model].with_user(uid) # Allow to current_website_id directly in route domain |
