diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index ebd143e1be8..949ed60ba82 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -156,21 +156,20 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res - def read_followers_data(self, cr, uid, ids, context=None): - data = self.pool.get('res.partner').read(cr, uid, ids, ['name', 'user_ids'], context=context) - - grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one') - tech_user = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users'] - user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] - - if uid in tech_user: - for dict in data: - if dict['id'] in [user_pid]: - dict.update({'is_editable': True}) - if uid in dict['user_ids']: - dict.update({'is_uid': True}) - - return data + def read_followers_data(self, cr, uid, follower_ids, context=None): + datas = [] + partner_pool = self.pool.get('res.partner') + technical_group = self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'group_no_one') + for follower in partner_pool.browse(cr, uid, follower_ids, context=context): + is_editable = uid in map(lambda x:x.id, technical_group.users) + is_uid = uid in map(lambda x:x.id, follower.user_ids) + data = ( + follower.id, + follower.name, + {'is_editable': is_editable, 'is_uid': is_uid}, + ) + datas.append(data) + return datas def _get_subscription_data(self, cr, uid, ids, name, args, user_pid=None, context=None): """ Computes: diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 99c2a629f5d..4fec4ff3fd3 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -35,8 +35,6 @@ openerp_mail_followers = function(session, mail) { this.followers = []; this.view_is_editable = this.__parentedParent.is_action_enabled('edit'); - this.check_access = false; - this.is_follower = false; }, start: function() { @@ -196,22 +194,17 @@ openerp_mail_followers = function(session, mail) { display_followers: function (records) { var self = this; this.followers = records || this.followers; - _.each(this.result, function (record) { - if (self.session.uid == record.user_ids[0]) { - if (record.is_editable == true) { self.check_access = true; } - } - }); - this.message_is_follower = this.set_is_follower(this.followers); // self.is_follower // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); _(truncated).each(function (record) { - record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); + self.message_is_follower = record[2].is_uid; + record[2].avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record[0]); $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); // On mouse-enter it will show the edit_subtype pencil. - if (self.check_access == true) { + if (record[2].is_editable == true) { self.$el.on('mouseenter', 'div.oe_follower_list', function() { $("img.oe_edit_subtype").removeClass("hidden"); $('div.oe_follower_list').find('.oe_partner').addClass('oe_partner_name'); @@ -227,12 +220,6 @@ openerp_mail_followers = function(session, mail) { } }, - /** Computes whether the current user is in the followers */ - set_is_follower: function (records) { - var user_ids = _.pluck(_.pluck(records, 'user_ids'), 0); - return _.indexOf(user_ids, this.session.uid) != -1; - }, - display_buttons: function () { if (this.message_is_follower) { this.$('button.oe_follower').removeClass('oe_notfollow').addClass('oe_following'); diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index db58abb1441..d23154096a6 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -29,10 +29,10 @@ Template used to display a partner following the record -->
- - - - X + + + + X