From 88c5a90677ff00dce27aae673616e4f27d7ad508 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 4 Dec 2015 11:25:11 +0100 Subject: [PATCH] [FIX] mail: allow users to unsubscribe from private channels Before this rev., only the root user was allowed to do so, because some operations were performed on the channel just after the user had been unsubscribed (to trigger the unsubscribe notification on the bus, and to post the 'left channel' message). --- addons/mail/models/mail_channel.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index b72f4c557b4..f63d4d763bc 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -159,11 +159,14 @@ class Channel(models.Model): @api.multi def action_unfollow(self): - result = self.write({'channel_partner_ids': [(3, self.env.user.partner_id.id)]}) - self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), self.channel_info('unsubscribe')[0]) + partner_id = self.env.user.partner_id.id + channel_info = self.channel_info('unsubscribe')[0] # must be computed before leaving the channel (access rights) + result = self.write({'channel_partner_ids': [(3, partner_id)]}) + self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', partner_id), channel_info) if not self.email_send: notification = _('
left #%s
') % (self.id, self.name,) - self.message_post(body=notification, message_type="notification", subtype="mail.mt_comment") + # post 'channel left' message as root since the partner just unsubscribed from the channel + self.sudo().message_post(body=notification, message_type="notification", subtype="mail.mt_comment", author_id=partner_id) return result @api.multi