From 790206d12cba70b1489070da491d22d502e6b5ac Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 27 Apr 2017 14:57:14 +0200 Subject: [PATCH] [FIX] mail: followers: don't list followers twice Before this rev., if concurrent calls to 'read_follower' were performed, it might happen that the read followers appearead twice in the follower dropdown. This was for example the case when validating an invoice: the customer was listed twice as follower. Note: in this particular case, the record shouldn't be reloaded twice: this is another bug to adress. --- addons/mail/static/src/js/followers.js | 2 +- addons/mail/static/tests/chatter_tests.js | 67 +++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/followers.js b/addons/mail/static/src/js/followers.js index f0fc21dab26..d60e3ede753 100644 --- a/addons/mail/static/src/js/followers.js +++ b/addons/mail/static/src/js/followers.js @@ -202,7 +202,7 @@ var Followers = AbstractField.extend({ } return $.when(def).then(function (results) { if (results) { - self.followers = self.followers.concat(results.followers); + self.followers = _.uniq(results.followers.concat(self.followers), 'id'); self.subtypes = results.subtypes; } // filter out previously fetched followers that are no longer following diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js index b20733949e2..834f58a40fe 100644 --- a/addons/mail/static/tests/chatter_tests.js +++ b/addons/mail/static/tests/chatter_tests.js @@ -752,5 +752,72 @@ QUnit.test('followers widget: follow/unfollow, edit subtypes', function (assert) form.destroy(); }); + +QUnit.test('followers widget: do not display follower duplications', function (assert) { + assert.expect(2); + + this.data.partner.records[0].message_follower_ids = [1]; + var resID = 2; + var followers = [{ + id: 1, + name: "Admin", + email: "admin@example.com", + res_id: resID, + res_model: 'partner', + }]; + var def; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '
' + + '' + + '
' + + '
', + mockRPC: function (route, args) { + if (route === '/mail/read_followers') { + return $.when(def).then(function () { + return { + followers: _.filter(followers, function (follower) { + return _.contains(args.follower_ids, follower.id); + }), + subtypes: [], + }; + }); + } + return this._super.apply(this, arguments); + }, + res_id: resID, + session: {partner_id: 1}, + }); + + + followers.push({ + id: 2, + is_uid: false, + name: "A follower", + email: "follower@example.com", + res_id: resID, + res_model: 'partner', + }); + this.data.partner.records[0].message_follower_ids.push(2); + + // simulate concurrent calls to read_followers and check that those followers + // are not added twice in the dropdown + def = $.Deferred(); + form.reload(); + form.reload(); + def.resolve(); + + assert.strictEqual(form.$('.o_followers_count').text(), '2', + "should have 2 followers"); + assert.strictEqual(form.$('.o_followers_list .o_partner').length, 2, + "there should be 2 followers in the follower dropdown"); + + form.destroy(); +}); + }); });