Skip to content

Commit ce45622

Browse files
committed
[FIX] website_sale: product mail action redirect to shop page
Issue: Mail action redirects only to shop page, even though the user has internal access to the product page. To reproduce: 1- Create a db with website_sale installed. 2- Create a product and publish it. 3- In the product page chatter, send a message to an internal user 4- In received email, click on 'View Product' button 5- As you see the shop page opens This is reproduced after odoo#202555 Inside `_get_access_action`, if the product is published, we are returning `website_url`. We can add a check to do that only if user is portal or public. opw-5155281 closes odoo#233217 X-original-commit: c0f784f Signed-off-by: Valeriya Chuprina (vchu) <vchu@odoo.com> Signed-off-by: Mohammadmahdi Alijani (malj) <malj@odoo.com>
1 parent 620b857 commit ce45622

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

addons/website_sale/models/product_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ def _get_ribbon(self, price_vals=None, auto_assign_ribbons=None, variant=None):
10671067
def _get_access_action(self, access_uid=None, force_website=False):
10681068
""" Instead of the classic form view, redirect to website if it is published. """
10691069
self.ensure_one()
1070-
if force_website or self.website_published:
1070+
if force_website or (self.website_published and self.env.user.share):
10711071
return {
10721072
"type": "ir.actions.act_url",
10731073
"url": self.website_url,

addons/website_sale/tests/test_mail.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
import odoo
66
from odoo import SUPERUSER_ID, fields
7-
from odoo.tests import HttpCase, tagged
7+
from odoo.tests import tagged
88

99
from odoo.addons.mail.tests.common import MailCommon
10+
from odoo.addons.base.tests.common import HttpCaseWithUserPortal
1011
from odoo.addons.website_sale.tests.common import WebsiteSaleCommon
1112

1213

1314
@tagged('post_install', '-at_install', 'mail_thread')
14-
class TestWebsiteSaleMail(HttpCase):
15+
class TestWebsiteSaleMail(HttpCaseWithUserPortal):
1516

1617
def test_01_shop_mail_tour(self):
1718
"""The goal of this test is to make sure sending SO by email works."""
@@ -52,6 +53,33 @@ def test_01_shop_mail_tour(self):
5253
self.assertIn('Your', new_mail.body_html)
5354
self.assertIn('order', new_mail.body_html)
5455

56+
def test_shop_product_mail_action_redirection(self):
57+
product_template = self.env['product.template'].create({
58+
'name': "test product template",
59+
'sale_ok': True,
60+
'website_published': True,
61+
})
62+
url = f'/mail/view?model=product.template&res_id={product_template.id}'
63+
shop_url = f'/shop/test-product-template-{product_template.id}'
64+
65+
with self.subTest(user='admin'):
66+
self.authenticate('admin', 'admin')
67+
res = self.url_open(url)
68+
self.assertEqual(res.status_code, 200)
69+
self.assertTrue(res.request.path_url.startswith('/odoo/product.template'))
70+
71+
with self.subTest(user='portal'):
72+
self.authenticate('portal', 'portal')
73+
res = self.url_open(url)
74+
self.assertEqual(res.status_code, 200)
75+
self.assertEqual(res.request.path_url, shop_url)
76+
77+
with self.subTest(user=None):
78+
self.authenticate(None, None)
79+
res = self.url_open(url)
80+
self.assertEqual(res.status_code, 200)
81+
self.assertEqual(res.request.path_url, shop_url)
82+
5583

5684
@tagged('post_install', '-at_install', 'mail_thread')
5785
class TestWebsiteSaleMails(MailCommon, WebsiteSaleCommon):

0 commit comments

Comments
 (0)