[FIX] Mail: fixed mail_followers widget, now taking into account crash when reading message_follower_ids, to disply only the number of followers, when the user does not have read access on the partners (ex: portal members).

bzr revid: tde@openerp.com-20120917150129-7ahagbvopo2iqoe5
This commit is contained in:
Thibault Delavallée
2012-09-17 17:01:29 +02:00
parent 198fd2b12c
commit 7f309d2df0
3 changed files with 24 additions and 6 deletions
+1
View File
@@ -81,6 +81,7 @@
</group>
</sheet>
<div class="oe_chatter">
<field name="message_is_follower" invisible="1"/>
<field name="message_ids" widget="mail_thread"
options='{"thread_level": 1}'/>
<field name="message_follower_ids" widget="mail_followers"/>
+5 -5
View File
@@ -119,7 +119,7 @@ class mail_thread(osv.AbstractModel):
def _get_message_data(self, cr, uid, ids, name, args, context=None):
res = dict((id, dict(message_unread=False, message_summary='')) for id in ids)
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
partner_id = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
# search for unread messages, by reading directly mail.notification, as SUPERUSER
notif_obj = self.pool.get('mail.notification')
@@ -132,10 +132,10 @@ class mail_thread(osv.AbstractModel):
for notif in notif_obj.browse(cr, SUPERUSER_ID, notif_ids, context=context):
res[notif.message_id.res_id]['message_unread'] = True
for thread in self.browse(cr, uid, ids, context=context):
cls = res[thread.id]['message_unread'] and ' class="oe_kanban_mail_new"' or ''
res[thread.id]['message_summary'] = "<span%s><span class='oe_e'>9</span> %d</span> <span><span class='oe_e'>+</span> %d</span>" % (cls, len(thread.message_comment_ids), len(thread.message_follower_ids))
res[thread.id]['message_is_follower'] = user.partner_id.id in [follower.id for follower in thread.message_follower_ids]
for thread in self.read(cr, uid, ids, ['message_follower_ids', 'message_comment_ids', 'message_ids'], context=context):
cls = res[thread['id']]['message_unread'] and ' class="oe_kanban_mail_new"' or ''
res[thread['id']]['message_summary'] = "<span%s><span class='oe_e'>9</span> %d</span> <span><span class='oe_e'>+</span> %d</span>" % (cls, len(thread['message_comment_ids']), len(thread['message_follower_ids']))
res[thread['id']]['message_is_follower'] = partner_id in thread['message_follower_ids']
return res
def _search_unread(self, cr, uid, obj=None, name=None, domain=None, context=None):
+18 -1
View File
@@ -88,7 +88,24 @@ openerp_mail_followers = function(session, mail) {
},
fetch_followers: function (value_) {
return this.ds_follow.call('read', [value_, ['name', 'user_ids']]).pipe(this.proxy('display_followers'));
this.value = value_;
this.message_is_follower = this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value() || undefined;
return this.ds_follow.call('read', [value_, ['name', 'user_ids']]).pipe(this.proxy('display_followers'), this.proxy('display_generic'));
},
/* Display generic info about follower, for people not having access to res_partner */
display_generic: function (error, event) {
event.preventDefault();
var node_user_list = this.$el.find('ul.oe_mail_followers_display').empty();
this.$el.find('div.oe_mail_recthread_followers h4').html(this.options.title + ' (' + this.value.length + ')');
if (this.message_is_follower) {
this.$el.find('button.oe_mail_button_follow').hide();
this.$el.find('button.oe_mail_button_unfollow').show(); }
else {
this.$el.find('button.oe_mail_button_follow').show();
this.$el.find('button.oe_mail_button_unfollow').hide(); }
return $.when();
},
/** Display the followers, evaluate is_follower directly */