From 6d03677e4eb3bd116d09ede645e08f7472c4ae6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 14:01:44 +0200 Subject: [PATCH 01/22] [CLEAN] mail_mail: cleaned some forgotten spaces; fixed the commend for the notification field. bzr revid: tde@openerp.com-20120912120144-m440eafqjtccv3sp --- addons/mail/mail_mail.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index 7b593c5b998..8d3f3ab6e01 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -30,6 +30,7 @@ from tools.translate import _ _logger = logging.getLogger(__name__) + class mail_mail(osv.Model): """ Model holding RFC2822 email messages to send. This model also provides facilities to queue and send new email messages. """ @@ -58,8 +59,8 @@ class mail_mail(osv.Model): 'body_html': fields.text('Rich-text Contents', help="Rich-text/HTML message"), # Auto-detected based on create() - if 'mail_message_id' was passed then this mail is a notification - # and during unlink() we will cascade delete the parent and its attachments - 'notification': fields.boolean('Is Notification') + # and during unlink() we will not cascade delete the parent and its attachments + 'notification': fields.boolean('Is Notification') } def _get_default_from(self, cr, uid, context=None): @@ -76,21 +77,21 @@ class mail_mail(osv.Model): def create(self, cr, uid, values, context=None): if 'notification' not in values and values.get('mail_message_id'): values['notification'] = True - return super(mail_mail,self).create(cr, uid, values, context=context) + return super(mail_mail, self).create(cr, uid, values, context=context) def unlink(self, cr, uid, ids, context=None): # cascade-delete the parent message for all mails that are not created for a notification - ids_to_cascade = self.search(cr, uid, [('notification','=',False),('id','in',ids)]) + ids_to_cascade = self.search(cr, uid, [('notification', '=', False), ('id', 'in', ids)]) parent_msg_ids = [m.mail_message_id.id for m in self.browse(cr, uid, ids_to_cascade, context=context)] - res = super(mail_mail,self).unlink(cr, uid, ids, context=context) + res = super(mail_mail, self).unlink(cr, uid, ids, context=context) self.pool.get('mail.message').unlink(cr, uid, parent_msg_ids, context=context) return res def mark_outgoing(self, cr, uid, ids, context=None): - return self.write(cr, uid, ids, {'state':'outgoing'}, context=context) + return self.write(cr, uid, ids, {'state': 'outgoing'}, context=context) def cancel(self, cr, uid, ids, context=None): - return self.write(cr, uid, ids, {'state':'cancel'}, context=context) + return self.write(cr, uid, ids, {'state': 'cancel'}, context=context) def process_email_queue(self, cr, uid, ids=None, context=None): """Send immediately queued messages, committing after each @@ -127,7 +128,7 @@ class mail_mail(osv.Model): """Perform any post-processing necessary after sending ``mail`` successfully, including deleting it completely along with its attachment if the ``auto_delete`` flag of the mail was set. - Overridden by subclasses for extra post-processing behaviors. + Overridden by subclasses for extra post-processing behaviors. :param browse_record mail: the mail that was just sent :return: True @@ -189,15 +190,15 @@ class mail_mail(osv.Model): res = ir_mail_server.send_email(cr, uid, msg, mail_server_id=mail.mail_server_id.id, context=context) if res: - mail.write({'state':'sent', 'message_id': res}) + mail.write({'state': 'sent', 'message_id': res}) else: - mail.write({'state':'exception'}) + mail.write({'state': 'exception'}) mail.refresh() if mail.state == 'sent': self._postprocess_sent_message(cr, uid, mail, context=context) except Exception: _logger.exception('failed sending mail.mail %s', mail.id) - mail.write({'state':'exception'}) + mail.write({'state': 'exception'}) if auto_commit == True: cr.commit() From 828ed33de7c2690405a8350ce9452606117d7a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 15:35:22 +0200 Subject: [PATCH 02/22] [ADD] mail: added Invite wizard, allowing to add partners to the followers. bzr revid: tde@openerp.com-20120912133522-af5dvae1rmburfwy --- addons/mail/mail_message.py | 24 ++++++++++ addons/mail/wizard/__init__.py | 1 + addons/mail/wizard/invite.py | 56 ++++++++++++++++++++++ addons/mail/wizard/invite_view.xml | 29 +++++++++++ addons/mail/wizard/mail_compose_message.py | 20 +------- 5 files changed, 111 insertions(+), 19 deletions(-) create mode 100644 addons/mail/wizard/invite.py create mode 100644 addons/mail/wizard/invite_view.xml diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index e4862ca9fb9..6c65c6b302c 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -25,6 +25,7 @@ import tools from email.header import decode_header from operator import itemgetter from osv import osv, fields +from tools.translate import _ _logger = logging.getLogger(__name__) @@ -341,3 +342,26 @@ class mail_message(osv.Model): default = {} default.update(message_id=False, headers=False) return super(mail_message, self).copy(cr, uid, id, default=default, context=context) + + #------------------------------------------------------ + # Tools + #------------------------------------------------------ + + def verify_partner_email(self, cr, uid, partner_ids, context=None): + """ Verify that selected partner_ids have an email_address defined. + Otherwise throw a warning. """ + partner_wo_email_lst = [] + for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context): + if not partner.email: + partner_wo_email_lst.append(partner) + if not partner_wo_email_lst: + return {} + warning_msg = _('The following partners chosen as recipients for the email have no email address linked :') + for partner in partner_wo_email_lst: + warning_msg += '\n- %s' % (partner.name) + return {'warning': { + 'title': _('Partners email addresses not found'), + 'message': warning_msg, + } + } + diff --git a/addons/mail/wizard/__init__.py b/addons/mail/wizard/__init__.py index 88b9581f68e..39a2d843354 100644 --- a/addons/mail/wizard/__init__.py +++ b/addons/mail/wizard/__init__.py @@ -19,6 +19,7 @@ # ############################################################################## +import invite import mail_compose_message # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mail/wizard/invite.py b/addons/mail/wizard/invite.py new file mode 100644 index 00000000000..71ae23304a8 --- /dev/null +++ b/addons/mail/wizard/invite.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2012-Today OpenERP SA () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +############################################################################## + +from osv import osv +from osv import fields + + +class invite_wizard(osv.osv_memory): + """ Wizard to invite partners and make them followers. """ + _name = 'mail.wizard.invite' + _description = 'Invite wizard' + + _columns = { + 'res_model': fields.char('Related Document Model', size=128, + required=True, select=1, + help='Model of the followed resource'), + 'res_id': fields.integer('Related Document ID', select=1, + help='Id of the followed resource'), + 'partner_ids': fields.many2many('res.partner', string='Partners'), + 'message': fields.text('Message'), + } + + def onchange_partner_ids(self, cr, uid, ids, value, context=None): + """ onchange_partner_ids (value format: [[6, 0, [3, 4]]]). The + basic purpose of this method is to check that destination partners + effectively have email addresses. Otherwise a warning is thrown. + """ + res = {'value': {}} + if not value or not value[0] or not value[0][0] == 6: + return + res.update(self.pool.get('mail.message').verify_partner_email(cr, uid, value[0][2], context=context)) + return res + + def add_followers(self, cr, uid, ids, context=None): + for wizard in self.browse(cr, uid, ids, context=context): + model_obj = self.pool.get(wizard.res_model) + model_obj.message_subscribe(cr, uid, [wizard.res_id], [p.id for p in wizard.partner_ids], context=context) + return {'type': 'ir.actions.act_window_close'} diff --git a/addons/mail/wizard/invite_view.xml b/addons/mail/wizard/invite_view.xml new file mode 100644 index 00000000000..b932f96dfe7 --- /dev/null +++ b/addons/mail/wizard/invite_view.xml @@ -0,0 +1,29 @@ + + + + + + + Add Followers + mail.wizard.invite + +
+ + + + + + +
+
+
+
+
+ +
+
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 3153ccc2069..fa4ca090943 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -192,24 +192,6 @@ class mail_compose_message(osv.TransientModel): specific behavior. """ return {'value': {'content_subtype': value}} - def _verify_partner_email(self, cr, uid, partner_ids, context=None): - """ Verify that selected partner_ids have an email_address defined. - Otherwise throw a warning. """ - partner_wo_email_lst = [] - for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context): - if not partner.email: - partner_wo_email_lst.append(partner) - if not partner_wo_email_lst: - return {} - warning_msg = _('The following partners chosen as recipients for the email have no email address linked :') - for partner in partner_wo_email_lst: - warning_msg += '\n- %s' % (partner.name) - return {'warning': { - 'title': _('Partners email addresses not found'), - 'message': warning_msg, - } - } - def onchange_partner_ids(self, cr, uid, ids, value, context=None): """ onchange_partner_ids (value format: [[6, 0, [3, 4]]]). The basic purpose of this method is to check that destination partners @@ -218,7 +200,7 @@ class mail_compose_message(osv.TransientModel): res = {'value': {}} if not value or not value[0] or not value[0][0] == 6: return - res.update(self._verify_partner_email(cr, uid, value[0][2], context=context)) + res.update(self.verify_partner_email(cr, uid, value[0][2], context=context)) return res def unlink(self, cr, uid, ids, context=None): From a126eb72b7894f4d38943a63d4a0d3948fcf3067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 15:36:27 +0200 Subject: [PATCH 03/22] [ADD] Chatter: added Invite button and its behavior. It calls the Invite wizard. Added a read_value in mail_followers, to reload the follower values after subscribing, unsubscribing or adding followers through the wizard. bzr revid: tde@openerp.com-20120912133627-pid0uazohsx37trt --- addons/mail/static/src/css/mail.css | 4 -- addons/mail/static/src/js/mail_followers.js | 57 ++++++++++++------- addons/mail/static/src/xml/mail_followers.xml | 3 +- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 815f0ec92c4..a92f6c52832 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -96,10 +96,6 @@ width: 120px; } -.openerp button.oe_mail_button_followers { - display: inline; -} - .openerp button.oe_mail_button_mouseout { color: white; background-color: #8a89ba; diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index e5d216ed3d2..c1ef6d2c844 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -31,17 +31,9 @@ openerp_mail_followers = function(session, mail) { }, start: function() { - var self = this; - // NB: all the widget should be modified to check the actual_mode property on view, not use - // any other method to know if the view is in create mode anymore + // use actual_mode property on view to know if the view is in create mode anymore this.view.on("change:actual_mode", this, this._check_visibility); this._check_visibility(); - this.$el.find('button.oe_mail_button_follow').click(function () { self.do_follow(); }) - .mouseover(function () { $(this).html('Follow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); }) - .mouseleave(function () { $(this).html('Not following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); }); - this.$el.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); }) - .mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); }) - .mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); }); this.reinit(); }, @@ -49,15 +41,41 @@ openerp_mail_followers = function(session, mail) { this.$el.toggle(this.view.get("actual_mode") !== "create"); }, - destroy: function () { - this._super.apply(this, arguments); - }, - reinit: function() { this.$el.find('button.oe_mail_button_follow').hide(); this.$el.find('button.oe_mail_button_unfollow').hide(); }, + bind_events: function() { + var self = this; + this.$el.find('button.oe_mail_button_follow').on('click', function () { self.do_follow(); }) + this.$el.find('button.oe_mail_button_unfollow').on('click', function () { self.do_unfollow(); }) + .mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); }) + .mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); }); + this.$el.find('button.oe_mail_button_invite').on('click', function(event) { + action = { + type: 'ir.actions.act_window', + res_model: 'mail.wizard.invite', + view_mode: 'form', + view_type: 'form', + views: [[false, 'form']], + target: 'new', + context: { + 'default_res_model': self.view.dataset.model, + 'default_res_id': self.view.datarecord.id + }, + } + self.do_action(action, function() { self.read_value(); }); + }); + }, + + read_value: function() { + var self = this; + return this.ds_model.read_ids([this.view.datarecord.id], ['message_follower_ids']).pipe(function (results) { + return results[0].message_follower_ids; + }).pipe(this.proxy('set_value')); + }, + set_value: function(value_) { this.reinit(); if (! this.view.datarecord.id || @@ -65,11 +83,12 @@ openerp_mail_followers = function(session, mail) { this.$el.find('div.oe_mail_recthread_aside').hide(); return; } - return this.fetch_followers(value_); + this.bind_events(); + return this.fetch_followers(value_ || this.get_value()); }, fetch_followers: function (value_) { - return this.ds_follow.call('read', [value_ || this.get_value(), ['name', 'user_ids']]).then(this.proxy('display_followers')); + return this.ds_follow.call('read', [value_, ['name', 'user_ids']]).pipe(this.proxy('display_followers')); }, /** Display the followers, evaluate is_follower directly */ @@ -91,13 +110,13 @@ openerp_mail_followers = function(session, mail) { }, do_follow: function () { - var context = new session.web.CompoundContext(this.build_context(), {'read_back': true}); - return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('set_value')); + var context = new session.web.CompoundContext(this.build_context(), {}); + return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('read_value')); }, do_unfollow: function () { - var context = new session.web.CompoundContext(this.build_context(), {'read_back': true}); - return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('set_value')); + var context = new session.web.CompoundContext(this.build_context(), {}); + return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('read_value')); }, }); }; diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 39622f42abf..32ce34d48d1 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -7,7 +7,8 @@ -->
- + +
From 7392ef4283763dcebc00cd5154f909c58d0368bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 15:37:11 +0200 Subject: [PATCH 04/22] [CLEAN] mail_thread: no need th have its hack about returning the new value after subscribing or unsubscribing. bzr revid: tde@openerp.com-20120912133711-tlt4pqm1cejjq9pv --- addons/mail/mail_thread.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index c0d6ac90fe6..d798007275f 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -623,14 +623,8 @@ class mail_thread(osv.AbstractModel): return self.message_subscribe(cr, uid, ids, partner_ids, context=context) def message_subscribe(self, cr, uid, ids, partner_ids, context=None): - """ Add partners to the records followers. - :param partner_ids: a list of partner_ids to subscribe - :param return: new value of followers if read_back key in context - """ - self.write(cr, uid, ids, {'message_follower_ids': [(4, pid) for pid in partner_ids]}, context=context) - if context and context.get('read_back'): - return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids] - return [] + """ Add partners to the records followers. """ + return self.write(cr, uid, ids, {'message_follower_ids': [(4, pid) for pid in partner_ids]}, context=context) def message_unsubscribe_users(self, cr, uid, ids, user_ids=None, context=None): """ Wrapper on message_subscribe, using users. If user_ids is not @@ -640,14 +634,8 @@ class mail_thread(osv.AbstractModel): return self.message_unsubscribe(cr, uid, ids, partner_ids, context=context) def message_unsubscribe(self, cr, uid, ids, partner_ids, context=None): - """ Remove partners from the records followers. - :param partner_ids: a list of partner_ids to unsubscribe - :param return: new value of followers if read_back key in context - """ - self.write(cr, uid, ids, {'message_follower_ids': [(3, pid) for pid in partner_ids]}, context=context) - if context and context.get('read_back'): - return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids] - return [] + """ Remove partners from the records followers. """ + return self.write(cr, uid, ids, {'message_follower_ids': [(3, pid) for pid in partner_ids]}, context=context) #------------------------------------------------------ # Thread state From 01803926245d4d8a81464d9af4559cfcbd77cb43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 15:37:33 +0200 Subject: [PATCH 05/22] [ADD] mail: added wizard in __openerp__. bzr revid: tde@openerp.com-20120912133733-xh484b24txefyhjm --- addons/mail/__openerp__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/mail/__openerp__.py b/addons/mail/__openerp__.py index 99dd6bda6ac..e55baa9ed75 100644 --- a/addons/mail/__openerp__.py +++ b/addons/mail/__openerp__.py @@ -61,6 +61,7 @@ The main features of the module are: 'website': 'http://www.openerp.com', 'depends': ['base', 'base_tools', 'base_setup'], 'data': [ + 'wizard/invite_view.xml', 'wizard/mail_compose_message_view.xml', 'res_config_view.xml', 'mail_message_view.xml', From a16bf464f5f3492f26eb4958e109f10653b22051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 15:38:43 +0200 Subject: [PATCH 06/22] [IMP] mail: added a new behavior when sending notifications. Each notification can now be customized (subject, body); each partner to notify will receive a different ir_email. It is still the same mail_mail as a basis, but specific content can be send to partners (for example, portal links). Updated the tests as well.L bzr revid: tde@openerp.com-20120912133843-lltf7pzder386e2w --- addons/mail/mail_followers.py | 59 ++++++++++++----------- addons/mail/mail_mail.py | 85 +++++++++++++++++++++++----------- addons/mail/tests/test_mail.py | 57 ++++++++++++++++------- 3 files changed, 132 insertions(+), 69 deletions(-) diff --git a/addons/mail/mail_followers.py b/addons/mail/mail_followers.py index 2aba685c4fa..146dc4b257c 100644 --- a/addons/mail/mail_followers.py +++ b/addons/mail/mail_followers.py @@ -84,16 +84,44 @@ class mail_notification(osv.Model): notif_ids = self.search(cr, uid, [('partner_id', '=', partner_id), ('message_id', '=', msg_id)], context=context) return self.write(cr, uid, notif_ids, {'read': True}, context=context) + def get_partners_to_notify(self, cr, uid, partner_ids, message, context=None): + """ Return the list of partners to notify, based on their preferences. + + :param message: browse_record of a mail.message + """ + notify_pids = [] + for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context): + # Do not send an email to the writer + if partner.user_ids and partner.user_ids[0].id == uid: + continue + # Do not send to partners without email address defined + if not partner.email: + continue + # Partner does not want to receive any emails + if partner.notification_email_send == 'none': + continue + # Partner wants to receive only emails and comments + if partner.notification_email_send == 'comment' and message.type not in ('email', 'comment'): + continue + # Partner wants to receive only emails + if partner.notification_email_send == 'email' and message.type != 'email': + continue + notify_pids.append(partner.id) + return notify_pids + def notify(self, cr, uid, partner_ids, msg_id, context=None): """ Send by email the notification depending on the user preferences """ context = context or {} # mail_noemail (do not send email) or no partner_ids: do not send, return if context.get('mail_noemail') or not partner_ids: return True - - mail_mail = self.pool.get('mail.mail') msg = self.pool.get('mail.message').browse(cr, uid, msg_id, context=context) + notify_partner_ids = self.get_partners_to_notify(cr, uid, partner_ids, msg, context=context) + if not notify_partner_ids: + return True + + mail_mail = self.pool.get('mail.mail') # add signature body_html = msg.body signature = msg.author_id and msg.author_id.user_ids[0].signature or '' @@ -107,27 +135,6 @@ class mail_notification(osv.Model): 'body_html': body_html, 'state': 'outgoing', } - - for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context): - # Do not send an email to the writer - if partner.user_ids and partner.user_ids[0].id == uid: - continue - # Do not send to partners without email address defined - if not partner.email: - continue - # Partner does not want to receive any emails - if partner.notification_email_send == 'none': - continue - # Partner wants to receive only emails and comments - if partner.notification_email_send == 'comment' and msg.type not in ('email', 'comment'): - continue - # Partner wants to receive only emails - if partner.notification_email_send == 'email' and msg.type != 'email': - continue - if partner.email not in mail_values['email_to']: - mail_values['email_to'].append(partner.email) - if mail_values['email_to']: - mail_values['email_to'] = ', '.join(mail_values['email_to']) - email_notif_id = mail_mail.create(cr, uid, mail_values, context=context) - mail_mail.send(cr, uid, [email_notif_id], context=context) - return True + mail_values['email_to'] = ', '.join(mail_values['email_to']) + email_notif_id = mail_mail.create(cr, uid, mail_values, context=context) + return mail_mail.send(cr, uid, [email_notif_id], notifier_ids=notify_partner_ids, context=context) diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index 8d3f3ab6e01..1cb9efa98e1 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -137,14 +137,46 @@ class mail_mail(osv.Model): mail.unlink() return True - def _send_get_mail_subject(self, cr, uid, mail, force=False, context=None): + def _send_get_mail_subject(self, cr, uid, mail, force=False, partner=None, context=None): """ if void and related document: ' posted on ' - :param mail: mail.mail browse_record """ + + :param force: force the 'Author posted'... subject + :param mail: mail.mail browse_record + :param partner: browse_record of the specific recipient partner + """ if force or (not mail.subject and mail.model and mail.res_id): return '%s posted on %s' % (mail.author_id.name, mail.record_name) return mail.subject - def send(self, cr, uid, ids, auto_commit=False, context=None): + def _send_get_mail_body(self, cr, uid, mail, partner=None, context=None): + """ Return a specific ir_email body. The main purpose of this method + is to be inherited by Portal, to add a link for signing in, in + each notification email a partner receives. + + :param mail: mail.mail browse_record + :param partner: browse_record of the specific recipient partner + """ + return mail.body_html + + def _send_get_ir_email_dict(self, cr, uid, mail, partner=None, context=None): + """ Return a dictionary for specific ir_email values, depending on a + partner, or generic to the whole recipients given by mail.email_to. + + :param mail: mail.mail browse_record + :param partner: browse_record of the specific recipient partner + """ + body = self._send_get_mail_body(cr, uid, mail, partner=partner, context=context) + subject = self._send_get_mail_subject(cr, uid, mail, partner=partner, context=context) + body_alternative = tools.html2plaintext(body) + email_to = [partner.email] if partner else tools.email_split(mail.email_to) + return { + 'body': body, + 'body_alternative': body_alternative, + 'subject': subject, + 'email_to': email_to, + } + + def send(self, cr, uid, ids, auto_commit=False, notifier_ids=None, context=None): """ Sends the selected emails immediately, ignoring their current state (mails that have already been sent should not be passed unless they should actually be re-sent). @@ -160,35 +192,36 @@ class mail_mail(osv.Model): ir_mail_server = self.pool.get('ir.mail_server') for mail in self.browse(cr, uid, ids, context=context): try: - body = mail.body_html - subject = self._send_get_mail_subject(cr, uid, mail, context=context) - # handle attachments attachments = [] for attach in mail.attachment_ids: attachments.append((attach.datas_fname, base64.b64decode(attach.datas))) - - # use only sanitized html and set its plaintexted version as alternative - body_alternative = tools.html2plaintext(body) - content_subtype_alternative = 'plain' + # specific behavior to customize the send email for notified partners + ir_email_list = [] + if notifier_ids: + for partner in self.pool.get('res.partner').browse(cr, uid, notifier_ids, context=context): + ir_email_list.append(self._send_get_ir_email_dict(cr, uid, mail, partner=partner, context=context)) + else: + ir_email_list.append(self._send_get_ir_email_dict(cr, uid, mail, context=context)) # build an RFC2822 email.message.Message object and send it without queuing - msg = ir_mail_server.build_email( - email_from = mail.email_from, - email_to = tools.email_split(mail.email_to), - subject = subject, - body = body, - body_alternative = body_alternative, - email_cc = tools.email_split(mail.email_cc), - reply_to = mail.reply_to, - attachments = attachments, - message_id = mail.message_id, - references = mail.references, - object_id = mail.res_id and ('%s-%s' % (mail.res_id, mail.model)), - subtype = 'html', - subtype_alternative = content_subtype_alternative) - res = ir_mail_server.send_email(cr, uid, msg, - mail_server_id=mail.mail_server_id.id, context=context) + for ir_email in ir_email_list: + msg = ir_mail_server.build_email( + email_from = mail.email_from, + email_to = ir_email.get('email_to'), + subject = ir_email.get('subject'), + body = ir_email.get('body'), + body_alternative = ir_email.get('body_alternative'), + email_cc = tools.email_split(mail.email_cc), + reply_to = mail.reply_to, + attachments = attachments, + message_id = mail.message_id, + references = mail.references, + object_id = mail.res_id and ('%s-%s' % (mail.res_id, mail.model)), + subtype = 'html', + subtype_alternative = 'plain') + res = ir_mail_server.send_email(cr, uid, msg, + mail_server_id=mail.mail_server_id.id, context=context) if res: mail.write({'state': 'sent', 'message_id': res}) else: diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index f45745f31dc..24d7db67b54 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -19,6 +19,8 @@ # ############################################################################## +import tools + from openerp.tests import common from openerp.tools.html_sanitize import html_sanitize @@ -29,7 +31,7 @@ Received: by mail1.openerp.com (Postfix, from userid 10002) From: Sylvie Lelitre Subject: {subject} MIME-Version: 1.0 -Content-Type: multipart/alternative; +Content-Type: multipart/alternative; boundary="----=_Part_4200734_24778174.1344608186754" Date: Fri, 10 Aug 2012 14:16:26 +0000 Message-ID: <1198923581.41972151344608186760.JavaMail@agrolait.com> @@ -52,9 +54,9 @@ Content-Transfer-Encoding: quoted-printable =20 =20 - +

Please call me as soon as possible this afternoon!

- +

--
Sylvie

@@ -88,10 +90,19 @@ class test_mail(common.TransactionCase): return True def _mock_build_email(self, *args, **kwargs): - self._build_email_args = args - self._build_email_kwargs = kwargs + self._build_email_args_list.append(args) + self._build_email_kwargs_list.append(kwargs) return self.build_email_real(*args, **kwargs) + def _init_mock_build_email(self): + self._build_email_args_list = [] + self._build_email_kwargs_list = [] + + def _mock_send_get_mail_body(self, *args, **kwargs): + # def _send_get_mail_body(self, cr, uid, mail, partner=None, context=None) + body = tools.append_content_to_html(args[2].body_html, kwargs.get('partner').name if kwargs.get('partner') else 'No specific partner') + return body + def setUp(self): super(test_mail, self).setUp() self.ir_model = self.registry('ir.model') @@ -106,10 +117,14 @@ class test_mail(common.TransactionCase): self.res_partner = self.registry('res.partner') # Install mock SMTP gateway + self._init_mock_build_email() self.build_email_real = self.registry('ir.mail_server').build_email self.registry('ir.mail_server').build_email = self._mock_build_email self.registry('ir.mail_server').send_email = self._mock_smtp_gateway + # Mock _send_get_mail_body to test its functionality without other addons override + self.registry('mail.mail')._send_get_mail_body = self._mock_send_get_mail_body + # groups@.. will cause the creation of new mail groups self.mail_group_model_id = self.ir_model.search(self.cr, self.uid, [('model', '=', 'mail.group')])[0] self.mail_alias.create(self.cr, self.uid, {'alias_name': 'groups', @@ -153,7 +168,7 @@ class test_mail(common.TransactionCase): test_msg_id = '' mail_text = MAIL_TEMPLATE_PLAINTEXT.format(to='groups@example.com', subject='frogs', extra='', msg_id=test_msg_id) self.mail_thread.message_process(cr, uid, None, mail_text) - new_mail = self.mail_message.browse(cr, uid, self.mail_message.search(cr, uid, [('message_id','=',test_msg_id)])[0]) + new_mail = self.mail_message.browse(cr, uid, self.mail_message.search(cr, uid, [('message_id', '=', test_msg_id)])[0]) self.assertEqual(new_mail.body, '\n

\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n
\n', 'plaintext mail incorrectly parsed') @@ -274,18 +289,20 @@ class test_mail(common.TransactionCase): _attachments = [('First', 'My first attachment'), ('Second', 'My second attachment')] # CASE1: post comment, body and subject specified + self._init_mock_build_email() msg_id = self.mail_group.message_post(cr, uid, self.group_pigs_id, body=_body1, subject=_subject, type='comment') message = self.mail_message.browse(cr, uid, msg_id) - sent_email = self._build_email_kwargs + sent_emails = self._build_email_kwargs_list # Test: notifications have been deleted self.assertFalse(self.mail_mail.search(cr, uid, [('mail_message_id', '=', msg_id)]), 'mail.mail notifications should have been auto-deleted!') # Test: mail_message: subject is _subject, body is _body1 (no formatting done) self.assertEqual(message.subject, _subject, 'mail.message subject incorrect') self.assertEqual(message.body, _body1, 'mail.message body incorrect') - # Test: sent_email: email send by server: correct subject, body; body_alternative - self.assertEqual(sent_email['subject'], _subject, 'sent_email subject incorrect') - self.assertEqual(sent_email['body'], _mail_body1, 'sent_email body incorrect') - self.assertEqual(sent_email['body_alternative'], _mail_bodyalt1, 'sent_email body_alternative is incorrect') + # Test: sent_email: email send by server: correct subject, body, body_alternative + for sent_email in sent_emails: + self.assertEqual(sent_email['subject'], _subject, 'sent_email subject incorrect') + self.assertEqual(sent_email['body'], _mail_body1 + '\n
Bert Tartopoils
\n', 'sent_email body incorrect') + self.assertEqual(sent_email['body_alternative'], _mail_bodyalt1 + '\nBert Tartopoils', 'sent_email body_alternative is incorrect') # Test: mail_message: partner_ids = group followers message_pids = set([partner.id for partner in message.partner_ids]) test_pids = set([p_a_id, p_b_id, p_c_id]) @@ -295,14 +312,16 @@ class test_mail(common.TransactionCase): notif_pids = set([notif.partner_id.id for notif in self.mail_notification.browse(cr, uid, notif_ids)]) self.assertEqual(notif_pids, test_pids, 'mail.message notification partners incorrect') # Test: sent_email: email_to should contain b@b, not c@c (pref email), not a@a (writer) - self.assertEqual(sent_email['email_to'], ['b@b'], 'sent_email email_to is incorrect') + for sent_email in sent_emails: + self.assertEqual(sent_email['email_to'], ['b@b'], 'sent_email email_to is incorrect') # CASE2: post an email with attachments, parent_id, partner_ids # TESTS: automatic subject, signature in body_html, attachments propagation + self._init_mock_build_email() msg_id2 = self.mail_group.message_post(cr, uid, self.group_pigs_id, body=_body2, type='email', partner_ids=[(6, 0, [p_d_id])], parent_id=msg_id, attachments=_attachments) message = self.mail_message.browse(cr, uid, msg_id2) - sent_email = self._build_email_kwargs + sent_emails = self._build_email_kwargs_list self.assertFalse(self.mail_mail.search(cr, uid, [('mail_message_id', '=', msg_id2)]), 'mail.mail notifications should have been auto-deleted!') # Test: mail_message: subject is False, body is _body2 (no formatting done), parent_id is msg_id @@ -310,9 +329,11 @@ class test_mail(common.TransactionCase): self.assertEqual(message.body, html_sanitize(_body2), 'mail.message body incorrect') self.assertEqual(message.parent_id.id, msg_id, 'mail.message parent_id incorrect') # Test: sent_email: email send by server: correct subject, body, body_alternative - self.assertEqual(sent_email['subject'], _mail_subject, 'sent_email subject incorrect') - self.assertEqual(sent_email['body'], _mail_body2, 'sent_email body incorrect') - self.assertEqual(sent_email['body_alternative'], _mail_bodyalt2, 'sent_email body_alternative incorrect') + self.assertEqual(len(sent_emails), 2, 'sent_email number of sent emails incorrect') + for sent_email in sent_emails: + self.assertEqual(sent_email['subject'], _mail_subject, 'sent_email subject incorrect') + self.assertIn(_mail_body2, sent_email['body'], 'sent_email body incorrect') + self.assertIn(_mail_bodyalt2, sent_email['body_alternative'], 'sent_email body_alternative incorrect') # Test: mail_message: partner_ids = group followers message_pids = set([partner.id for partner in message.partner_ids]) test_pids = set([p_a_id, p_b_id, p_c_id, p_d_id]) @@ -322,7 +343,8 @@ class test_mail(common.TransactionCase): notif_pids = set([notif.partner_id.id for notif in self.mail_notification.browse(cr, uid, notif_ids)]) self.assertEqual(notif_pids, test_pids, 'mail.message notification partners incorrect') # Test: sent_email: email_to should contain b@b, c@c, not a@a (writer) - self.assertEqual(set(sent_email['email_to']), set(['b@b', 'c@c']), 'sent_email email_to incorrect') + for sent_email in sent_emails: + self.assertTrue(set(sent_email['email_to']).issubset(set(['b@b', 'c@c'])), 'sent_email email_to incorrect') # Test: attachments for attach in message.attachment_ids: self.assertEqual(attach.res_model, 'mail.group', 'mail.message attachment res_model incorrect') @@ -458,6 +480,7 @@ class test_mail(common.TransactionCase): # It will be updated as soon as we have fixed specs ! cr, uid = self.cr, self.uid group_pigs = self.mail_group.browse(cr, uid, self.group_pigs_id) + def _compare_structures(struct1, struct2, n=0): # print '%scompare structure' % ('\t' * n) self.assertEqual(len(struct1), len(struct2), 'message_read structure number of childs incorrect') From 30fb693c20745bb2e656732d7a6893b800ae0351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 17:53:00 +0200 Subject: [PATCH 07/22] [IMP] Portal: override of mail_mail to add the signin link into footer of send notifications. bzr revid: tde@openerp.com-20120912155300-8ilg2g24yl7qsjfg --- addons/mail/mail_mail.py | 14 +++++------ addons/portal/__init__.py | 1 + addons/portal/mail_mail.py | 50 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 addons/portal/mail_mail.py diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index 1cb9efa98e1..cf86c39f273 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -137,7 +137,7 @@ class mail_mail(osv.Model): mail.unlink() return True - def _send_get_mail_subject(self, cr, uid, mail, force=False, partner=None, context=None): + def send_get_mail_subject(self, cr, uid, mail, force=False, partner=None, context=None): """ if void and related document: ' posted on ' :param force: force the 'Author posted'... subject @@ -148,7 +148,7 @@ class mail_mail(osv.Model): return '%s posted on %s' % (mail.author_id.name, mail.record_name) return mail.subject - def _send_get_mail_body(self, cr, uid, mail, partner=None, context=None): + def send_get_mail_body(self, cr, uid, mail, partner=None, context=None): """ Return a specific ir_email body. The main purpose of this method is to be inherited by Portal, to add a link for signing in, in each notification email a partner receives. @@ -158,15 +158,15 @@ class mail_mail(osv.Model): """ return mail.body_html - def _send_get_ir_email_dict(self, cr, uid, mail, partner=None, context=None): + def send_get_ir_email_dict(self, cr, uid, mail, partner=None, context=None): """ Return a dictionary for specific ir_email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param mail: mail.mail browse_record :param partner: browse_record of the specific recipient partner """ - body = self._send_get_mail_body(cr, uid, mail, partner=partner, context=context) - subject = self._send_get_mail_subject(cr, uid, mail, partner=partner, context=context) + body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) + subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) email_to = [partner.email] if partner else tools.email_split(mail.email_to) return { @@ -200,9 +200,9 @@ class mail_mail(osv.Model): ir_email_list = [] if notifier_ids: for partner in self.pool.get('res.partner').browse(cr, uid, notifier_ids, context=context): - ir_email_list.append(self._send_get_ir_email_dict(cr, uid, mail, partner=partner, context=context)) + ir_email_list.append(self.send_get_ir_email_dict(cr, uid, mail, partner=partner, context=context)) else: - ir_email_list.append(self._send_get_ir_email_dict(cr, uid, mail, context=context)) + ir_email_list.append(self.send_get_ir_email_dict(cr, uid, mail, context=context)) # build an RFC2822 email.message.Message object and send it without queuing for ir_email in ir_email_list: diff --git a/addons/portal/__init__.py b/addons/portal/__init__.py index 9c6cc59be7d..2bfc6df0d96 100644 --- a/addons/portal/__init__.py +++ b/addons/portal/__init__.py @@ -20,6 +20,7 @@ ############################################################################## import portal +import mail_mail import wizard diff --git a/addons/portal/mail_mail.py b/addons/portal/mail_mail.py new file mode 100644 index 00000000000..d7f4d05d5ac --- /dev/null +++ b/addons/portal/mail_mail.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 OpenERP S.A (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import tools +from osv import osv + + +class mail_mail_portal(osv.Model): + """ Update of mail_mail class, to add the signin URL to notifications. + """ + _name = 'mail.mail' + _inherit = ['mail.mail'] + + def _generate_portal_url(self, cr, uid, partner_id, portal_group_id, key, context=None): + """ . """ + base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='', context=context) + return base_url + '/login?action=signin&partner_id=%s&group=%s&key=%s' % (partner_id, portal_group_id, key) + + def send_get_mail_body(self, cr, uid, mail, partner=None, context=None): + """ Return a specific ir_email body. The main purpose of this method + is to be inherited by Portal, to add a link for signing in, in + each notification email a partner receives. + + :param mail: mail.mail browse_record + :param partner: browse_record of the specific recipient partner + """ + if partner: + url = self._generate_portal_url(cr, uid, partner.id, 12, 1234, context=context) + body = tools.append_content_to_html(mail.body_html, url) + return body + else: + return super(mail_mail_portal, self).send_get_mail_body(cr, uid, mail, partner=partner, context=context) From 918dc35da53232569e67caeb8256bb6e9f9608bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 17:53:13 +0200 Subject: [PATCH 08/22] [ADD] Portal: added skeleton files for tests. bzr revid: tde@openerp.com-20120912155313-xhx6hqyfr85t0ncw --- addons/portal/tests/__init__.py | 27 ++++++++++++++ addons/portal/tests/test_portal.py | 59 ++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 addons/portal/tests/__init__.py create mode 100644 addons/portal/tests/test_portal.py diff --git a/addons/portal/tests/__init__.py b/addons/portal/tests/__init__.py new file mode 100644 index 00000000000..c4717f80ebf --- /dev/null +++ b/addons/portal/tests/__init__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import test_portal + +checks = [ + test_portal, +] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/portal/tests/test_portal.py b/addons/portal/tests/test_portal.py new file mode 100644 index 00000000000..93b9d220149 --- /dev/null +++ b/addons/portal/tests/test_portal.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.tests import common + + +class test_portal(common.TransactionCase): + + def _mock_smtp_gateway(self, *args, **kwargs): + return True + + def _mock_build_email(self, *args, **kwargs): + self._build_email_args_list.append(args) + self._build_email_kwargs_list.append(kwargs) + return self.build_email_real(*args, **kwargs) + + def _init_mock_build_email(self): + self._build_email_args_list = [] + self._build_email_kwargs_list = [] + + def setUp(self): + super(test_portal, self).setUp() + self.ir_model = self.registry('ir.model') + self.mail_group = self.registry('mail.group') + self.mail_mail = self.registry('mail.mail') + self.res_users = self.registry('res.users') + self.res_partner = self.registry('res.partner') + + # Install mock SMTP gateway + self._init_mock_build_email() + self.build_email_real = self.registry('ir.mail_server').build_email + self.registry('ir.mail_server').build_email = self._mock_build_email + self.registry('ir.mail_server').send_email = self._mock_smtp_gateway + + # create a 'pigs' group that will be used through the various tests + self.group_pigs_id = self.mail_group.create(self.cr, self.uid, + {'name': 'Pigs', 'description': 'Fans of Pigs, unite !'}) + + def test_00_mail_invite(self): + cr, uid = self.cr, self.uid + print 'cacaprout' From a1dec2072a5c02cac601f0c1b1590ccb39fa124e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 18:13:49 +0200 Subject: [PATCH 09/22] [FIX] Fixed test mocking wrong method. bzr revid: tde@openerp.com-20120912161349-ya5jvplze9ke3rtr --- addons/mail/tests/test_mail.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index f5a0fa9d592..39f69ff0a68 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -122,8 +122,8 @@ class test_mail(common.TransactionCase): self.registry('ir.mail_server').build_email = self._mock_build_email self.registry('ir.mail_server').send_email = self._mock_smtp_gateway - # Mock _send_get_mail_body to test its functionality without other addons override - self.registry('mail.mail')._send_get_mail_body = self._mock_send_get_mail_body + # Mock send_get_mail_body to test its functionality without other addons override + self.registry('mail.mail').send_get_mail_body = self._mock_send_get_mail_body # groups@.. will cause the creation of new mail groups self.mail_group_model_id = self.ir_model.search(self.cr, self.uid, [('model', '=', 'mail.group')])[0] From e7a24e7350efc7f38ad32df604cfdb813cfe452f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Sep 2012 18:36:18 +0200 Subject: [PATCH 10/22] [IMP] mail: invite wizard: added default message; added email send to the newly added followers. bzr revid: tde@openerp.com-20120912163618-rp67taqr24zp2yei --- addons/mail/wizard/invite.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/addons/mail/wizard/invite.py b/addons/mail/wizard/invite.py index 71ae23304a8..4644dc1e55b 100644 --- a/addons/mail/wizard/invite.py +++ b/addons/mail/wizard/invite.py @@ -21,6 +21,7 @@ from osv import osv from osv import fields +from tools.translate import _ class invite_wizard(osv.osv_memory): @@ -38,6 +39,13 @@ class invite_wizard(osv.osv_memory): 'message': fields.text('Message'), } + _defaults = { + 'message': lambda s, *a, **k: s._get_default_message(*a, **k), + } + + def _get_default_message(self, cr, uid, context=None): + return _('You have been invited to follow a new document.') + def onchange_partner_ids(self, cr, uid, ids, value, context=None): """ onchange_partner_ids (value format: [[6, 0, [3, 4]]]). The basic purpose of this method is to check that destination partners @@ -52,5 +60,19 @@ class invite_wizard(osv.osv_memory): def add_followers(self, cr, uid, ids, context=None): for wizard in self.browse(cr, uid, ids, context=context): model_obj = self.pool.get(wizard.res_model) - model_obj.message_subscribe(cr, uid, [wizard.res_id], [p.id for p in wizard.partner_ids], context=context) + document = model_obj.browse(cr, uid, wizard.res_id, context=context) + + # filter partner_ids to get the new followers, to avoid sending email to already following partners + new_follower_ids = [p.id for p in wizard.partner_ids if p.id not in document.message_follower_ids] + model_obj.message_subscribe(cr, uid, [wizard.res_id], new_follower_ids, context=context) + + # send an email + if wizard.message: + for follower_id in new_follower_ids: + mail_mail = self.pool.get('mail.mail') + mail_id = mail_mail.create(cr, uid, { + 'body_html': '
%s
' % wizard.message, + 'auto_delete': True, + }, context=context) + mail_mail.send(cr, uid, [mail_id], notifier_ids=[follower_id], context=context) return {'type': 'ir.actions.act_window_close'} From 13583b36d3cd94cf1687ddd82d2b4bfe7a216dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 13 Sep 2012 10:41:19 +0200 Subject: [PATCH 11/22] [FIX] mail, portal: fixed tests to remove mockups at tearDown. Otherwise, when using tests, no email could be send because of the mockups installed during tests. bzr revid: tde@openerp.com-20120913084119-6ligp3o864vtzlmz --- addons/mail/tests/test_mail.py | 22 +++++++++++++++------- addons/portal/tests/test_portal.py | 11 +++++++++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index 39f69ff0a68..bf9520f0e68 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -89,15 +89,15 @@ class test_mail(common.TransactionCase): def _mock_smtp_gateway(self, *args, **kwargs): return True - def _mock_build_email(self, *args, **kwargs): - self._build_email_args_list.append(args) - self._build_email_kwargs_list.append(kwargs) - return self.build_email_real(*args, **kwargs) - def _init_mock_build_email(self): self._build_email_args_list = [] self._build_email_kwargs_list = [] + def _mock_build_email(self, *args, **kwargs): + self._build_email_args_list.append(args) + self._build_email_kwargs_list.append(kwargs) + return self._build_email(*args, **kwargs) + def _mock_send_get_mail_body(self, *args, **kwargs): # def _send_get_mail_body(self, cr, uid, mail, partner=None, context=None) body = tools.append_content_to_html(args[2].body_html, kwargs.get('partner').name if kwargs.get('partner') else 'No specific partner') @@ -118,11 +118,12 @@ class test_mail(common.TransactionCase): # Install mock SMTP gateway self._init_mock_build_email() - self.build_email_real = self.registry('ir.mail_server').build_email + self._build_email = self.registry('ir.mail_server').build_email self.registry('ir.mail_server').build_email = self._mock_build_email + self._send_email = self.registry('ir.mail_server').send_email self.registry('ir.mail_server').send_email = self._mock_smtp_gateway - # Mock send_get_mail_body to test its functionality without other addons override + self._send_get_mail_body = self.registry('mail.mail').send_get_mail_body self.registry('mail.mail').send_get_mail_body = self._mock_send_get_mail_body # groups@.. will cause the creation of new mail groups @@ -133,6 +134,13 @@ class test_mail(common.TransactionCase): self.group_pigs_id = self.mail_group.create(self.cr, self.uid, {'name': 'Pigs', 'description': 'Fans of Pigs, unite !'}) + def tearDown(self): + # Remove mocks + self.registry('ir.mail_server').build_email = self._build_email + self.registry('ir.mail_server').send_email = self._send_email + self.registry('mail.mail').send_get_mail_body = self._send_get_mail_body + super(test_mail, self).tearDown() + def test_00_message_process(self): cr, uid = self.cr, self.uid # Incoming mail creates a new mail_group "frogs" diff --git a/addons/portal/tests/test_portal.py b/addons/portal/tests/test_portal.py index 93b9d220149..b98614de5e9 100644 --- a/addons/portal/tests/test_portal.py +++ b/addons/portal/tests/test_portal.py @@ -30,7 +30,7 @@ class test_portal(common.TransactionCase): def _mock_build_email(self, *args, **kwargs): self._build_email_args_list.append(args) self._build_email_kwargs_list.append(kwargs) - return self.build_email_real(*args, **kwargs) + return self._build_email(*args, **kwargs) def _init_mock_build_email(self): self._build_email_args_list = [] @@ -46,14 +46,21 @@ class test_portal(common.TransactionCase): # Install mock SMTP gateway self._init_mock_build_email() - self.build_email_real = self.registry('ir.mail_server').build_email + self._build_email = self.registry('ir.mail_server').build_email self.registry('ir.mail_server').build_email = self._mock_build_email + self._send_email = self.registry('ir.mail_server').send_email self.registry('ir.mail_server').send_email = self._mock_smtp_gateway # create a 'pigs' group that will be used through the various tests self.group_pigs_id = self.mail_group.create(self.cr, self.uid, {'name': 'Pigs', 'description': 'Fans of Pigs, unite !'}) + def tearDown(self): + # Remove mocks + self.registry('ir.mail_server').build_email = self._build_email + self.registry('ir.mail_server').send_email = self._send_email + super(test_portal, self).tearDown() + def test_00_mail_invite(self): cr, uid = self.cr, self.uid print 'cacaprout' From 02668c368230b420159ec7c67e631bba2c6cbb84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 13 Sep 2012 11:32:46 +0200 Subject: [PATCH 12/22] [IMP] mail_group: when deleting a mail_group, delete also the related menu entry. bzr revid: tde@openerp.com-20120913093246-kkxjqspupbq7j7z8 --- addons/mail/mail_group.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index 175ce650f06..fe0cc3950ae 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -19,13 +19,11 @@ # ############################################################################## -import datetime as DT import openerp import openerp.tools as tools -from operator import itemgetter from osv import osv from osv import fields -from tools.translate import _ + class mail_group(osv.Model): """ A mail_group is a collection of users sharing messages in a discussion @@ -47,7 +45,7 @@ class mail_group(osv.Model): _columns = { 'description': fields.text('Description'), 'menu_id': fields.many2one('ir.ui.menu', string='Related Menu', required=True, ondelete="cascade"), - 'public': fields.selection([('public','Public'),('private','Private'),('groups','Selected Group Only')], 'Privacy', required=True, + 'public': fields.selection([('public', 'Public'), ('private', 'Private'), ('groups', 'Selected Group Only')], 'Privacy', required=True, help='This group is visible by non members. \ Invisible groups can add members through the invite button.'), 'group_public_id': fields.many2one('res.groups', string='Authorized Group'), @@ -126,14 +124,14 @@ class mail_group(osv.Model): search_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'view_message_search') params = { 'search_view_id': search_ref and search_ref[1] or False, - 'domain': [('model','=','mail.group'), ('res_id','=',mail_group_id)], + 'domain': [('model', '=', 'mail.group'), ('res_id', '=', mail_group_id)], 'context': {'default_model': 'mail.group', 'default_res_id': mail_group_id}, 'res_model': 'mail.message', 'thread_level': 1, } cobj = self.pool.get('ir.actions.client') newref = cobj.copy(cr, uid, ref[1], default={'params': str(params), 'name': vals['name']}, context=context) - self.write(cr, uid, [mail_group_id], {'action': 'ir.actions.client,'+str(newref), 'mail_group_id': mail_group_id}, context=context) + self.write(cr, uid, [mail_group_id], {'action': 'ir.actions.client,' + str(newref), 'mail_group_id': mail_group_id}, context=context) mail_alias.write(cr, uid, [vals['alias_id']], {"alias_force_thread_id": mail_group_id}, context) @@ -142,9 +140,13 @@ class mail_group(osv.Model): return mail_group_id def unlink(self, cr, uid, ids, context=None): + groups = self.browse(cr, uid, ids, context=context) # Cascade-delete mail aliases as well, as they should not exist without the mail group. mail_alias = self.pool.get('mail.alias') - alias_ids = [group.alias_id.id for group in self.browse(cr, uid, ids, context=context) if group.alias_id] + alias_ids = [group.alias_id.id for group in groups if group.alias_id] + # Cascade-delete menu entries as well + self.pool.get('ir.ui.menu').unlink(cr, uid, [group.menu_id.id for group in groups if group.menu_id], context=context) + # Delete mail_group res = super(mail_group, self).unlink(cr, uid, ids, context=context) mail_alias.unlink(cr, uid, alias_ids, context=context) return res From b1839623476824bd0f2e848039e1ff845da59092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 13 Sep 2012 11:33:20 +0200 Subject: [PATCH 13/22] [IMP] mail_wizard_invite: updated default message. An override of default_get allows to have a more precise message. bzr revid: tde@openerp.com-20120913093320-mhwp43kkgoqd0h33 --- addons/mail/wizard/invite.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/addons/mail/wizard/invite.py b/addons/mail/wizard/invite.py index 4644dc1e55b..a63608d5a23 100644 --- a/addons/mail/wizard/invite.py +++ b/addons/mail/wizard/invite.py @@ -29,6 +29,16 @@ class invite_wizard(osv.osv_memory): _name = 'mail.wizard.invite' _description = 'Invite wizard' + def default_get(self, cr, uid, fields, context=None): + result = super(invite_wizard, self).default_get(cr, uid, fields, context=context) + if 'message' in fields and result.get('res_model') and result.get('res_id'): + document_name = self.pool.get(result.get('res_model')).name_get(cr, uid, [result.get('res_id')], context=context)[0][1] + message = _('You have been invited to follow %s.' % document_name) + result['message'] = message + elif 'message' in fields: + result['message'] = _('You have been invited to follow a new document.') + return result + _columns = { 'res_model': fields.char('Related Document Model', size=128, required=True, select=1, @@ -39,13 +49,6 @@ class invite_wizard(osv.osv_memory): 'message': fields.text('Message'), } - _defaults = { - 'message': lambda s, *a, **k: s._get_default_message(*a, **k), - } - - def _get_default_message(self, cr, uid, context=None): - return _('You have been invited to follow a new document.') - def onchange_partner_ids(self, cr, uid, ids, value, context=None): """ onchange_partner_ids (value format: [[6, 0, [3, 4]]]). The basic purpose of this method is to check that destination partners From 8868fa2810ea449f7fb81e72ccb0cd2219838ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 13 Sep 2012 12:33:19 +0200 Subject: [PATCH 14/22] [IMP] mail_wizard_invite: message is now an html field, and default values embedded inside a div. Added a subject to email sent to newly added followers. bzr revid: tde@openerp.com-20120913103319-6jg5moa0tl9p6ujn --- addons/mail/wizard/invite.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/mail/wizard/invite.py b/addons/mail/wizard/invite.py index a63608d5a23..9734a595d7a 100644 --- a/addons/mail/wizard/invite.py +++ b/addons/mail/wizard/invite.py @@ -33,10 +33,10 @@ class invite_wizard(osv.osv_memory): result = super(invite_wizard, self).default_get(cr, uid, fields, context=context) if 'message' in fields and result.get('res_model') and result.get('res_id'): document_name = self.pool.get(result.get('res_model')).name_get(cr, uid, [result.get('res_id')], context=context)[0][1] - message = _('You have been invited to follow %s.' % document_name) + message = _('
You have been invited to follow %s.
' % document_name) result['message'] = message elif 'message' in fields: - result['message'] = _('You have been invited to follow a new document.') + result['message'] = _('
You have been invited to follow a new document.
') return result _columns = { @@ -46,7 +46,7 @@ class invite_wizard(osv.osv_memory): 'res_id': fields.integer('Related Document ID', select=1, help='Id of the followed resource'), 'partner_ids': fields.many2many('res.partner', string='Partners'), - 'message': fields.text('Message'), + 'message': fields.html('Message'), } def onchange_partner_ids(self, cr, uid, ids, value, context=None): @@ -74,7 +74,8 @@ class invite_wizard(osv.osv_memory): for follower_id in new_follower_ids: mail_mail = self.pool.get('mail.mail') mail_id = mail_mail.create(cr, uid, { - 'body_html': '
%s
' % wizard.message, + 'subject': 'Invitation to follow %s' % document.name_get()[0][1], + 'body_html': '%s' % wizard.message, 'auto_delete': True, }, context=context) mail_mail.send(cr, uid, [mail_id], notifier_ids=[follower_id], context=context) From 01f6ac8d16080258fdd403b33c0d2147af1750f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 13 Sep 2012 12:34:01 +0200 Subject: [PATCH 15/22] [FIX] portal invite wizard: generated URL improvement (partner_id and portal_group_id should be correct now). bzr revid: tde@openerp.com-20120913103401-waepkmjq8flsu13j --- addons/portal/mail_mail.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/portal/mail_mail.py b/addons/portal/mail_mail.py index d7f4d05d5ac..813e31545e8 100644 --- a/addons/portal/mail_mail.py +++ b/addons/portal/mail_mail.py @@ -43,7 +43,9 @@ class mail_mail_portal(osv.Model): :param partner: browse_record of the specific recipient partner """ if partner: - url = self._generate_portal_url(cr, uid, partner.id, 12, 1234, context=context) + portal_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal', 'portal') + portal_id = portal_ref and portal_ref[1] or False + url = self._generate_portal_url(cr, uid, partner.id, portal_id, 1234, context=context) body = tools.append_content_to_html(mail.body_html, url) return body else: From 25734f2cfd0bb270e4834a2d0c77511795550fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 13 Sep 2012 12:35:29 +0200 Subject: [PATCH 16/22] [IMP] mail, portal: improved tests. A new TestMailMockup class has been defined, holding the various mockups for the mail gateway, to avoid having duplicate code in tests using emails. Added tests in portal about the invite mechanism. bzr revid: tde@openerp.com-20120913103529-410g9sk32sbbmkgn --- addons/mail/tests/test_mail.py | 28 ++++++++----- addons/portal/tests/test_portal.py | 65 +++++++++++++++++------------- 2 files changed, 56 insertions(+), 37 deletions(-) diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index bf9520f0e68..1fab5dd1732 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -84,7 +84,7 @@ Sylvie """ -class test_mail(common.TransactionCase): +class TestMailMockups(common.TransactionCase): def _mock_smtp_gateway(self, *args, **kwargs): return True @@ -98,6 +98,24 @@ class test_mail(common.TransactionCase): self._build_email_kwargs_list.append(kwargs) return self._build_email(*args, **kwargs) + def setUp(self): + super(TestMailMockups, self).setUp() + # Install mock SMTP gateway + self._init_mock_build_email() + self._build_email = self.registry('ir.mail_server').build_email + self.registry('ir.mail_server').build_email = self._mock_build_email + self._send_email = self.registry('ir.mail_server').send_email + self.registry('ir.mail_server').send_email = self._mock_smtp_gateway + + def tearDown(self): + # Remove mocks + self.registry('ir.mail_server').build_email = self._build_email + self.registry('ir.mail_server').send_email = self._send_email + super(TestMailMockups, self).tearDown() + + +class test_mail(TestMailMockups): + def _mock_send_get_mail_body(self, *args, **kwargs): # def _send_get_mail_body(self, cr, uid, mail, partner=None, context=None) body = tools.append_content_to_html(args[2].body_html, kwargs.get('partner').name if kwargs.get('partner') else 'No specific partner') @@ -116,12 +134,6 @@ class test_mail(common.TransactionCase): self.res_users = self.registry('res.users') self.res_partner = self.registry('res.partner') - # Install mock SMTP gateway - self._init_mock_build_email() - self._build_email = self.registry('ir.mail_server').build_email - self.registry('ir.mail_server').build_email = self._mock_build_email - self._send_email = self.registry('ir.mail_server').send_email - self.registry('ir.mail_server').send_email = self._mock_smtp_gateway # Mock send_get_mail_body to test its functionality without other addons override self._send_get_mail_body = self.registry('mail.mail').send_get_mail_body self.registry('mail.mail').send_get_mail_body = self._mock_send_get_mail_body @@ -136,8 +148,6 @@ class test_mail(common.TransactionCase): def tearDown(self): # Remove mocks - self.registry('ir.mail_server').build_email = self._build_email - self.registry('ir.mail_server').send_email = self._send_email self.registry('mail.mail').send_get_mail_body = self._send_get_mail_body super(test_mail, self).tearDown() diff --git a/addons/portal/tests/test_portal.py b/addons/portal/tests/test_portal.py index b98614de5e9..5f2875711df 100644 --- a/addons/portal/tests/test_portal.py +++ b/addons/portal/tests/test_portal.py @@ -19,22 +19,12 @@ # ############################################################################## -from openerp.tests import common +from openerp.addons.mail.tests import test_mail +# from openerp.tests import common +from openerp.tools import append_content_to_html -class test_portal(common.TransactionCase): - - def _mock_smtp_gateway(self, *args, **kwargs): - return True - - def _mock_build_email(self, *args, **kwargs): - self._build_email_args_list.append(args) - self._build_email_kwargs_list.append(kwargs) - return self._build_email(*args, **kwargs) - - def _init_mock_build_email(self): - self._build_email_args_list = [] - self._build_email_kwargs_list = [] +class test_portal(test_mail.TestMailMockups): def setUp(self): super(test_portal, self).setUp() @@ -44,23 +34,42 @@ class test_portal(common.TransactionCase): self.res_users = self.registry('res.users') self.res_partner = self.registry('res.partner') - # Install mock SMTP gateway - self._init_mock_build_email() - self._build_email = self.registry('ir.mail_server').build_email - self.registry('ir.mail_server').build_email = self._mock_build_email - self._send_email = self.registry('ir.mail_server').send_email - self.registry('ir.mail_server').send_email = self._mock_smtp_gateway - # create a 'pigs' group that will be used through the various tests self.group_pigs_id = self.mail_group.create(self.cr, self.uid, {'name': 'Pigs', 'description': 'Fans of Pigs, unite !'}) - def tearDown(self): - # Remove mocks - self.registry('ir.mail_server').build_email = self._build_email - self.registry('ir.mail_server').send_email = self._send_email - super(test_portal, self).tearDown() - def test_00_mail_invite(self): cr, uid = self.cr, self.uid - print 'cacaprout' + user_admin = self.res_users.browse(cr, uid, uid) + self.mail_invite = self.registry('mail.wizard.invite') + base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='') + portal_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'portal', 'portal') + portal_id = portal_ref and portal_ref[1] or False + + # 0 - Admin + p_a_id = user_admin.partner_id.id + # 1 - Bert Tartopoils, with email, should receive emails for comments and emails + p_b_id = self.res_partner.create(cr, uid, {'name': 'Bert Tartopoils', 'email': 'b@b'}) + + # ---------------------------------------- + # CASE1: invite Bert + # ---------------------------------------- + + _sent_email_subject = 'Invitation to follow Pigs' + _sent_email_body = append_content_to_html('
You have been invited to follow Pigs.
', + base_url + '/login?action=signin&partner_id=%s&group=%s&key=%s' % (p_b_id, portal_id, 1234)) + + # Do: create a mail_wizard_invite, validate it + self._init_mock_build_email() + mail_invite_id = self.mail_invite.create(cr, uid, {'partner_ids': [(4, p_b_id)]}, {'default_res_model': 'mail.group', 'default_res_id': self.group_pigs_id}) + self.mail_invite.add_followers(cr, uid, [mail_invite_id]) + group_pigs = self.mail_group.browse(cr, uid, self.group_pigs_id) + + # Test: Pigs followers should contain Admin and Bert + follower_ids = [follower.id for follower in group_pigs.message_follower_ids] + self.assertEqual(set(follower_ids), set([p_a_id, p_b_id]), 'Pigs followers after invite is incorrect') + # Test: sent email subject, body + self.assertEqual(len(self._build_email_kwargs_list), 1, 'sent email number incorrect, should be only for Bert') + for sent_email in self._build_email_kwargs_list: + self.assertEqual(sent_email.get('subject'), _sent_email_subject, 'sent email subject incorrect') + self.assertEqual(sent_email.get('body'), _sent_email_body, 'sent email body incorrect') From 0e4422809ba411a629b03baf705a3a7dd781302f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 13 Sep 2012 13:49:17 +0200 Subject: [PATCH 17/22] [IMP] email_template: now inherit from TestMailMockups test class. bzr revid: tde@openerp.com-20120913114917-na341w0ja7n0ditu --- addons/email_template/tests/test_mail.py | 16 ++-------------- addons/portal/tests/test_portal.py | 1 - 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/addons/email_template/tests/test_mail.py b/addons/email_template/tests/test_mail.py index 85ab3afc902..1091c34ad5c 100644 --- a/addons/email_template/tests/test_mail.py +++ b/addons/email_template/tests/test_mail.py @@ -20,17 +20,10 @@ ############################################################################## import base64 -from openerp.tests import common +from openerp.addons.mail.tests import test_mail -class test_message_compose(common.TransactionCase): - def _mock_smtp_gateway(self, *args, **kwargs): - return True - - def _mock_build_email(self, *args, **kwargs): - self._build_email_args = args - self._build_email_kwargs = kwargs - return self.build_email_real(*args, **kwargs) +class test_message_compose(test_mail.TestMailMockups): def setUp(self): super(test_message_compose, self).setUp() @@ -40,11 +33,6 @@ class test_message_compose(common.TransactionCase): self.res_users = self.registry('res.users') self.res_partner = self.registry('res.partner') - # Install mock SMTP gateway - self.build_email_real = self.registry('ir.mail_server').build_email - self.registry('ir.mail_server').build_email = self._mock_build_email - self.registry('ir.mail_server').send_email = self._mock_smtp_gateway - # create a 'pigs' and 'bird' groups that will be used through the various tests self.group_pigs_id = self.mail_group.create(self.cr, self.uid, {'name': 'Pigs', 'description': 'Fans of Pigs, unite !'}) diff --git a/addons/portal/tests/test_portal.py b/addons/portal/tests/test_portal.py index 5f2875711df..1f709ed3fa9 100644 --- a/addons/portal/tests/test_portal.py +++ b/addons/portal/tests/test_portal.py @@ -20,7 +20,6 @@ ############################################################################## from openerp.addons.mail.tests import test_mail -# from openerp.tests import common from openerp.tools import append_content_to_html From b2c79d266b7a2752f26782ee673e52b647825f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 13 Sep 2012 14:11:10 +0200 Subject: [PATCH 18/22] [FIX] mail_message: fixed record_name, because we could call a name_get on a document we can not see (if we are in the recipints of a document we can not access). name_get is therefore inside a try/except statement, getting a void string as result if AccessDenied is raised. Updated JS to avoid displaying the record name on a void string. bzr revid: tde@openerp.com-20120913121110-bd0syf813h0e39gk --- addons/mail/mail_message.py | 6 +++++- addons/mail/static/src/xml/mail.xml | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 10f02805ab3..234c0262f6a 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -20,6 +20,7 @@ ############################################################################## import logging +import openerp import tools from email.header import decode_header @@ -58,7 +59,10 @@ class mail_message(osv.Model): for message in self.browse(cr, uid, ids, context=context): if not message.model or not message.res_id: continue - result[message.id] = self._shorten_name(self.pool.get(message.model).name_get(cr, uid, [message.res_id], context=context)[0][1]) + try: + result[message.id] = self._shorten_name(self.pool.get(message.model).name_get(cr, uid, [message.res_id], context=context)[0][1]) + except openerp.exceptions.AccessDenied, e: + pass return result def _get_unread(self, cr, uid, ids, name, arg, context=None): diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 4d3b56cf62f..10aa7c07ec7 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -130,14 +130,14 @@
- +