[FIX] mail, im_livechat: properly handle multiple public partners
task-2391334 closes odoo/odoo#63002 X-original-commit: 9fbea9f8ee193e672c855c73ad29de187f27cef1 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -104,12 +104,13 @@ class MailChannel(models.Model):
|
||||
if not partners:
|
||||
# operator probably testing the livechat with his own user
|
||||
partners = channel_partner_ids
|
||||
if partners and partners[0] != self.env.ref('base.public_partner'):
|
||||
first_partner = partners and partners[0]
|
||||
if first_partner and (not first_partner.user_ids or not any(user._is_public() for user in first_partner.user_ids)):
|
||||
# legit non-public partner
|
||||
return {
|
||||
'country': partners[0].country_id.name_get()[0] if partners[0].country_id else False,
|
||||
'id': partners[0].id,
|
||||
'name': partners[0].name,
|
||||
'country': first_partner.country_id.name_get()[0] if first_partner.country_id else False,
|
||||
'id': first_partner.id,
|
||||
'name': first_partner.name,
|
||||
}
|
||||
return {
|
||||
'country': self.country_id.name_get()[0] if self.country_id else False,
|
||||
|
||||
@@ -71,8 +71,8 @@ QUnit.test('livechat: public website visitor is typing', async function (assert)
|
||||
const typingData = {
|
||||
info: 'typing_status',
|
||||
is_typing: true,
|
||||
partner_id: this.env.messaging.publicPartner.id,
|
||||
partner_name: this.env.messaging.publicPartner.name,
|
||||
partner_id: this.env.messaging.publicPartners[0].id,
|
||||
partner_name: this.env.messaging.publicPartners[0].name,
|
||||
};
|
||||
const notification = [[false, 'mail.channel', 20], typingData];
|
||||
this.widget.call('bus_service', 'trigger', 'notification', [notification]);
|
||||
|
||||
+2
-2
@@ -67,8 +67,8 @@ QUnit.test('receive visitor typing status "is typing"', async function (assert)
|
||||
const typingData = {
|
||||
info: 'typing_status',
|
||||
is_typing: true,
|
||||
partner_id: this.env.messaging.publicPartner.id,
|
||||
partner_name: this.env.messaging.publicPartner.name,
|
||||
partner_id: this.env.messaging.publicPartners[0].id,
|
||||
partner_name: this.env.messaging.publicPartners[0].name,
|
||||
};
|
||||
const notification = [[false, 'mail.channel', 20], typingData];
|
||||
this.widget.call('bus_service', 'trigger', 'notification', [notification]);
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ registerInstancePatchModel('mail.messaging_notification_handler', 'im_livechat/s
|
||||
}
|
||||
let partnerId;
|
||||
let partnerName;
|
||||
if (partner_id === this.env.messaging.publicPartner.id) {
|
||||
if (this.env.messaging.publicPartners.some(publicPartner => publicPartner.id === partner_id)) {
|
||||
// Some shenanigans that this is a typing notification
|
||||
// from public partner.
|
||||
partnerId = channel.correspondent.id;
|
||||
|
||||
@@ -39,7 +39,7 @@ registerClassPatchModel('mail.thread', 'im_livechat/static/src/models/thread/thr
|
||||
* of polluting the database, it is therefore acceptable and
|
||||
* easier to handle one temporary partner per channel.
|
||||
*/
|
||||
data2.members.push(['unlink', this.env.messaging.publicPartner]);
|
||||
data2.members.push(['unlink', this.env.messaging.publicPartners]);
|
||||
const partner = this.env.models['mail.partner'].create(
|
||||
Object.assign(
|
||||
this.env.models['mail.partner'].convertData(data.livechat_visitor),
|
||||
|
||||
@@ -267,7 +267,7 @@ class MailController(http.Controller):
|
||||
'moderation_counter': request.env.user.moderation_counter,
|
||||
'moderation_channel_ids': request.env.user.moderation_channel_ids.ids,
|
||||
'partner_root': request.env.ref('base.partner_root').sudo().mail_partner_format(),
|
||||
'public_partner': request.env.ref('base.public_partner').sudo().mail_partner_format(),
|
||||
'public_partners': [partner.mail_partner_format() for partner in request.env.ref('base.group_public').sudo().with_context(active_test=False).users.partner_id],
|
||||
'current_partner': request.env.user.partner_id.mail_partner_format(),
|
||||
'current_user_id': request.env.user.id,
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ odoo.define('mail/static/src/models/messaging/messaging.js', function (require)
|
||||
'use strict';
|
||||
|
||||
const { registerNewModel } = require('mail/static/src/model/model_core.js');
|
||||
const { attr, many2one, one2many, one2one } = require('mail/static/src/model/model_field.js');
|
||||
const { attr, many2many, many2one, one2many, one2one } = require('mail/static/src/model/model_field.js');
|
||||
|
||||
function factory(dependencies) {
|
||||
|
||||
@@ -231,7 +231,11 @@ function factory(dependencies) {
|
||||
default: 0,
|
||||
}),
|
||||
partnerRoot: many2one('mail.partner'),
|
||||
publicPartner: many2one('mail.partner'),
|
||||
/**
|
||||
* Determines which partners should be considered the public partners,
|
||||
* which are special partners notably used in livechat.
|
||||
*/
|
||||
publicPartners: many2many('mail.partner'),
|
||||
/**
|
||||
* Mailbox Starred.
|
||||
*/
|
||||
|
||||
@@ -79,7 +79,7 @@ function factory(dependencies) {
|
||||
* @param {integer} [param0.moderation_counter=0]
|
||||
* @param {integer} [param0.needaction_inbox_counter=0]
|
||||
* @param {Object} param0.partner_root
|
||||
* @param {Object} param0.public_partner
|
||||
* @param {Object[]} param0.public_partners
|
||||
* @param {Object[]} [param0.shortcodes=[]]
|
||||
* @param {integer} [param0.starred_counter=0]
|
||||
*/
|
||||
@@ -95,7 +95,7 @@ function factory(dependencies) {
|
||||
moderation_counter = 0,
|
||||
needaction_inbox_counter = 0,
|
||||
partner_root,
|
||||
public_partner,
|
||||
public_partners,
|
||||
shortcodes = [],
|
||||
starred_counter = 0
|
||||
}) {
|
||||
@@ -106,7 +106,7 @@ function factory(dependencies) {
|
||||
current_user_id,
|
||||
moderation_channel_ids,
|
||||
partner_root,
|
||||
public_partner,
|
||||
public_partners,
|
||||
});
|
||||
// mailboxes after partners and before other initializers that might
|
||||
// manipulate threads or messages
|
||||
@@ -245,14 +245,14 @@ function factory(dependencies) {
|
||||
* @param {integer} current_user_id
|
||||
* @param {integer[]} moderation_channel_ids
|
||||
* @param {Object} partner_root
|
||||
* @param {Object} public_partner
|
||||
* @param {Object[]} [public_partners=[]]
|
||||
*/
|
||||
_initPartners({
|
||||
current_partner,
|
||||
current_user_id: currentUserId,
|
||||
moderation_channel_ids = [],
|
||||
partner_root,
|
||||
public_partner,
|
||||
public_partners = [],
|
||||
}) {
|
||||
this.messaging.update({
|
||||
currentPartner: [['insert', Object.assign(
|
||||
@@ -271,7 +271,11 @@ function factory(dependencies) {
|
||||
)]],
|
||||
currentUser: [['insert', { id: currentUserId }]],
|
||||
partnerRoot: [['insert', this.env.models['mail.partner'].convertData(partner_root)]],
|
||||
publicPartner: [['insert', this.env.models['mail.partner'].convertData(public_partner)]],
|
||||
publicPartners: [
|
||||
['insert', public_partners.map(
|
||||
publicPartner => this.env.models['mail.partner'].convertData(publicPartner))
|
||||
],
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -420,7 +420,7 @@ MockServer.include({
|
||||
moderation_counter,
|
||||
needaction_inbox_counter,
|
||||
partner_root: partnerRootFormat,
|
||||
public_partner: publicPartnerFormat,
|
||||
public_partners: [publicPartnerFormat],
|
||||
shortcodes,
|
||||
starred_counter: starredCounter,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user