[FIX] mail,*: markup chatbot livechat message

calendar, im_livechat

Before this commit, messages in chatbot conversation were not
properly markup. This comes from changes from [1] that added
trusted insert. Original code in `Record.insert()` makes a model
insertion of the data using the `html` flag. Patches must not
override `static insert()` as only the super call is affected by
the provided `html` flag. For patches to take account of it, they
must instead patch `_insert`, with `_` prefix, which is internally
called by original `Record.insert()`.

In addition:
- `static insert` allows array of data while `static _insert` works
  with data on single record. Patches were designed with data on
  single record, so some code were not working properly
- Signature of `static insert` has been overloaded with new option
  `html: true`, so patches must propagate it. They were only
  propagating `data` and omitting the 2nd paramater, which results
  in omitting provided `html` thus falling back to `html: false`,
  resulting to non-escaping message body

This commit fixes all model patches to override `static _insert`
instead of `static insert`.

[1]: https://github.com/odoo/odoo/pull/139501

closes odoo/odoo#140064

Related: odoo/enterprise#49718
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Alexandre Kühn
2023-10-27 16:09:34 +00:00
parent 01f03b1e19
commit b3c231b1b2
5 changed files with 12 additions and 14 deletions
@@ -1,15 +1,13 @@
/** @odoo-module */
import { Activity } from "@mail/core/web/activity_model";
import { assignIn } from "@mail/utils/common/misc";
import { patch } from "@web/core/utils/patch";
patch(Activity, {
insert(data) {
const activity = super.insert(...arguments);
const { calendar_event_id: calendarEventId } = data;
if (calendarEventId) {
activity["calendar_event_id"] = calendarEventId;
}
_insert(data) {
const activity = super._insert(...arguments);
assignIn(activity, data, ["calendar_event_id"]);
return activity;
},
});
@@ -6,8 +6,8 @@ import { Thread } from "@mail/core/common/thread_model";
import { patch } from "@web/core/utils/patch";
patch(Thread, {
insert(data) {
const thread = super.insert(data);
_insert(data) {
const thread = super._insert(...arguments);
if (thread.type === "livechat") {
if (data?.operator_pid) {
thread.operator = {
@@ -6,8 +6,8 @@ import { assignIn } from "@mail/utils/common/misc";
import { patch } from "@web/core/utils/patch";
patch(Thread, {
insert(data) {
const thread = super.insert(data);
_insert(data) {
const thread = super._insert(...arguments);
if (thread.type === "livechat") {
assignIn(thread, data, ["anonymous_name", "anonymous_country"]);
this.store.discuss.livechat.threads.add(thread);
@@ -7,9 +7,9 @@ import { Message } from "@mail/core/common/message_model";
import { patch } from "@web/core/utils/patch";
patch(Message, {
insert(data) {
_insert(data) {
const chatbotStep = this.store.Message.get(data)?.chatbotStep;
const message = super.insert(data);
const message = super._insert(...arguments);
if (data.chatbotStep) {
message.chatbotStep = new ChatbotStep({ ...chatbotStep, ...data.chatbotStep });
}
@@ -10,9 +10,9 @@ import { patch } from "@web/core/utils/patch";
import { session } from "@web/session";
patch(Thread, {
insert(data) {
_insert(data) {
const isUnknown = !this.get(data);
const thread = super.insert(...arguments);
const thread = super._insert(...arguments);
const livechatService = this.env.services["im_livechat.livechat"];
if (thread.type === "livechat" && isUnknown) {
onChange(