diff options
| author | Nasreddin (bon) <bon@odoo.com> | 2020-05-28 17:03:23 +0000 |
|---|---|---|
| committer | Nasreddin (bon) <bon@odoo.com> | 2020-05-29 15:23:09 +0000 |
| commit | 31b9c40124e4bdcae1d35afb27714e332787b6e9 (patch) | |
| tree | 5ded6f363aaafce39911e4cde9522fbede32671c /addons | |
| parent | fe250e609c74f0502bcb0e34a65e360d1bc6f65f (diff) | |
[FIX] website : Wrong 308 redirect
Issue
- Install "Website" app
- Go to Website->Configuration->Redirect
- Click on Create
- Set "Action" to 308
- Set "Url to" to nothing or any url
with no leading '/'
The DB is broken.
Error in 'werkzeug' python library.
Cause
Missing leading slash in url or empty url.
Solution
Add a counstraint to check if url is valid (not empty and
with a leading slash).
opw-2266935
closes odoo/odoo#52189
X-original-commit: fe1e76638132197ef4804d1261fb5b9e23d44159
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/website/i18n/website.pot | 12 | ||||
| -rw-r--r-- | addons/website/models/website_rewrite.py | 13 |
2 files changed, 23 insertions, 2 deletions
diff --git a/addons/website/i18n/website.pot b/addons/website/i18n/website.pot index d54d8787a7c..24c9ba52b49 100644 --- a/addons/website/i18n/website.pot +++ b/addons/website/i18n/website.pot @@ -25,6 +25,18 @@ msgid "" msgstr "" #. module: website +#: code:addons/website/models/website_rewrite.py:0 +#, python-format +msgid "\"URL to\" can not be empty." +msgstr "" + +#. module: website +#: code:addons/website/models/website_rewrite.py:0 +#, python-format +msgid "\"URL to\" must start with a leading slash." +msgstr "" + +#. module: website #: model:ir.model.fields,field_description:website.field_website_visitor__page_count msgid "# Visited Pages" msgstr "" diff --git a/addons/website/models/website_rewrite.py b/addons/website/models/website_rewrite.py index 5c3096cb5b3..1d4cc752396 100644 --- a/addons/website/models/website_rewrite.py +++ b/addons/website/models/website_rewrite.py @@ -1,5 +1,5 @@ -from odoo import models, fields, api -from odoo.exceptions import AccessDenied +from odoo import models, fields, api, _ +from odoo.exceptions import AccessDenied, ValidationError import logging _logger = logging.getLogger(__name__) @@ -73,6 +73,15 @@ class WebsiteRewrite(models.Model): self.url_from = self.route_id.path self.url_to = self.route_id.path + @api.constrains('url_to', 'redirect_type') + def _check_url_to(self): + for rewrite in self: + if rewrite.redirect_type == '308': + if not rewrite.url_to: + raise ValidationError(_('"URL to" can not be empty.')) + elif not rewrite.url_to.startswith('/'): + raise ValidationError(_('"URL to" must start with a leading slash.')) + def name_get(self): result = [] for rewrite in self: |
