[FIX] mail: avoid adding non-members on mention in channels

task-2392010

closes odoo/odoo#62242

X-original-commit: 0a3fe0a513abbde8f74d59de522a216035cdcd98
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Sébastien Theys
2020-11-24 12:52:37 +00:00
parent 49f9a8aa84
commit 5ab794cf30
2 changed files with 59 additions and 0 deletions
@@ -2099,6 +2099,61 @@ QUnit.test('send message only once when enter is pressed twice quickly', async f
);
});
QUnit.test("mentioned partners should not be notified if they are not member of current channel", async function (assert) {
assert.expect(4);
this.data['res.partner'].records.push({
email: "testpartner@example.com",
name: "TestPartner",
});
this.data['mail.channel'].records.push({
id: 10,
members: [this.data.currentPartnerId],
});
await this.start({
async mockRPC(route, args) {
if (args.model === 'mail.channel' && args.method === 'message_post') {
assert.step('message_post');
assert.strictEqual(
args.kwargs.partner_ids.length,
0,
"message_post should not contain mentioned partners that are not members of channel"
);
}
return this._super(...arguments);
},
});
const thread = this.env.models['mail.thread'].findFromIdentifyingData({
id: 10,
model: 'mail.channel',
});
await this.createComposerComponent(thread.composer);
await afterNextRender(() => {
document.querySelector(`.o_ComposerTextInput_textarea`).focus();
document.execCommand('insertText', false, "@");
document.querySelector(`.o_ComposerTextInput_textarea`)
.dispatchEvent(new window.KeyboardEvent('keydown'));
document.querySelector(`.o_ComposerTextInput_textarea`)
.dispatchEvent(new window.KeyboardEvent('keyup'));
});
await afterNextRender(() => {
document.querySelector(`.o_ComposerTextInput_textarea`).focus();
document.execCommand('insertText', false, "Test");
document.querySelector(`.o_ComposerTextInput_textarea`)
.dispatchEvent(new window.KeyboardEvent('keydown'));
document.querySelector(`.o_ComposerTextInput_textarea`)
.dispatchEvent(new window.KeyboardEvent('keyup'));
});
await afterNextRender(() => document.querySelector('.o_ComposerSuggestion').click());
assert.strictEqual(
document.querySelector(`.o_ComposerTextInput_textarea`).value.replace(/\s/, " "),
"@TestPartner ",
"text content of composer should have mentioned partner + additional whitespace afterwards"
);
await afterNextRender(() => document.querySelector('.o_Composer_buttonSend').click());
assert.verifySteps(['message_post'], "the message should be posted");
});
});
});
});
@@ -188,6 +188,10 @@ function factory(dependencies) {
* @returns {mail.partner[]}
*/
_computeRecipients() {
if (this.thread && this.thread.model === 'mail.channel') {
// prevent from notifying/adding to followers non-members
return [['unlink-all']];
}
const recipients = [...this.mentionedPartners];
if (this.thread && !this.isLog) {
for (const recipient of this.thread.suggestedRecipientInfoList) {