[FIX] mail: backport of saas-2 revision 9065 and 9081.
Make sure the user is subscribed before the super() call in mail_thread. This allows to have follower based record rules working (eg: note.note) bzr revid: mat@openerp.com-20140206104714-anpehaik4wajnfrw
This commit is contained in:
parent
ffabcd257c
commit
7407f3c888
|
@ -188,10 +188,9 @@ class mail_thread(osv.AbstractModel):
|
|||
new = set(command[2])
|
||||
|
||||
# remove partners that are no longer followers
|
||||
self.message_unsubscribe(cr, uid, [id], list(old-new))
|
||||
|
||||
self.message_unsubscribe(cr, uid, [id], list(old-new), context=context)
|
||||
# add new followers
|
||||
self.message_subscribe(cr, uid, [id], list(new-old))
|
||||
self.message_subscribe(cr, uid, [id], list(new-old), context=context)
|
||||
|
||||
def _search_followers(self, cr, uid, obj, name, args, context):
|
||||
fol_obj = self.pool.get('mail.followers')
|
||||
|
@ -238,16 +237,22 @@ class mail_thread(osv.AbstractModel):
|
|||
if context is None:
|
||||
context = {}
|
||||
|
||||
thread_id = super(mail_thread, self).create(cr, uid, values, context=context)
|
||||
# subscribe uid unless asked not to
|
||||
if not context.get('mail_create_nosubscribe'):
|
||||
pid = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid).partner_id.id
|
||||
message_follower_ids = values.get('message_follower_ids') or [] # webclient can send None or False
|
||||
message_follower_ids.append([4, pid])
|
||||
values['message_follower_ids'] = message_follower_ids
|
||||
# add operation to ignore access rule checking for subscription
|
||||
context_operation = dict(context, operation='create')
|
||||
else:
|
||||
context_operation = context
|
||||
thread_id = super(mail_thread, self).create(cr, uid, values, context=context_operation)
|
||||
|
||||
# automatic logging unless asked not to (mainly for various testing purpose)
|
||||
if not context.get('mail_create_nolog'):
|
||||
self.message_post(cr, uid, thread_id, body=_('%s created') % (self._description), context=context)
|
||||
|
||||
# subscribe uid unless asked not to
|
||||
if not context.get('mail_create_nosubscribe'):
|
||||
self.message_subscribe_users(cr, uid, [thread_id], [uid], context=context)
|
||||
|
||||
# auto_subscribe: take values and defaults into account
|
||||
create_values = dict(values)
|
||||
for key, val in context.iteritems():
|
||||
|
@ -1188,16 +1193,20 @@ class mail_thread(osv.AbstractModel):
|
|||
|
||||
def message_subscribe(self, cr, uid, ids, partner_ids, subtype_ids=None, context=None):
|
||||
""" Add partners to the records followers. """
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
mail_followers_obj = self.pool.get('mail.followers')
|
||||
subtype_obj = self.pool.get('mail.message.subtype')
|
||||
|
||||
user_pid = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id.id
|
||||
if set(partner_ids) == set([user_pid]):
|
||||
try:
|
||||
self.check_access_rights(cr, uid, 'read')
|
||||
self.check_access_rule(cr, uid, ids, 'read')
|
||||
except (osv.except_osv, orm.except_orm):
|
||||
return False
|
||||
if context.get('operation', '') != 'create':
|
||||
try:
|
||||
self.check_access_rights(cr, uid, 'read')
|
||||
self.check_access_rule(cr, uid, ids, 'read')
|
||||
except (osv.except_osv, orm.except_orm):
|
||||
return False
|
||||
else:
|
||||
self.check_access_rights(cr, uid, 'write')
|
||||
self.check_access_rule(cr, uid, ids, 'write')
|
||||
|
|
Loading…
Reference in New Issue