Files
odoo_source/addons/test_mail/static/tests/properties_field_tests.js
T
Alexandre Kühn 23e60fb780 [FIX] mail: no access right issue on open chat from message avatar
Before this commit, when hr was installed and Demo clicks on avatar
of Mitchell Admin, open chat failed due to access right exception.

This happens because open chat works only with internal users, and
when we don't know whether the partner has an internal user, we have
to check whether there's a user linked to this partner.
Doing `searchRead()` without passing any field triggers this missing
access right for some reasons.

Only the knowledge of an existing `userId` is enough, so we
can actually just make a `search()` to get the user id. This won't
trigger the access right exception while giving the user id of
the partner if this exists, thus proceeding with open chat request.

closes odoo/odoo#123796

X-original-commit: 2f6dc5f4222d380cf77c6660ccce8b7381e0e64a
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2023-06-06 11:45:14 +02:00

78 lines
2.7 KiB
JavaScript

/** @odoo-module **/
import { start, startServer, click } from "@mail/../tests/helpers/test_utils";
QUnit.module("properties field");
/**
* Open a chat window when clicking on an avatar many2one / many2many properties.
*/
async function testPropertyFieldAvatarOpenChat(assert, propertyType) {
const pyEnv = await startServer();
const view = `
<form string="Form With Avatar Users">
<sheet>
<field name="name"/>
<field name="parent_id"/>
<field name="properties"/>
</sheet>
<div class="oe_chatter">
<field name="message_ids"/>
</div>
</form>`;
const { openView } = await start({
serverData: {
views: {
"mail.test.properties,false,form": view,
},
},
async mockRPC(route) {
if (route.includes("/mail.test.properties/check_access_rights")) {
return true;
} else if (route === "/web/dataset/call_kw/res.users/read") {
assert.step("read res.users");
return [{ id: userId, partner_id: [partnerId, "Partner Test"] }];
} else if (route === "/web/dataset/call_kw/res.users/search_read") {
return [{ id: userId, name: "User Test" }];
}
},
});
const partnerId = pyEnv["res.partner"].create({ name: "Partner Test" });
const userId = pyEnv["res.users"].create({ name: "User Test", partner_id: partnerId });
const parentId = pyEnv["mail.test.properties"].create({ name: "Parent" });
const value = propertyType === "many2one" ? [userId, "User Test"] : [[userId, "User Test"]];
const childId = pyEnv["mail.test.properties"].create({
name: "Test",
parent_id: parentId,
properties: [
{ type: propertyType, comodel: "res.users", name: "user", string: "user", value },
],
});
await openView({
res_id: childId,
res_model: "mail.test.properties",
views: [[false, "form"]],
});
assert.verifySteps([]);
await click(
propertyType === "many2one" ? ".o_field_property_many2one_value img" : ".o_m2m_avatar"
);
assert.verifySteps(["read res.users"]);
const chatter = document.querySelectorAll(".o-mail-ChatWindow-name");
assert.strictEqual(chatter.length, 1);
assert.strictEqual(chatter[0].innerText, "Partner Test");
}
QUnit.test("Properties fields: many2one avatar open chat on click", async function (assert) {
await testPropertyFieldAvatarOpenChat(assert, "many2one");
});
QUnit.test("Properties fields: m2m avatar list open chat on click", async function (assert) {
await testPropertyFieldAvatarOpenChat(assert, "many2many");
});