[FIX] mail: crash when message has no author

This commit fixes a crash that occured when a message has
no author. The author avatar url was assuming an author
would always be given while it is not the case.

closes odoo/odoo#116306

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
tsm-odoo
2023-03-23 21:13:05 +01:00
parent dbc6b60839
commit 08278d582b
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -156,7 +156,7 @@ export class Message extends Component {
get authorAvatarUrl() {
if (
this.message.type === "email" &&
!["partner", "guest"].includes(this.message.author.type)
!["partner", "guest"].includes(this.message.author?.type)
) {
return url("/mail/static/src/img/email_icon.png");
}
@@ -1400,3 +1400,22 @@ QUnit.test("Mark as unread", async (assert) => {
assert.containsOnce($, ".o-mail-Thread-newMessage");
assert.containsOnce($, ".o-mail-DiscussCategoryItem .badge:contains(1)");
});
QUnit.test("Avatar of unknown author", async (assert) => {
const pyEnv = await startServer();
pyEnv["mail.message"].create({
body: "<p>Want to know features and benefits of using the new software.</p>",
email_from: "md@oilcompany.fr",
message_type: "email",
subject: "Need Details",
model: "res.partner",
res_id: pyEnv.currentPartnerId,
author_id: null,
});
const { openFormView } = await start();
await openFormView("res.partner", pyEnv.currentPartnerId);
assert.containsOnce(
$,
".o-mail-Message-avatar[data-src*='mail/static/src/img/email_icon.png']"
);
});