mirror of https://github.com/OCA/social.git
[FIX] mail_post_defer: recover "view $model" button
Fixes a regression in https://github.com/OCA/social/pull/1380 that made posted messages lose the "View $model" button, even if the recipient had access. @moduon MT-6348pull/1382/head
parent
db0e34a8cd
commit
41aeacea65
|
@ -19,7 +19,7 @@ class MailMessageSchedule(models.Model):
|
||||||
result = super()._group_by_model()
|
result = super()._group_by_model()
|
||||||
for model, records in result.copy().items():
|
for model, records in result.copy().items():
|
||||||
# Move records without mail.thread mixin to a False key
|
# Move records without mail.thread mixin to a False key
|
||||||
if model and not hasattr(model, "_notify_thread"):
|
if model and not hasattr(self.env.get(model), "_notify_thread"):
|
||||||
result.pop(model)
|
result.pop(model)
|
||||||
result.setdefault(False, self.browse())
|
result.setdefault(False, self.browse())
|
||||||
result[False] += records
|
result[False] += records
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||||
|
|
||||||
import freezegun
|
import freezegun
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
from odoo.tests import tagged
|
from odoo.tests import tagged
|
||||||
|
@ -216,6 +217,49 @@ class MessagePostCase(MailPostDeferCommon):
|
||||||
self.assertFalse(hasattr(self.env["res.country"], "_notify_thread"))
|
self.assertFalse(hasattr(self.env["res.country"], "_notify_thread"))
|
||||||
self.assertTrue(hasattr(self.env["res.partner"], "_notify_thread"))
|
self.assertTrue(hasattr(self.env["res.partner"], "_notify_thread"))
|
||||||
|
|
||||||
|
def test_button_access(self):
|
||||||
|
"""A button is added to the email to access the record."""
|
||||||
|
customer = self.env["res.partner"].create(
|
||||||
|
{"name": "Customer", "email": "customer@example.com"}
|
||||||
|
)
|
||||||
|
with self.mock_mail_gateway():
|
||||||
|
customer.message_post(
|
||||||
|
body="test body",
|
||||||
|
subject="test subject",
|
||||||
|
message_type="comment",
|
||||||
|
partner_ids=(self.partner_employee | customer).ids,
|
||||||
|
)
|
||||||
|
self.assertNoMail(self.partner_employee | customer)
|
||||||
|
# After a minute, mails are sent
|
||||||
|
with freezegun.freeze_time("2023-01-02 10:01:00"):
|
||||||
|
self.env["mail.message.schedule"]._send_notifications_cron()
|
||||||
|
self.env["mail.mail"].process_email_queue()
|
||||||
|
# Employee has a button that grants them access
|
||||||
|
customer_link = customer._notify_get_action_link("view")
|
||||||
|
employee_mail = self.assertSentEmail(
|
||||||
|
self.env.user.partner_id,
|
||||||
|
self.partner_employee,
|
||||||
|
body_content="test body",
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
html.fromstring(employee_mail["body"])
|
||||||
|
.xpath(f"//a[contains(@href, '{customer_link}')]")[0]
|
||||||
|
.text_content()
|
||||||
|
.strip(),
|
||||||
|
"View Contact",
|
||||||
|
)
|
||||||
|
# Customer got the mail, but doesn't have access
|
||||||
|
customer_mail = self.assertSentEmail(
|
||||||
|
self.env.user.partner_id,
|
||||||
|
customer,
|
||||||
|
body_content="test body",
|
||||||
|
)
|
||||||
|
self.assertFalse(
|
||||||
|
html.fromstring(customer_mail["body"]).xpath(
|
||||||
|
f"//a[contains(@href, '{customer_link}')]"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@tagged("-at_install", "post_install")
|
@tagged("-at_install", "post_install")
|
||||||
@freezegun.freeze_time("2023-01-02 10:00:00")
|
@freezegun.freeze_time("2023-01-02 10:00:00")
|
||||||
|
|
Loading…
Reference in New Issue