From 66bb1d351b28584bdca1da896e90cf6cd339c2d5 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Tue, 24 Oct 2023 14:06:26 +0200 Subject: [PATCH] [FIX] {im,website}_livechat: only send guest token when available Before this commit, live chat would fail for guest portal. In this scenario, there is no guest token. Before this commit, the guest token was sent anyway with `null` as value which caused a crash. closes odoo/odoo#139585 Signed-off-by: Matthieu Stockbauer (tsm) --- .../src/embed/common/livechat_service.js | 10 ++++--- .../tests/tours/website_livechat_as_portal.js | 29 +++++++++++++++++++ .../tests/test_livechat_basic_flow.py | 5 ++++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 addons/website_livechat/static/tests/tours/website_livechat_as_portal.js diff --git a/addons/im_livechat/static/src/embed/common/livechat_service.js b/addons/im_livechat/static/src/embed/common/livechat_service.js index d62abad9ae4..8f9d4ae0f98 100644 --- a/addons/im_livechat/static/src/embed/common/livechat_service.js +++ b/addons/im_livechat/static/src/embed/common/livechat_service.js @@ -225,10 +225,12 @@ export class LivechatService { } async initializePersistedSession() { - await this.busService.updateContext({ - ...this.busService.context, - guest_token: this.guestToken, - }); + if (this.guestToken) { + await this.busService.updateContext({ + ...this.busService.context, + guest_token: this.guestToken, + }); + } if (this.busService.isActive) { this.busService.forceUpdateChannels(); } else { diff --git a/addons/website_livechat/static/tests/tours/website_livechat_as_portal.js b/addons/website_livechat/static/tests/tours/website_livechat_as_portal.js new file mode 100644 index 00000000000..08d0c2284f6 --- /dev/null +++ b/addons/website_livechat/static/tests/tours/website_livechat_as_portal.js @@ -0,0 +1,29 @@ +/* @odoo-module */ + +import { registry } from "@web/core/registry"; + +registry.category("web_tour.tours").add("website_livechat_as_portal_tour", { + test: true, + shadow_dom: ".o-livechat-root", + steps: () => [ + { + trigger: ".o-livechat-LivechatButton", + }, + { + trigger: ".o-mail-Composer-input", + run: "text Hello, I need help!", + }, + { + trigger: ".o-mail-Composer-input", + run() { + this.$anchor[0].dispatchEvent( + new KeyboardEvent("keydown", { key: "Enter", which: 13, bubbles: true }) + ); + }, + }, + { + trigger: ".o-mail-Message:contains('Hello, I need help!')", + isCheck: true, + }, + ], +}); diff --git a/addons/website_livechat/tests/test_livechat_basic_flow.py b/addons/website_livechat/tests/test_livechat_basic_flow.py index 89355c89c83..3e5a021520d 100644 --- a/addons/website_livechat/tests/test_livechat_basic_flow.py +++ b/addons/website_livechat/tests/test_livechat_basic_flow.py @@ -5,6 +5,7 @@ import datetime from odoo import tests, _ from odoo.addons.website_livechat.tests.common import TestLivechatCommon +from odoo.tests.common import new_test_user @tests.tagged('post_install', '-at_install') @@ -140,3 +141,7 @@ class TestLivechatBasicFlowHttpCase(tests.HttpCase, TestLivechatCommon): self.assertEqual(channel.livechat_active, True, "The livechat session must be active as the visitor did not left the conversation yet.") return channel + + def test_livechat_as_portal_user(self): + new_test_user(self.env, login="portal_user", groups="base.group_portal") + self.start_tour("/my", "website_livechat_as_portal_tour", login="portal_user")