[FIX] message_route: removed owner of created documents using aliases taken from...
[odoo/odoo.git] / addons / mail / mail_thread.py
index 6925128..12e43d0 100644 (file)
@@ -309,13 +309,15 @@ class mail_thread(osv.AbstractModel):
 
     def message_track(self, cr, uid, ids, tracked_fields, initial_values, context=None):
 
-        def convert_for_display(value, field_obj):
+        def convert_for_display(value, col_info):
+            if not value and col_info['type'] == 'boolean':
+                return 'False'
             if not value:
                 return ''
-            if field_obj['type'] == 'many2one':
+            if col_info['type'] == 'many2one':
                 return value[1]
-            if field_obj['type'] == 'selection':
-                return dict(field_obj['selection'])[value]
+            if col_info['type'] == 'selection':
+                return dict(col_info['selection'])[value]
             return value
 
         def format_message(message_description, tracked_values):
@@ -489,7 +491,13 @@ class mail_thread(osv.AbstractModel):
                 for alias in mail_alias.browse(cr, uid, alias_ids, context=context):
                     user_id = alias.alias_user_id.id
                     if not user_id:
-                        user_id = self._message_find_user_id(cr, uid, message, context=context)
+                        # TDE note: this could cause crashes, because no clue that the user
+                        # that send the email has the right to create or modify a new document
+                        # Fallback on user_id = uid
+                        # Note: recognized partners will be added as followers anyway
+                        # user_id = self._message_find_user_id(cr, uid, message, context=context)
+                        user_id = uid
+                        _logger.debug('Routing mail with Message-Id %s: direct alias match: %r', message_id, routes)
                     routes.append((alias.alias_model_id.model, alias.alias_force_thread_id, \
                                    eval(alias.alias_defaults), user_id))
                 _logger.debug('Routing mail with Message-Id %s: direct alias match: %r', message_id, routes)
@@ -886,9 +894,9 @@ class mail_thread(osv.AbstractModel):
 
         return mail_message.create(cr, uid, values, context=context)
 
-    def message_post_user_api(self, cr, uid, thread_id, body='', subject=False,
-                                parent_id=False, attachment_ids=None, extra_emails=None,
-                                context=None, content_subtype='plaintext', **kwargs):
+    def message_post_user_api(self, cr, uid, thread_id, body='', parent_id=False,
+                                attachment_ids=None, extra_emails=None, content_subtype='plaintext',
+                                context=None, **kwargs):
         """ Wrapper on message_post, used for user input :
             - mail gateway
             - quick reply in Chatter (refer to mail.js), not
@@ -917,7 +925,7 @@ class mail_thread(osv.AbstractModel):
                 mail_message_obj.write(cr, SUPERUSER_ID, partner_msg_ids, {'email_from': None, 'author_id': partner_id}, context=context)
             partner_ids.add((4, partner_id))
         if partner_ids:
-            self.message_subscribe(cr, uid, [thread_id], list(partner_ids), context=context)
+            self.message_subscribe(cr, uid, [thread_id], [item[1] for item in partner_ids], context=context)
 
         # 1.A.2: add recipients of parent message
         if parent_id:
@@ -933,8 +941,8 @@ class mail_thread(osv.AbstractModel):
         # 1.B: handle body, message_type and message_subtype
         if content_subtype == 'plaintext':
             body = tools.plaintext2html(body)
-        message_type = kwargs.pop('type', 'comment')
-        message_subtype = kwargs.pop('subtype', 'mail.mt_comment')
+        msg_type = kwargs.pop('type', 'comment')
+        msg_subtype = kwargs.pop('subtype', 'mail.mt_comment')
 
         # 2. Pre-processing: attachments
         # HACK TDE FIXME: Chatter: attachments linked to the document (not done JS-side), load the message
@@ -954,13 +962,12 @@ class mail_thread(osv.AbstractModel):
                     ir_attachment.write(cr, SUPERUSER_ID, attachment_ids, {'res_model': model, 'res_id': thread_id}, context=context)
         else:
             attachment_ids = []
+        attachment_ids = [(4, id) for id in attachment_ids]
 
         # 3. Post message
-        new_message_id = self.message_post(cr, uid, thread_id=thread_id, body=body, subject=subject,
-                            type=message_type, subtype=message_subtype, parent_id=parent_id,
-                            attachment_ids=[(4, id) for id in attachment_ids], partner_ids=partner_ids,
-                            context=context, **kwargs)
-        return new_message_id
+        return self.message_post(cr, uid, thread_id=thread_id, body=body,
+                            type=msg_type, subtype=msg_subtype, parent_id=parent_id,
+                            attachment_ids=attachment_ids, partner_ids=list(partner_ids), context=context, **kwargs)
 
     #------------------------------------------------------
     # Followers API