Skip to content
Snippets Groups Projects
Commit b61f95c9 authored by Hubert Van de Walle (huvw)'s avatar Hubert Van de Walle (huvw)
Browse files

[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: default avatarHubert Van De Walle <huvw@odoo.com>
parent 3ec5454e
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......
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)
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment