summaryrefslogtreecommitdiff
path: root/addons/mail/mail_thread.py
diff options
context:
space:
mode:
authorsgo@tinyerp.com <>2013-06-05 12:49:05 +0530
committersgo@tinyerp.com <>2013-06-05 12:49:05 +0530
commit6a3cdf718ce4f9bd2749bb75993cdbcfd86d3eb2 (patch)
tree075af0421f75fd36ca9f5cd44551e58ffc73460a /addons/mail/mail_thread.py
parent143b485baf8adb7936d7784e314ccd405d1b8c14 (diff)
parent5cc8c30adfeccc6db22ebf7487b8e4ebdbe10423 (diff)
[MERGE]sync with trunk
bzr revid: sgo@tinyerp.com-20130605071905-o2ldzc6vxqnoe099
Diffstat (limited to 'addons/mail/mail_thread.py')
-rw-r--r--addons/mail/mail_thread.py100
1 files changed, 90 insertions, 10 deletions
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 5ddf412e66b..80df8ad6e99 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -33,7 +33,7 @@ from email.message import Message
from openerp import tools
from openerp import SUPERUSER_ID
from openerp.addons.mail.mail_message import decode
-from openerp.osv import fields, osv
+from openerp.osv import fields, osv, orm
from openerp.tools.safe_eval import safe_eval as eval
from openerp.tools.translate import _
@@ -449,6 +449,70 @@ class mail_thread(osv.AbstractModel):
ir_attachment_obj.unlink(cr, uid, attach_ids, context=context)
return True
+ def _get_formview_action(self, cr, uid, id, model=None, context=None):
+ """ Return an action to open the document. This method is meant to be
+ overridden in addons that want to give specific view ids for example.
+
+ :param int id: id of the document to open
+ :param string model: specific model that overrides self._name
+ """
+ return {
+ 'type': 'ir.actions.act_window',
+ 'res_model': model or self._name,
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'views': [(False, 'form')],
+ 'target': 'current',
+ 'res_id': id,
+ }
+
+ def _get_inbox_action_xml_id(self, cr, uid, context=None):
+ """ When redirecting towards the Inbox, choose which action xml_id has
+ to be fetched. This method is meant to be inherited, at least in portal
+ because portal users have a different Inbox action than classic users. """
+ return ('mail', 'action_mail_inbox_feeds')
+
+ def message_redirect_action(self, cr, uid, context=None):
+ """ For a given message, return an action that either
+ - opens the form view of the related document if model, res_id, and
+ read access to the document
+ - opens the Inbox with a default search on the conversation if model,
+ res_id
+ - opens the Inbox with context propagated
+
+ """
+ if context is None:
+ context = {}
+
+ # default action is the Inbox action
+ self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
+ act_model, act_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, *self._get_inbox_action_xml_id(cr, uid, context=context))
+ action = self.pool.get(act_model).read(cr, uid, act_id, [])
+
+ # if msg_id specified: try to redirect to the document or fallback on the Inbox
+ msg_id = context.get('params', {}).get('message_id')
+ if not msg_id:
+ return action
+ msg = self.pool.get('mail.message').browse(cr, uid, msg_id, context=context)
+ if msg.model and msg.res_id:
+ action.update({
+ 'context': {
+ 'search_default_model': msg.model,
+ 'search_default_res_id': msg.res_id,
+ }
+ })
+ if self.pool.get(msg.model).check_access_rights(cr, uid, 'read', raise_exception=False):
+ try:
+ model_obj = self.pool.get(msg.model)
+ model_obj.check_access_rule(cr, uid, [msg.res_id], 'read', context=context)
+ if not hasattr(model_obj, '_get_formview_action'):
+ action = self.pool.get('mail.thread')._get_formview_action(cr, uid, msg.res_id, model=msg.model, context=context)
+ else:
+ action = model_obj._get_formview_action(cr, uid, msg.res_id, context=context)
+ except (osv.except_osv, orm.except_orm):
+ pass
+ return action
+
#------------------------------------------------------
# Email specific
#------------------------------------------------------
@@ -459,7 +523,7 @@ class mail_thread(osv.AbstractModel):
return ["%s@%s" % (record['alias_name'], record['alias_domain'])
if record.get('alias_domain') and record.get('alias_name')
else False
- for record in self.read(cr, uid, ids, ['alias_name', 'alias_domain'], context=context)]
+ for record in self.read(cr, SUPERUSER_ID, ids, ['alias_name', 'alias_domain'], context=context)]
#------------------------------------------------------
# Mail gateway
@@ -1200,19 +1264,35 @@ class mail_thread(osv.AbstractModel):
""" Add partners to the records followers. """
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')
+ try:
+ self.check_access_rights(cr, uid, 'read')
+ except (osv.except_osv, orm.except_orm):
+ return
else:
self.check_access_rights(cr, uid, 'write')
+ # subscribe partners
self.write(cr, SUPERUSER_ID, ids, {'message_follower_ids': [(4, pid) for pid in partner_ids]}, context=context)
- # if subtypes are not specified (and not set to a void list), fetch default ones
- if subtype_ids is None:
- subtype_obj = self.pool.get('mail.message.subtype')
- subtype_ids = subtype_obj.search(cr, uid, [('default', '=', True), '|', ('res_model', '=', self._name), ('res_model', '=', False)], context=context)
- # update the subscriptions
+
+ # subtype specified: update the subscriptions
fol_obj = self.pool.get('mail.followers')
- fol_ids = fol_obj.search(cr, SUPERUSER_ID, [('res_model', '=', self._name), ('res_id', 'in', ids), ('partner_id', 'in', partner_ids)], context=context)
- fol_obj.write(cr, SUPERUSER_ID, fol_ids, {'subtype_ids': [(6, 0, subtype_ids)]}, context=context)
+ if subtype_ids is not None:
+ fol_ids = fol_obj.search(cr, SUPERUSER_ID, [('res_model', '=', self._name), ('res_id', 'in', ids), ('partner_id', 'in', partner_ids)], context=context)
+ fol_obj.write(cr, SUPERUSER_ID, fol_ids, {'subtype_ids': [(6, 0, subtype_ids)]}, context=context)
+ # no subtypes: default ones for new subscription, do not update existing subscriptions
+ else:
+ # search new subscriptions: subtype_ids is False
+ fol_ids = fol_obj.search(cr, SUPERUSER_ID, [
+ ('res_model', '=', self._name),
+ ('res_id', 'in', ids),
+ ('partner_id', 'in', partner_ids),
+ ('subtype_ids', '=', False)
+ ], context=context)
+ if fol_ids:
+ subtype_obj = self.pool.get('mail.message.subtype')
+ subtype_ids = subtype_obj.search(cr, uid, [('default', '=', True), '|', ('res_model', '=', self._name), ('res_model', '=', False)], context=context)
+ fol_obj.write(cr, SUPERUSER_ID, fol_ids, {'subtype_ids': [(6, 0, subtype_ids)]}, context=context)
+
return True
def message_unsubscribe_users(self, cr, uid, ids, user_ids=None, context=None):