diff --git a/addons/mail/mail_followers.py b/addons/mail/mail_followers.py index 2a20c4f58dc..dea10bbd7a1 100644 --- a/addons/mail/mail_followers.py +++ b/addons/mail/mail_followers.py @@ -22,7 +22,7 @@ import threading from openerp.osv import osv, fields -from openerp import tools, SUPERUSER_ID +from openerp import api, tools, SUPERUSER_ID from openerp.tools.translate import _ from openerp.tools.mail import plaintext2html @@ -55,20 +55,31 @@ class mail_followers(osv.Model): # Modifying followers change access rights to individual documents. As the # cache may contain accessible/inaccessible data, one has to refresh it. # - def create(self, cr, uid, vals, context=None): - res = super(mail_followers, self).create(cr, uid, vals, context=context) - self.invalidate_cache(cr, uid, context=context) + @api.multi + def _invalidate_documents(self): + """ Invalidate the cache of the documents followed by ``self``. """ + for record in self: + if record.res_id: + self.env[record.res_model].invalidate_cache(ids=[record.res_id]) + + @api.model + def create(self, vals): + record = super(mail_followers, self).create(vals) + record._invalidate_documents() + return record + + @api.multi + def write(self, vals): + if 'res_model' in vals or 'res_id' in vals: + self._invalidate_documents() + res = super(mail_followers, self).write(vals) + self._invalidate_documents() return res - def write(self, cr, uid, ids, vals, context=None): - res = super(mail_followers, self).write(cr, uid, ids, vals, context=context) - self.invalidate_cache(cr, uid, context=context) - return res - - def unlink(self, cr, uid, ids, context=None): - res = super(mail_followers, self).unlink(cr, uid, ids, context=context) - self.invalidate_cache(cr, uid, context=context) - return res + @api.multi + def unlink(self): + self._invalidate_documents() + return super(mail_followers, self).unlink() _sql_constraints = [('mail_followers_res_partner_res_model_id_uniq','unique(res_model,res_id,partner_id)','Error, a partner cannot follow twice the same object.')] diff --git a/addons/mail/tests/test_mail_features.py b/addons/mail/tests/test_mail_features.py index a457dd0db73..50ee8db7eaf 100644 --- a/addons/mail/tests/test_mail_features.py +++ b/addons/mail/tests/test_mail_features.py @@ -209,6 +209,16 @@ class test_mail(TestMail): self.assertTrue(subtype_data['mt_mg_nodef']['followed'], 'Admin should follow mt_mg_nodef in pigs') self.assertTrue(subtype_data['mt_all_nodef']['followed'], 'Admin should follow mt_all_nodef in pigs') + def test_10_cache_invalidation(self): + """ Test that creating a mail-thread record does not invalidate the whole cache. """ + # make a new record in cache + record = self.env['res.partner'].new({'name': 'Brave New Partner'}) + self.assertTrue(record.name) + + # creating a mail-thread record should not invalidate the whole cache + self.env['res.partner'].create({'name': 'Actual Partner'}) + self.assertTrue(record.name) + def test_11_notification_url(self): """ Tests designed to test the URL added in notification emails. """ cr, uid, group_pigs = self.cr, self.uid, self.group_pigs diff --git a/addons/portal/mail_message.py b/addons/portal/mail_message.py index 36b06484e9e..1030deeb941 100644 --- a/addons/portal/mail_message.py +++ b/addons/portal/mail_message.py @@ -51,6 +51,8 @@ class mail_message(osv.Model): """ if uid == SUPERUSER_ID: return super(mail_message, self).check_access_rule(cr, uid, ids=ids, operation=operation, context=context) + if isinstance(ids, (int, long)): + ids = [ids] group_ids = self.pool.get('res.users').browse(cr, uid, uid, context=context).groups_id group_user_id = self.pool.get("ir.model.data").get_object_reference(cr, uid, 'base', 'group_user')[1] if group_user_id not in [group.id for group in group_ids]: diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index d28a14bdfa5..494fb3abfe7 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -72,7 +72,6 @@ class purchase_order(osv.osv): ('order_id', '=', po.id), '|', ('date_planned', '=', po.minimum_planned_date), ('date_planned', '<', value) ], context=context) pol_obj.write(cr, uid, pol_ids, {'date_planned': value}, context=context) - self.invalidate_cache(cr, uid, context=context) return True def _minimum_planned_date(self, cr, uid, ids, field_name, arg, context=None):