From 5d1e9bfbad795328738d0aefe7aefd91b516aa33 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 20 Sep 2023 18:56:19 +0200 Subject: [PATCH] [FIX] website, *: add website_id in seo save rpc context *: website_event Without this, the seo saving would not forward the current website in the context. It's especially bad in this case as it's writing on views which are not triggering the COW due to the lack of a website_id in the context. Step to reproduce: - Go to /shop (if you didn't do anything, this will be bound to the `website_sale.products` view which has no website_id set and is called a generic view) - Open "Optimize SEO" dialog and type something in the title - Save - It saved the change on the mentioned view, without duplicating it (COW) before writing on it. The title you added is now applied to every websites and not only the one you edited, which is against the website holy grail rule: only the website you edit should be changed. Technically, this is because we refactored that part of the code in Odoo 16: the website is now editable in the backend. Note that this fix also revealed that a test for events (which has been introduced with [1]) was relying on the bug: it tested the meta title of a view that should (and will after this fix) have been COW'ed. This test will now indirectly protects this bug from re-happening, although we might want to write a dedicated test in the future as the behavior for events might need some refactoring. [1]: https://github.com/odoo/odoo/commit/2072a7739eb9a9ee87c8b3c7b0d43a82a7e2375f opw-3499285 closes odoo/odoo#136550 X-original-commit: c45c0bf8fff7285a9fff33ff9bf1c24bbfb130e7 Signed-off-by: Quentin Smetz (qsm) Co-authored-by: qsm-odoo --- addons/website/static/src/components/dialog/seo.js | 5 ++++- addons/website_event/tests/test_website_event.py | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/website/static/src/components/dialog/seo.js b/addons/website/static/src/components/dialog/seo.js index 50868352a07..21a7e4bd617 100644 --- a/addons/website/static/src/components/dialog/seo.js +++ b/addons/website/static/src/components/dialog/seo.js @@ -458,7 +458,10 @@ export class OptimizeSEODialog extends Component { } data.website_meta_og_img = seoContext.metaImage; await this.orm.write(this.object.model, [this.object.id], data, { - context: {lang: this.website.currentWebsite.metadata.lang}, + context: { + lang: this.website.currentWebsite.metadata.lang, + 'website_id': this.website.currentWebsite.id, + }, }); this.website.goToWebsite({path: this.url.replace(this.previousSeoName || this.seoNameDefault, seoContext.seoName)}); } diff --git a/addons/website_event/tests/test_website_event.py b/addons/website_event/tests/test_website_event.py index 8a615845c72..67011045e11 100644 --- a/addons/website_event/tests/test_website_event.py +++ b/addons/website_event/tests/test_website_event.py @@ -21,14 +21,18 @@ class TestUi(HttpCaseWithUserDemo): self.start_tour(self.env['website'].get_client_action_url('/'), 'website_event_tour', login='admin', step_delay=100) def test_website_event_pages_seo(self): + website = self.env['website'].get_current_website() event = self.env['event.event'].create({ 'name': 'Event With Menu', 'website_menu': True, + 'website_id': website.id, }) intro_event_menu = event.introduction_menu_ids url = intro_event_menu.menu_id._clean_url() self.start_tour(self.env['website'].get_client_action_url(url), 'website_event_pages_seo', login='admin') - self.assertEqual(intro_event_menu.view_id.website_meta_title, "Hello, world!") + view_key = intro_event_menu.view_id.key + specific_view = website.with_context(website_id=website.id).viewref(view_key) + self.assertEqual(specific_view.website_meta_title, "Hello, world!") self.assertEqual(event.website_meta_title, False) def test_website_event_questions(self):