From 7d8a8ddea0b363732f2177ad589a3e0e10e2fb6c Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Thu, 21 Oct 2021 13:11:07 +0000 Subject: [PATCH] [IMP] website(_forum/_profile): remove _get_http_domain method Before Odoo saas-14.4, one should call `_get_http_domain()` on website to get its domain. Indeed, that method was in charge of cleaning that domain, as it was done with commit [1]. Since Odoo saas-14.4, that cleaning is automatically performed on domain before saving it into database, thanks to commit [2]. Thus, we can now remove the `_get_http_domain()` and use directly the domain as it is considered clean. Note that migrated databases coming from version older than Odoo saas-14.4 could still have an incorrect domain (trailing slash, no scheme..). This will be handled during migration with [3]. [1]: https://github.com/odoo/odoo/commit/3ad775aab717b395a5d11527aeb3596af66afa99 [2]: https://github.com/odoo/odoo/commit/042c95b0219bb0aa13e73385e092fa76ff1a1b0a [3]: https://github.com/odoo/upgrade/pull/2951 closes odoo/odoo#78766 Signed-off-by: Quentin Smetz (qsm) --- addons/website/controllers/backend.py | 3 +-- addons/website/controllers/main.py | 4 ++-- addons/website/models/ir_model.py | 6 +++--- addons/website/models/ir_ui_view.py | 4 ++-- addons/website/models/res_config_settings.py | 4 ++-- addons/website/models/website.py | 14 +------------- addons/website/views/website_navbar_templates.xml | 4 ++-- .../website_forum/views/website_forum_profile.xml | 2 +- addons/website_profile/views/website_profile.xml | 2 +- 9 files changed, 15 insertions(+), 28 deletions(-) diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py index 89355a74554..87f9a42eb9a 100644 --- a/addons/website/controllers/backend.py +++ b/addons/website/controllers/backend.py @@ -28,8 +28,7 @@ class WebsiteBackend(http.Controller): multi_website = request.env.user.has_group('website.group_multi_website') websites = multi_website and request.env['website'].search([]) or current_website dashboard_data['websites'] = websites.read(['id', 'name']) - for rec, website in zip(websites, dashboard_data['websites']): - website['domain'] = rec._get_http_domain() + for website in dashboard_data['websites']: if website['id'] == current_website.id: website['selected'] = True diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index d4aac43473d..ef193673f3c 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -108,10 +108,10 @@ class Website(Home): if not isredir and website.domain: domain_from = request.httprequest.environ.get('HTTP_HOST', '') - domain_to = werkzeug.urls.url_parse(website._get_http_domain()).netloc + domain_to = werkzeug.urls.url_parse(website.domain).netloc if domain_from != domain_to: # redirect to correct domain for a correct routing map - url_to = werkzeug.urls.url_join(website._get_http_domain(), '/website/force/%s?isredir=1&path=%s' % (website.id, path)) + url_to = werkzeug.urls.url_join(website.domain, '/website/force/%s?isredir=1&path=%s' % (website.id, path)) return request.redirect(url_to) website._force() return request.redirect(path) diff --git a/addons/website/models/ir_model.py b/addons/website/models/ir_model.py index 35eb225d8ff..67f7dd28685 100644 --- a/addons/website/models/ir_model.py +++ b/addons/website/models/ir_model.py @@ -27,11 +27,11 @@ class BaseModel(models.AbstractModel): if self._name == 'website': # Note that website_1.company_id.website_id might not be website_1 - return self._get_http_domain() or super().get_base_url() + return self.domain or super().get_base_url() if 'website_id' in self and self.website_id.domain: - return self.website_id._get_http_domain() + return self.website_id.domain if 'company_id' in self and self.company_id.website_id.domain: - return self.company_id.website_id._get_http_domain() + return self.company_id.website_id.domain return super().get_base_url() def get_website_meta(self): diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index 698bc82093c..bd107afd514 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -447,9 +447,9 @@ class View(models.Model): cur = Website.get_current_website() if self.env.user.has_group('website.group_website_publisher') and self.env.user.has_group('website.group_multi_website'): - qcontext['multi_website_websites_current'] = {'website_id': cur.id, 'name': cur.name, 'domain': cur._get_http_domain()} + qcontext['multi_website_websites_current'] = cur.name qcontext['multi_website_websites'] = [ - {'website_id': website.id, 'name': website.name, 'domain': website._get_http_domain()} + {'website_id': website.id, 'name': website.name, 'domain': website.domain} for website in Website.search([]) if website != cur ] diff --git a/addons/website/models/res_config_settings.py b/addons/website/models/res_config_settings.py index 9d621f483c5..e1048a4b1de 100644 --- a/addons/website/models/res_config_settings.py +++ b/addons/website/models/res_config_settings.py @@ -179,12 +179,12 @@ class ResConfigSettings(models.TransientModel): } def action_ping_sitemap(self): - if not self.website_id._get_http_domain(): + if not self.website_id.domain: raise UserError(_("You haven't defined your domain")) return { 'type': 'ir.actions.act_url', - 'url': 'http://www.google.com/ping?sitemap=%s/sitemap.xml' % self.website_id._get_http_domain(), + 'url': 'http://www.google.com/ping?sitemap=%s/sitemap.xml' % self.website_id.domain, 'target': 'new', } diff --git a/addons/website/models/website.py b/addons/website/models/website.py index e9984da40c8..7cda5b1afef 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -976,7 +976,7 @@ class Website(models.Model): is host:port in the version of `url_parse` we use.""" # Here we add http:// to the domain if it's not set because # `url_parse` expects it to be set to correctly return the `netloc`. - website_domain = urls.url_parse(website._get_http_domain()).netloc + website_domain = urls.url_parse(website.domain or '').netloc if ignore_port: website_domain = _remove_port(website_domain) domain_name = _remove_port(domain_name) @@ -1286,18 +1286,6 @@ class Website(models.Model): 'target': 'self', } - def _get_http_domain(self): - """Get the domain of the current website, prefixed by http if no - scheme is specified. - - Empty string if no domain is specified on the website. - """ - self.ensure_one() - if not self.domain: - return '' - res = urls.url_parse(self.domain) - return 'http://' + self.domain if not res.scheme else self.domain - def _get_canonical_url_localized(self, lang, canonical_params): """Returns the canonical URL for the current request with translatable elements appropriately translated in `lang`. diff --git a/addons/website/views/website_navbar_templates.xml b/addons/website/views/website_navbar_templates.xml index 4432ac7ab43..328fb7675e1 100644 --- a/addons/website/views/website_navbar_templates.xml +++ b/addons/website/views/website_navbar_templates.xml @@ -88,12 +88,12 @@ - +