[FIX] mail: message/activity link with dataset oe-id and oe-model
Task-2328718 closes odoo/odoo#56872 X-original-commit: 430aa0c2ffe242992fb935733d81f6e05a6d2458 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com> Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -130,6 +130,25 @@ class Activity extends Component {
|
||||
this.activity.markAsDone({ attachments: [ev.detail.attachment] });
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
_onClick(ev) {
|
||||
if (
|
||||
ev.target.tagName === 'A' &&
|
||||
ev.target.dataset.oeId &&
|
||||
ev.target.dataset.oeModel
|
||||
) {
|
||||
this.env.messaging.openProfile({
|
||||
id: Number(ev.target.dataset.oeId),
|
||||
model: ev.target.dataset.oeModel,
|
||||
});
|
||||
// avoid following dummy href
|
||||
ev.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {MouseEvent} ev
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="mail.Activity" owl="1">
|
||||
<div class="o_Activity">
|
||||
<div class="o_Activity" t-on-click="_onClick">
|
||||
<t t-if="activity">
|
||||
<div class="o_Activity_sidebar">
|
||||
<div class="o_Activity_user">
|
||||
|
||||
@@ -1069,6 +1069,54 @@ QUnit.test('activity mark done popover click on discard', async function (assert
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('data-oe-id & data-oe-model link redirection on click', async function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
const bus = new Bus();
|
||||
bus.on('do-action', null, payload => {
|
||||
assert.strictEqual(
|
||||
payload.action.type,
|
||||
'ir.actions.act_window',
|
||||
"action should open view"
|
||||
);
|
||||
assert.strictEqual(
|
||||
payload.action.res_model,
|
||||
'some.model',
|
||||
"action should open view on 'some.model' model"
|
||||
);
|
||||
assert.strictEqual(
|
||||
payload.action.res_id,
|
||||
250,
|
||||
"action should open view on 250"
|
||||
);
|
||||
assert.step('do-action:openFormView_some.model_250');
|
||||
});
|
||||
await this.start({ env: { bus } });
|
||||
const activity = this.env.models['mail.activity'].create({
|
||||
canWrite: true,
|
||||
category: 'not_upload_file',
|
||||
id: 12,
|
||||
note: `<p><a href="#" data-oe-id="250" data-oe-model="some.model">some.model_250</a></p>`,
|
||||
});
|
||||
await this.createActivityComponent(activity);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_Activity_note',
|
||||
"activity should have a note"
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.querySelector('.o_Activity_note'),
|
||||
'a',
|
||||
"activity note should have a link"
|
||||
);
|
||||
|
||||
document.querySelector(`.o_Activity_note a`).click();
|
||||
assert.verifySteps(
|
||||
['do-action:openFormView_some.model_250'],
|
||||
"should have open form view on related record after click on link"
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -435,22 +435,15 @@ class Message extends Component {
|
||||
ev.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (ev.target.closest('.o_mention')) {
|
||||
this.env.messaging.openProfile({
|
||||
id: Number(ev.target.dataset.oeId),
|
||||
model: ev.target.dataset.oeModel,
|
||||
});
|
||||
// avoid following dummy href
|
||||
ev.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (ev.target.closest('.o_mail_redirect')) {
|
||||
this.env.messaging.openProfile({
|
||||
id: Number(ev.target.dataset.oeId),
|
||||
model: ev.target.dataset.oeModel,
|
||||
});
|
||||
// avoid following dummy href
|
||||
ev.preventDefault();
|
||||
if (ev.target.tagName === 'A') {
|
||||
if (ev.target.dataset.oeId && ev.target.dataset.oeModel) {
|
||||
this.env.messaging.openProfile({
|
||||
id: Number(ev.target.dataset.oeId),
|
||||
model: ev.target.dataset.oeModel,
|
||||
});
|
||||
// avoid following dummy href
|
||||
ev.preventDefault();
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.state.isClicked = !this.state.isClicked;
|
||||
|
||||
@@ -783,6 +783,52 @@ QUnit.test('subtype description should not be displayed if it is similar to body
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('data-oe-id & data-oe-model link redirection on click', async function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
const bus = new Bus();
|
||||
bus.on('do-action', null, payload => {
|
||||
assert.strictEqual(
|
||||
payload.action.type,
|
||||
'ir.actions.act_window',
|
||||
"action should open view"
|
||||
);
|
||||
assert.strictEqual(
|
||||
payload.action.res_model,
|
||||
'some.model',
|
||||
"action should open view on 'some.model' model"
|
||||
);
|
||||
assert.strictEqual(
|
||||
payload.action.res_id,
|
||||
250,
|
||||
"action should open view on 250"
|
||||
);
|
||||
assert.step('do-action:openFormView_some.model_250');
|
||||
});
|
||||
await this.start({ env: { bus } });
|
||||
const message = this.env.models['mail.message'].create({
|
||||
body: `<p><a href="#" data-oe-id="250" data-oe-model="some.model">some.model_250</a></p>`,
|
||||
id: 100,
|
||||
});
|
||||
await this.createMessageComponent(message);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_Message_content',
|
||||
"message should have content"
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.querySelector('.o_Message_content'),
|
||||
'a',
|
||||
"message content should have a link"
|
||||
);
|
||||
|
||||
document.querySelector(`.o_Message_content a`).click();
|
||||
assert.verifySteps(
|
||||
['do-action:openFormView_some.model_250'],
|
||||
"should have open form view on related record after click on link"
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -739,9 +739,7 @@ QUnit.test('read more links becomes read less after being clicked', async functi
|
||||
"read more/less link should contain 'read more' as text"
|
||||
);
|
||||
|
||||
await afterNextRender(() => {
|
||||
document.querySelector('.o_Message_readMoreLess').click();
|
||||
});
|
||||
document.querySelector('.o_Message_readMoreLess').click();
|
||||
assert.strictEqual(
|
||||
document.querySelector('.o_Message_readMoreLess').textContent,
|
||||
'read less',
|
||||
|
||||
Reference in New Issue
Block a user