diff options
Diffstat (limited to 'addons/mail/mail_thread.py')
| -rw-r--r-- | addons/mail/mail_thread.py | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index eea95a6c5ed..97abd6050e8 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -365,10 +365,11 @@ class mail_thread(osv.AbstractModel): track_ctx = dict(context) if 'lang' not in track_ctx: track_ctx['lang'] = self.pool.get('res.users').browse(cr, uid, uid, context=context).lang - tracked_fields = self._get_tracked_fields(cr, uid, values.keys(), context=track_ctx) - if tracked_fields: - initial_values = {thread_id: dict((item, False) for item in tracked_fields)} - self.message_track(cr, uid, [thread_id], tracked_fields, initial_values, context=track_ctx) + if not context.get('mail_notrack'): + tracked_fields = self._get_tracked_fields(cr, uid, values.keys(), context=track_ctx) + if tracked_fields: + initial_values = {thread_id: dict((item, False) for item in tracked_fields)} + self.message_track(cr, uid, [thread_id], tracked_fields, initial_values, context=track_ctx) return thread_id def write(self, cr, uid, ids, values, context=None): @@ -392,7 +393,11 @@ class mail_thread(osv.AbstractModel): result = super(mail_thread, self).write(cr, uid, ids, values, context=context) self.message_auto_subscribe(cr, uid, ids, values.keys(), context=context, values=values) - # Perform the tracking + if not context.get('mail_notrack'): + # Perform the tracking + tracked_fields = self._get_tracked_fields(cr, uid, values.keys(), context=context) + else: + tracked_fields = None if tracked_fields: self.message_track(cr, uid, ids, tracked_fields, initial_values, context=track_ctx) return result @@ -413,6 +418,9 @@ class mail_thread(osv.AbstractModel): return res def copy(self, cr, uid, id, default=None, context=None): + # avoid tracking multiple temporary changes during copy + context = dict(context or {}, mail_notrack=True) + default = default or {} default['message_ids'] = [] default['message_follower_ids'] = [] @@ -724,13 +732,15 @@ class mail_thread(osv.AbstractModel): # Private message: should not contain any thread_id if not model and thread_id: if assert_model: - assert thread_id == 0, 'Routing: posting a message without model should be with a null res_id (private message), received %s.' % thread_id - _warn('posting a message without model should be with a null res_id (private message), received %s, resetting thread_id' % thread_id) + if thread_id: + raise ValueError('Routing: posting a message without model should be with a null res_id (private message), received %s.' % thread_id) + _warn('posting a message without model should be with a null res_id (private message), received %s resetting thread_id' % thread_id) thread_id = 0 # Private message: should have a parent_id (only answers) if not model and not message_dict.get('parent_id'): if assert_model: - assert message_dict.get('parent_id'), 'Routing: posting a message without model should be with a parent_id (private mesage).' + if not message_dict.get('parent_id'): + raise ValueError('Routing: posting a message without model should be with a parent_id (private mesage).') _warn('posting a message without model should be with a parent_id (private mesage), skipping') return () @@ -759,7 +769,10 @@ class mail_thread(osv.AbstractModel): # New Document: check model accepts the mailgateway if not thread_id and model and not hasattr(model_pool, 'message_new'): if assert_model: - assert hasattr(model_pool, 'message_new'), 'Model %s does not accept document creation, crashing' % model + if not hasattr(model_pool, 'message_new'): + raise ValueError( + 'Model %s does not accept document creation, crashing' % model + ) _warn('model %s does not accept document creation, skipping' % model) return () @@ -820,8 +833,11 @@ class mail_thread(osv.AbstractModel): to which this mail should be attached. Only used if the message does not reply to an existing thread and does not match any mail alias. :return: list of [model, thread_id, custom_values, user_id, alias] + + :raises: ValueError, TypeError """ - assert isinstance(message, Message), 'message must be an email.message.Message at this point' + if not isinstance(message, Message): + raise TypeError('message must be an email.message.Message at this point') mail_msg_obj = self.pool['mail.message'] fallback_model = model @@ -939,9 +955,11 @@ class mail_thread(osv.AbstractModel): return [route] # AssertionError if no routes found and if no bounce occured - assert False, \ - "No possible route found for incoming message from %s to %s (Message-Id %s:)." \ - "Create an appropriate mail.alias or force the destination model." % (email_from, email_to, message_id) + raise ValueError( + 'No possible route found for incoming message from %s to %s (Message-Id %s:). ' + 'Create an appropriate mail.alias or force the destination model.' % + (email_from, email_to, message_id) + ) def message_route_process(self, cr, uid, message, message_dict, routes, context=None): # postpone setting message_dict.partner_ids after message_post, to avoid double notifications @@ -952,9 +970,11 @@ class mail_thread(osv.AbstractModel): context.update({'thread_model': model}) if model: model_pool = self.pool[model] - assert thread_id and hasattr(model_pool, 'message_update') or hasattr(model_pool, 'message_new'), \ - "Undeliverable mail with Message-Id %s, model %s does not accept incoming emails" % \ - (message_dict['message_id'], model) + if not (thread_id and hasattr(model_pool, 'message_update') or hasattr(model_pool, 'message_new')): + raise ValueError( + "Undeliverable mail with Message-Id %s, model %s does not accept incoming emails" % + (message_dict['message_id'], model) + ) # disabled subscriptions during message_new/update to avoid having the system user running the # email gateway become a follower of all inbound messages @@ -964,7 +984,8 @@ class mail_thread(osv.AbstractModel): else: thread_id = model_pool.message_new(cr, user_id, message_dict, custom_values, context=nosub_ctx) else: - assert thread_id == 0, "Posting a message without model should be with a null res_id, to create a private message." + if thread_id: + raise ValueError("Posting a message without model should be with a null res_id, to create a private message.") model_pool = self.pool.get('mail.thread') if not hasattr(model_pool, 'message_post'): context['thread_model'] = model @@ -1548,6 +1569,9 @@ class mail_thread(osv.AbstractModel): """ Add partners to the records followers. """ if context is None: context = {} + # not necessary for computation, but saves an access right check + if not partner_ids: + return True mail_followers_obj = self.pool.get('mail.followers') subtype_obj = self.pool.get('mail.message.subtype') @@ -1556,6 +1580,9 @@ class mail_thread(osv.AbstractModel): if set(partner_ids) == set([user_pid]): try: self.check_access_rights(cr, uid, 'read') + if context.get('operation', '') == 'create': + self.check_access_rule(cr, uid, ids, 'create') + else: self.check_access_rule(cr, uid, ids, 'read') except (osv.except_osv, orm.except_orm): return False @@ -1603,6 +1630,9 @@ class mail_thread(osv.AbstractModel): def message_unsubscribe(self, cr, uid, ids, partner_ids, context=None): """ Remove partners from the records followers. """ + # not necessary for computation, but saves an access right check + if not partner_ids: + return True user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] if set(partner_ids) == set([user_pid]): self.check_access_rights(cr, uid, 'read') |
