From 61a45e9268d149120e7d1e46a75fecafc8953005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 23 Aug 2012 14:24:26 +0200 Subject: [PATCH] [IMP] mail_thread: message_follower_ids: simplified message_subscribe code, now that we use the many2many modified field. Subscrubing is now a simple write on the field. bzr revid: tde@openerp.com-20120823122426-o08nh8gxx93kizjl --- addons/mail/mail_thread.py | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 9f43087cd6a..d21aae67c87 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -637,35 +637,15 @@ class mail_thread(osv.Model): return self.message_subscribe(cr, uid, ids, partner_ids, context=context) def message_subscribe(self, cr, uid, ids, partner_ids, context=None): - """ Add partners to the records followers. This implementation cannot - directly use [(4, partner_id)] because of the res_model column of - mail.followers. We therefore check access rights and access rules - before directly creating a follower record. This way we simulate - a write in message_follower_ids, enabling a correct check of access - rights. + """ Add partners to the records followers. :param partner_ids: a list of partner_ids to subscribe :param return: new value of followers, for Chatter """ - self.check_access_rights(cr, uid, 'write', raise_exception=True) - self.check_access_rule(cr, uid, ids, 'write', context=context) - - fol_obj = self.pool.get('mail.followers') - fol_ids = fol_obj.search(cr, uid, [ - ('res_id', 'in', ids), ('res_model', '=', self._name), ('partner_id', 'in', partner_ids) - ], context=context) - followers = {} - for fol in fol_obj.browse(cr, uid, fol_ids, context=context): - followers.setdefault(fol.partner_id.id, []).append(fol.res_id) - - for res_id in ids: - for partner_id in partner_ids: - if not res_id in followers.get(partner_id, []): - fol_obj.create(cr, uid, { - 'res_id': res_id, 'partner_id': partner_id, 'res_model': self._name - }, context=context) + self.write(cr, uid, ids, {'message_follower_ids': [(4, pid) for pid in partner_ids]}, context=context) # TDE: temp, must check followers widget return [] + # return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids] def message_unsubscribe_users(self, cr, uid, ids, user_ids=None, context=None): """ Wrapper on message_subscribe, using users. If user_ids is not @@ -682,9 +662,9 @@ class mail_thread(osv.Model): :param return: new value of followers, for Chatter """ self.write(cr, uid, ids, {'message_follower_ids': [(3, pid) for pid in partner_ids]}, context=context) - # return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids] # TDE: temp, must check followers widget return [] + # return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids] #------------------------------------------------------ # Notification API