[REV] mail: fix a traceback when sending a message in a "email channel"
Bug
===
Since 4da64b3f3c , if multiple users of
different companies are in the same channel, and if the type of the
channel is "email", a traceback is raised when sending a message.
Technical
=========
"with_user" drop the SU flag and is not enough to bypass the multi
company ACLs. Moreover, we do not want to send a "channel_seen" bus
notifications and we can mark the message as seen on the JS side
directly.
Changes
=======
So now, the traceback is not raised anymore in that case, and the
message is marked as seen if the receiver has the web client open.
But, if the receiver has not the web client open, when he will login,
the message will not be marked as seen. This can be improved but at the
moment we just want to revert the fix that cause the traceback and fix
the issue in most cases.
Task 2427790
closes odoo/odoo#71320
X-original-commit: 8b5de95bea0087c48d17f40847750eb31fe97caf
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -577,15 +577,6 @@ class Channel(models.Model):
|
||||
bus_notifications = self._channel_message_notifications(message, message_format_values)
|
||||
self.env['bus.bus'].sudo().sendmany(bus_notifications)
|
||||
|
||||
# Message from mailing channel should not make a notification in Odoo for users
|
||||
# with notification "Handled by Email", but web client should receive the message.
|
||||
# To do so, message is still sent from longpolling, but channel is marked as read
|
||||
# in order to remove notification.
|
||||
for channel in self.filtered(lambda c: c.email_send):
|
||||
users = channel.channel_partner_ids.mapped('user_ids')
|
||||
for user in users.filtered(lambda u: u.notification_type == 'email'):
|
||||
channel.with_user(user).channel_seen(message.id)
|
||||
|
||||
else:
|
||||
message._notify_pending_by_chat()
|
||||
rdata = False
|
||||
|
||||
+4
@@ -236,6 +236,10 @@ function factory(dependencies) {
|
||||
channel.mass_mailing &&
|
||||
this.env.session.notification_type === 'email'
|
||||
) {
|
||||
this._handleNotificationChannelSeen(channelId, {
|
||||
last_message_id: messageData.id,
|
||||
partner_id: this.env.messaging.currentPartner.id,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// In all other cases: update counter and notify if necessary
|
||||
|
||||
@@ -435,6 +435,74 @@ class TestChannelInternals(MailCommon):
|
||||
).channel_get(self.partner_employee_c2.ids)
|
||||
self.assertTrue(initial_channel_info, 'should be able to chat with multi company user')
|
||||
|
||||
def test_multi_company_message_post_notifications(self):
|
||||
company_1 = self.company_admin
|
||||
company_2 = self.env['res.company'].create({'name': 'Company 2'})
|
||||
|
||||
# Company 1 and notification_type == "inbox"
|
||||
user_1 = self.user_employee
|
||||
|
||||
# Company 1 and notification_type == "email"
|
||||
user_2 = self.user_admin
|
||||
user_2.notification_type = 'email'
|
||||
|
||||
user_3 = mail_new_test_user(
|
||||
self.env, login='user3', email='user3@example.com', groups='base.group_user',
|
||||
company_id=company_2.id, company_ids=[(6, 0, company_2.ids)],
|
||||
name='user3', notification_type='inbox')
|
||||
|
||||
user_4 = mail_new_test_user(
|
||||
self.env, login='user4', email='user4@example.com', groups='base.group_user',
|
||||
company_id=company_2.id, company_ids=[(6, 0, company_2.ids)],
|
||||
name='user4', notification_type='email')
|
||||
|
||||
partner_without_user = self.env['res.partner'].create({
|
||||
'name': 'Partner',
|
||||
'email': 'partner_test_123@example.com',
|
||||
})
|
||||
mail_channel = self.env['mail.channel'].with_user(user_1).create({
|
||||
'name': 'Channel',
|
||||
'channel_partner_ids': [
|
||||
(4, user_1.partner_id.id),
|
||||
(4, user_2.partner_id.id),
|
||||
(4, user_3.partner_id.id),
|
||||
(4, user_4.partner_id.id),
|
||||
(4, partner_without_user.id),
|
||||
],
|
||||
'email_send': True,
|
||||
})
|
||||
|
||||
mail_channel.invalidate_cache()
|
||||
(user_1 | user_2 | user_3 | user_4).invalidate_cache()
|
||||
|
||||
with self.mock_mail_gateway():
|
||||
mail_channel.with_user(user_1).with_company(company_1).message_post(
|
||||
body='Test body message 1337',
|
||||
message_type='email',
|
||||
subtype_xmlid='mail.mt_comment',
|
||||
)
|
||||
|
||||
self.assertSentEmail(user_1.partner_id, [user_2.partner_id])
|
||||
self.assertSentEmail(user_1.partner_id, [user_4.partner_id])
|
||||
self.assertEqual(len(self._mails), 3, 'Should have send only 3 emails to user 2, user 4 and the partner')
|
||||
|
||||
self.assertBusNotifications([(self.cr.dbname, 'mail.channel', mail_channel.id)])
|
||||
|
||||
# Should not create mail notifications for user 1 & 3
|
||||
self.assertFalse(self.env['mail.notification'].search([('res_partner_id', '=', user_1.partner_id.id)]))
|
||||
self.assertFalse(self.env['mail.notification'].search([('res_partner_id', '=', user_3.partner_id.id)]))
|
||||
|
||||
# Should create mail notifications for user 2 & 4
|
||||
self.assertTrue(self.env['mail.notification'].search([('res_partner_id', '=', user_2.partner_id.id)]))
|
||||
self.assertTrue(self.env['mail.notification'].search([('res_partner_id', '=', user_4.partner_id.id)]))
|
||||
|
||||
# Check that we did not send a "channel_seen" notifications
|
||||
# for the users which receive the notifications by email
|
||||
notification_seen_user_2 = self.env['bus.bus'].search([('create_uid', '=', user_2.id)])
|
||||
self.assertFalse(notification_seen_user_2, 'Should not have sent a notification as user 2')
|
||||
notification_seen_user_4 = self.env['bus.bus'].search([('create_uid', '=', user_4.id)])
|
||||
self.assertFalse(notification_seen_user_4, 'Should not have sent a notification as user 4')
|
||||
|
||||
|
||||
@tagged('moderation', 'mail_channel')
|
||||
class TestChannelModeration(MailCommon):
|
||||
|
||||
Reference in New Issue
Block a user