From b61f95c9d9facedef1d8d6b89f8c89e3b22b69cd Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" <huvw@odoo.com> Date: Wed, 21 Dec 2022 10:35:23 +0000 Subject: [PATCH] [FIX] website{,_forum}: wrong forum post link when created from the website Steps to reproduce ================== - Website > Go to website - Forum > New post - Fill the form and post your question - Go to the backend - Website > Forum > Post - Click on the one you just created - Click on the link in the chatter -> It goes to an ir.ui.view model Cause of the issue ================== Since the form is posted from the frontend, the inherit_branding is automatically added to the context. This causes the data-oe-{model,view,id} to be added to the button. https://github.com/odoo/odoo/blob/46ce4345c96a58845bfa13dd1a86be391cf0a923/addons/website/models/ir_ui_view.py#L425-L426 Solution ======== - Set a context key `inherit_branding` to False inside `message_post_with_view`. - In `_render`, only set the key to True if it is not set. - Also do the same for `inherit_branding_auto` opw-3070490 closes odoo/odoo#108427 Signed-off-by: Hubert Van De Walle <huvw@odoo.com> --- addons/website/models/__init__.py | 1 + addons/website/models/ir_ui_view.py | 4 ++-- addons/website/models/mail_thread.py | 8 ++++++++ addons/website_forum/tests/test_forum.py | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 addons/website/models/mail_thread.py diff --git a/addons/website/models/__init__.py b/addons/website/models/__init__.py index f6bac4c2848f..cd6a5a9d1b88 100644 --- a/addons/website/models/__init__.py +++ b/addons/website/models/__init__.py @@ -11,6 +11,7 @@ from . import ir_model_data from . import ir_module_module from . import ir_qweb from . import ir_qweb_fields +from . import mail_thread from . import mixins from . import website from . import website_menu diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index c555b8a4dc1e..9ef82ce370d3 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -423,9 +423,9 @@ class View(models.Model): # in edit mode ir.ui.view will tag nodes if not translatable and not self.env.context.get('rendering_bundle'): if editable: - new_context = dict(self._context, inherit_branding=True) + new_context.setdefault("inherit_branding", True) elif request.env.user.has_group('website.group_website_publisher'): - new_context = dict(self._context, inherit_branding_auto=True) + new_context.setdefault("inherit_branding_auto", True) if values and 'main_object' in values: if request.env.user.has_group('website.group_website_publisher'): func = getattr(values['main_object'], 'get_backend_menu_id', False) diff --git a/addons/website/models/mail_thread.py b/addons/website/models/mail_thread.py new file mode 100644 index 000000000000..edfc17163f41 --- /dev/null +++ b/addons/website/models/mail_thread.py @@ -0,0 +1,8 @@ +from odoo import models + + +class MailThread(models.AbstractModel): + _inherit = 'mail.thread' + + def message_post_with_view(self, views_or_xmlid, **kwargs): + super(MailThread, self.with_context(inherit_branding=False)).message_post_with_view(views_or_xmlid, **kwargs) diff --git a/addons/website_forum/tests/test_forum.py b/addons/website_forum/tests/test_forum.py index 98f3781dd1a1..844459cf6e73 100644 --- a/addons/website_forum/tests/test_forum.py +++ b/addons/website_forum/tests/test_forum.py @@ -2,7 +2,10 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from .common import KARMA, TestForumCommon +from odoo import http +from odoo.addons.http_routing.models.ir_http import slug from odoo.exceptions import UserError, AccessError +from odoo.tests import HttpCase from odoo.tools import mute_logger from psycopg2 import IntegrityError @@ -458,3 +461,15 @@ class TestForum(TestForumCommon): self.assertEqual(len(food_tags), 2, "One Food tag should have been created in each forum.") self.assertIn(forum_1, food_tags.forum_id, "One Food tag should have been created for forum 1.") self.assertIn(forum_2, food_tags.forum_id, "One Food tag should have been created for forum 2.") + +class TestWebsiteForum(TestForumCommon, HttpCase): + + def test_forum_post_compose_message_without_branding(self): + self.authenticate("admin", "admin") + self.url_open(f"/forum/{slug(self.forum)}/new", { + "post_name": "test_branding", + "content": "<p>test</p>", + "csrf_token": http.WebRequest.csrf_token(self), + }) + post = self.env["forum.post"].search([('forum_id', '=', self.forum.id), ('name', '=', 'test_branding')]) + self.assertNotIn("data-oe-", post.message_ids.body) -- GitLab