[IMP] mail, mail_bot: move notif request and OdooBot name into mail
task-2282334 closes odoo/odoo#56616 X-original-commit: bde23b82029507e525cf55d11b050af5f820a06b Related: odoo/upgrade#1705 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com> Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
committed by
Sébastien Theys
parent
0c68958048
commit
bc5654f0a4
@@ -101,9 +101,11 @@
|
||||
'static/src/components/moderation_ban_dialog/moderation_ban_dialog.xml',
|
||||
'static/src/components/moderation_discard_dialog/moderation_discard_dialog.xml',
|
||||
'static/src/components/moderation_reject_dialog/moderation_reject_dialog.xml',
|
||||
'static/src/components/notification_alert/notification_alert.xml',
|
||||
'static/src/components/notification_group/notification_group.xml',
|
||||
'static/src/components/notification_list/notification_list.xml',
|
||||
'static/src/components/notification_popover/notification_popover.xml',
|
||||
'static/src/components/notification_request/notification_request.xml',
|
||||
'static/src/components/partner_im_status_icon/partner_im_status_icon.xml',
|
||||
'static/src/components/partner_mention_suggestion/partner_mention_suggestion.xml',
|
||||
'static/src/components/thread_icon/thread_icon.xml',
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="base.partner_root" model="res.partner">
|
||||
<field name="name">OdooBot</field>
|
||||
<field name="email">odoobot@example.com</field>
|
||||
<field name="image_1920" type="base64" file="mail/static/src/img/odoobot.png"/>
|
||||
</record>
|
||||
|
||||
<!-- user root should not receive emails at creation -->
|
||||
<record id="base.user_root" model="res.users">
|
||||
<field name="notification_type">inbox</field>
|
||||
|
||||
@@ -25,6 +25,13 @@ class Partner(models.Model):
|
||||
# override the field to track the visibility of user
|
||||
user_id = fields.Many2one(tracking=True)
|
||||
|
||||
def _compute_im_status(self):
|
||||
super()._compute_im_status()
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id('base.partner_root')
|
||||
odoobot = self.env['res.partner'].browse(odoobot_id)
|
||||
if odoobot in self:
|
||||
odoobot.im_status = 'bot'
|
||||
|
||||
def _message_get_suggested_recipients(self):
|
||||
recipients = super(Partner, self)._message_get_suggested_recipients()
|
||||
for partner in self:
|
||||
@@ -114,6 +121,12 @@ class Partner(models.Model):
|
||||
# Remove duplicates
|
||||
partners = [p for p in partners if not len([u for u in users if u['id'] == p['id']])]
|
||||
|
||||
# add OdooBot even if its partner is archived
|
||||
if len(partners) + len(users) < limit and "odoobot".startswith(search.lower()):
|
||||
odoobot = self.env.ref("base.partner_root")
|
||||
if not any(elem['id'] == odoobot.id for elem in partners):
|
||||
partners.append(odoobot.read(fields)[0])
|
||||
|
||||
return [users, partners]
|
||||
|
||||
@api.model
|
||||
@@ -150,4 +163,3 @@ class Partner(models.Model):
|
||||
return self.env.cr.dictfetchall()
|
||||
else:
|
||||
return {}
|
||||
|
||||
|
||||
@@ -86,4 +86,4 @@
|
||||
</button>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
</templates>
|
||||
|
||||
@@ -815,6 +815,146 @@ QUnit.test('<br/> tags in message body preview are transformed in spaces', async
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('rendering with OdooBot has a request (default)', async function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
await this.start({
|
||||
env: {
|
||||
browser: {
|
||||
Notification: {
|
||||
permission: 'default',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.ok(
|
||||
document.querySelector('.o_MessagingMenu_counter'),
|
||||
"should display a notification counter next to the messaging menu for OdooBot request"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelector('.o_MessagingMenu_counter').textContent,
|
||||
"1",
|
||||
"should display a counter of '1' next to the messaging menu"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_NotificationRequest',
|
||||
"should display a notification in the messaging menu"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelector('.o_NotificationRequest_name').textContent.trim(),
|
||||
'OdooBot has a request',
|
||||
"notification should display that OdooBot has a request"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('rendering without OdooBot has a request (denied)', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
await this.start({
|
||||
env: {
|
||||
browser: {
|
||||
Notification: {
|
||||
permission: 'denied',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_MessagingMenu_counter',
|
||||
"should not display a notification counter next to the messaging menu"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_NotificationRequest',
|
||||
"should display no notification in the messaging menu"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('rendering without OdooBot has a request (accepted)', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
await this.start({
|
||||
env: {
|
||||
browser: {
|
||||
Notification: {
|
||||
permission: 'granted',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_MessagingMenu_counter',
|
||||
"should not display a notification counter next to the messaging menu"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_NotificationRequest',
|
||||
"should display no notification in the messaging menu"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('respond to notification prompt (denied)', async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
await this.start({
|
||||
env: {
|
||||
browser: {
|
||||
Notification: {
|
||||
permission: 'default',
|
||||
async requestPermission() {
|
||||
this.permission = 'denied';
|
||||
return this.permission;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_NotificationRequest').click()
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.toast .o_notification_content',
|
||||
"should display a toast notification with the deny confirmation"
|
||||
);
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_MessagingMenu_counter',
|
||||
"should not display a notification counter next to the messaging menu"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_NotificationRequest',
|
||||
"should display no notification in the messaging menu"
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
odoo.define('mail_bot/static/src/components/notification_alert/notification_alert.js', function (require) {
|
||||
odoo.define('mail/static/src/components/notification_alert/notification_alert.js', function (require) {
|
||||
'use strict';
|
||||
|
||||
const useStore = require('mail/static/src/component_hooks/use_store/use_store.js');
|
||||
@@ -44,7 +44,7 @@ class NotificationAlert extends Component {
|
||||
|
||||
Object.assign(NotificationAlert, {
|
||||
props: {},
|
||||
template: 'mail_bot.NotificationAlert',
|
||||
template: 'mail.NotificationAlert',
|
||||
});
|
||||
|
||||
return NotificationAlert;
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="mail_bot.NotificationAlert" owl="1">
|
||||
<t t-name="mail.NotificationAlert" owl="1">
|
||||
<div class="o_NotificationAlert">
|
||||
<t t-if="env.isMessagingInitialized()">
|
||||
<center t-if="isNotificationBlocked" class="o_notification_alert alert alert-primary">
|
||||
@@ -3,6 +3,7 @@ odoo.define('mail/static/src/components/notification_list/notification_list.js',
|
||||
|
||||
const components = {
|
||||
NotificationGroup: require('mail/static/src/components/notification_group/notification_group.js'),
|
||||
NotificationRequest: require('mail/static/src/components/notification_request/notification_request.js'),
|
||||
ThreadNeedactionPreview: require('mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js'),
|
||||
ThreadPreview: require('mail/static/src/components/thread_preview/thread_preview.js'),
|
||||
};
|
||||
@@ -135,6 +136,13 @@ class NotificationList extends Component {
|
||||
};
|
||||
}).concat(notifications);
|
||||
}
|
||||
// native notification request
|
||||
if (props.filter === 'all' && this.env.messaging.isNotificationPermissionDefault()) {
|
||||
notifications.unshift({
|
||||
type: 'odoobotRequest',
|
||||
uniqueId: 'odoobotRequest',
|
||||
});
|
||||
}
|
||||
return {
|
||||
isDeviceMobile: this.env.messaging.device.isMobile,
|
||||
notifications,
|
||||
|
||||
@@ -30,7 +30,13 @@
|
||||
notificationGroupLocalId="notification.notificationGroup.localId"
|
||||
/>
|
||||
</t>
|
||||
<t name="separatorCondition" t-if="!notification_last">
|
||||
<t t-if="notification.type === 'odoobotRequest'">
|
||||
<NotificationRequest
|
||||
class="o_NotificationList_notificationRequest"
|
||||
t-att-class="{ 'o-mobile': env.messaging.device.isMobile }"
|
||||
/>
|
||||
</t>
|
||||
<t t-if="!notification_last">
|
||||
<div class="o_NotificationList_separator"/>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
+7
-3
@@ -1,4 +1,4 @@
|
||||
odoo.define('mail_bot/static/src/components/notification_request/notification_request.js', function (require) {
|
||||
odoo.define('mail/static/src/components/notification_request/notification_request.js', function (require) {
|
||||
'use strict';
|
||||
|
||||
const components = {
|
||||
@@ -74,7 +74,11 @@ class NotificationRequest extends Component {
|
||||
if (def) {
|
||||
def.then(this._handleResponseNotificationPermission.bind(this));
|
||||
}
|
||||
this.trigger('o-odoobot-request-clicked');
|
||||
|
||||
const device = this.env.messaging.device;
|
||||
if (!device.isMobile) {
|
||||
this.env.messaging.messagingMenu.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -82,7 +86,7 @@ class NotificationRequest extends Component {
|
||||
Object.assign(NotificationRequest, {
|
||||
components,
|
||||
props: {},
|
||||
template: 'mail_bot.NotificationRequest',
|
||||
template: 'mail.NotificationRequest',
|
||||
});
|
||||
|
||||
return NotificationRequest;
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="mail_bot.NotificationRequest" owl="1">
|
||||
<t t-name="mail.NotificationRequest" owl="1">
|
||||
<div class="o_NotificationRequest" t-on-click="_onClick">
|
||||
<div class="o_NotificationRequest_sidebar">
|
||||
<div class="o_NotificationRequest_imageContainer o_NotificationRequest_sidebarItem">
|
||||
@@ -20,6 +20,16 @@ function factory(dependencies) {
|
||||
// Public
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isNotificationPermissionDefault() {
|
||||
const windowNotification = this.env.browser.Notification;
|
||||
return windowNotification
|
||||
? windowNotification.permission === 'default'
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the form view of the record with provided id and model.
|
||||
*
|
||||
|
||||
@@ -68,16 +68,15 @@ function factory(dependencies) {
|
||||
if (inboxMailbox) {
|
||||
counter += inboxMailbox.counter;
|
||||
}
|
||||
if (!this.messaging) {
|
||||
// compute after delete
|
||||
return counter;
|
||||
}
|
||||
if (this.messaging.notificationGroupManager) {
|
||||
counter += this.messaging.notificationGroupManager.groups.reduce(
|
||||
(total, group) => total + group.notifications.length,
|
||||
0
|
||||
);
|
||||
}
|
||||
if (this.messaging.isNotificationPermissionDefault()) {
|
||||
counter++;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
odoo.define('mail_bot/static/src/widgets/notification_alert/notification_alert.js', function (require) {
|
||||
odoo.define('mail/static/src/widgets/notification_alert/notification_alert.js', function (require) {
|
||||
"use strict";
|
||||
|
||||
const components = {
|
||||
NotificationAlert: require('mail_bot/static/src/components/notification_alert/notification_alert.js'),
|
||||
NotificationAlert: require('mail/static/src/components/notification_alert/notification_alert.js'),
|
||||
};
|
||||
|
||||
const { ComponentWrapper, WidgetAdapterMixin } = require('web.OwlCompatibility');
|
||||
+4
-2
@@ -1,12 +1,13 @@
|
||||
odoo.define('mail_bot/static/src/widgets/notification_alert/notification_alert_tests.js', function (require) {
|
||||
odoo.define('mail/static/src/widgets/notification_alert/notification_alert_tests.js', function (require) {
|
||||
'use strict';
|
||||
|
||||
const { afterEach, beforeEach, start } = require('mail/static/src/utils/test_utils.js');
|
||||
|
||||
const FormView = require('web.FormView');
|
||||
|
||||
QUnit.module('mail_bot', {}, function () {
|
||||
QUnit.module('mail', {}, function () {
|
||||
QUnit.module('widgets', {}, function () {
|
||||
QUnit.module('notification_alert', {}, function () {
|
||||
QUnit.module('notification_alert_tests.js', {
|
||||
beforeEach() {
|
||||
beforeEach(this);
|
||||
@@ -95,6 +96,7 @@ QUnit.test('notification_alert widget: no notification alert when default', asyn
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,9 +101,11 @@
|
||||
<script type="text/javascript" src="/mail/static/src/components/moderation_ban_dialog/moderation_ban_dialog.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/moderation_discard_dialog/moderation_discard_dialog.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/moderation_reject_dialog/moderation_reject_dialog.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/notification_alert/notification_alert.js"/>
|
||||
<script type="text/javascript" src="/mail/static/src/components/notification_group/notification_group.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/notification_list/notification_list.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/notification_popover/notification_popover.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/notification_request/notification_request.js"/>
|
||||
<script type="text/javascript" src="/mail/static/src/components/partner_im_status_icon/partner_im_status_icon.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/partner_mention_suggestion/partner_mention_suggestion.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/thread_icon/thread_icon.js"></script>
|
||||
@@ -160,6 +162,7 @@
|
||||
<script type="text/javascript" src="/mail/static/src/widgets/discuss_invite_partner_dialog/discuss_invite_partner_dialog.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/widgets/form_renderer/form_renderer.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/widgets/messaging_menu/messaging_menu.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/widgets/notification_alert/notification_alert.js"/>
|
||||
|
||||
<!-- notification_list_item.scss contains variables/mixins, it must be positioned before sub-components of NotificationList -->
|
||||
<link rel="stylesheet" type="text/scss" href="/mail/static/src/components/notification_list/notification_list_item.scss"/>
|
||||
@@ -203,6 +206,7 @@
|
||||
<link rel="stylesheet" type="text/scss" href="/mail/static/src/components/notification_group/notification_group.scss"/>
|
||||
<link rel="stylesheet" type="text/scss" href="/mail/static/src/components/notification_list/notification_list.scss"/>
|
||||
<link rel="stylesheet" type="text/scss" href="/mail/static/src/components/notification_popover/notification_popover.scss"/>
|
||||
<link rel="stylesheet" type="text/scss" href="/mail/static/src/components/notification_request/notification_request.scss"/>
|
||||
<link rel="stylesheet" type="text/scss" href="/mail/static/src/components/partner_im_status_icon/partner_im_status_icon.scss"/>
|
||||
<link rel="stylesheet" type="text/scss" href="/mail/static/src/components/partner_mention_suggestion/partner_mention_suggestion.scss"/>
|
||||
<link rel="stylesheet" type="text/scss" href="/mail/static/src/components/thread_icon/thread_icon.scss"/>
|
||||
@@ -277,8 +281,8 @@
|
||||
<script type="text/javascript" src="/mail/static/src/components/partner_im_status_icon/partner_im_status_icon_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/partner_mention_suggestion/partner_mention_suggestion_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/thread_icon/thread_icon_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/thread_preview/thread_preview_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/thread_preview/thread_preview_tests.js"/>
|
||||
<script type="text/javascript" src="/mail/static/src/components/thread_textual_typing_status/thread_textual_typing_status_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/components/thread_viewer/thread_viewer_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/models/attachment/attachment_tests.js"></script>
|
||||
@@ -288,6 +292,7 @@
|
||||
<script type="text/javascript" src="/mail/static/src/utils/throttle/throttle_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/utils/timer/timer_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/widgets/form_renderer/form_renderer_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail/static/src/widgets/notification_alert/notification_alert_tests.js"/>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
|
||||
@@ -8,11 +8,14 @@
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base.view_users_form_simple_modif"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<field name="email" position="before">
|
||||
<field name="notification_type" widget="radio" readonly="0"/>
|
||||
</field>
|
||||
</data>
|
||||
<data>
|
||||
<field name="email" position="before">
|
||||
<field name="notification_type" widget="radio" readonly="0"/>
|
||||
</field>
|
||||
<xpath expr="//field[@name='image_1920']" position="before">
|
||||
<widget name="notification_alert"/>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
{
|
||||
'name': 'OdooBot',
|
||||
'version': '1.1',
|
||||
'version': '1.2',
|
||||
'category': 'Productivity/Discuss',
|
||||
'summary': 'Add OdooBot in discussions',
|
||||
'description': "",
|
||||
@@ -21,9 +21,5 @@
|
||||
],
|
||||
'qweb': [
|
||||
'static/src/bugfix/bugfix.xml',
|
||||
'static/src/components/messaging_menu/messaging_menu.xml',
|
||||
'static/src/components/notification_alert/notification_alert.xml',
|
||||
'static/src/components/notification_list/notification_list.xml',
|
||||
'static/src/components/notification_request/notification_request.xml',
|
||||
],
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="base.partner_root" model="res.partner">
|
||||
<field name="name">OdooBot</field>
|
||||
<field name="email">odoobot@example.com</field>
|
||||
<field name="image_1920" type="base64" file="mail/static/src/img/odoobot.png"/>
|
||||
</record>
|
||||
|
||||
<record id="base.user_root" model="res.users">
|
||||
<field name="odoobot_state">disabled</field>
|
||||
</record>
|
||||
|
||||
@@ -5,5 +5,4 @@ from . import ir_http
|
||||
from . import mail_bot
|
||||
from . import mail_channel
|
||||
from . import mail_thread
|
||||
from . import res_partner
|
||||
from . import res_users
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class Partner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
def _compute_im_status(self):
|
||||
#we asume that mail_bot _compute_im_status will be executed after bus _compute_im_status
|
||||
super(Partner, self)._compute_im_status()
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("base.partner_root")
|
||||
for partner in self:
|
||||
if partner.id == odoobot_id:
|
||||
partner.im_status = 'bot'
|
||||
|
||||
@api.model
|
||||
def get_mention_suggestions(self, search, limit=8):
|
||||
#add odoobot in mention suggestion when pinging in mail_thread
|
||||
[users, partners] = super(Partner, self).get_mention_suggestions(search, limit=limit)
|
||||
if len(partners) + len(users) < limit and "odoobot".startswith(search.lower()):
|
||||
odoobot = self.env.ref("base.partner_root")
|
||||
if odoobot and not any(elem['id'] == odoobot.id for elem in partners):
|
||||
partners.append({'id': odoobot.id, 'name': odoobot.name, 'email': odoobot.email})
|
||||
return [users, partners]
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
odoo.define('mail_bot/static/src/components/messaging_menu/messaging_menu,js', function (require) {
|
||||
'use strict';
|
||||
|
||||
const components = {
|
||||
MessagingMenu: require('mail/static/src/components/messaging_menu/messaging_menu.js'),
|
||||
};
|
||||
|
||||
const { patch } = require('web.utils');
|
||||
|
||||
patch(components.MessagingMenu, 'mail_bot/static/src/components/messaging_menu/messaging_menu,js', {
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_onOdoobotRequestClicked() {
|
||||
const device = this.messagingMenu.messaging.device;
|
||||
if (!device.isMobile) {
|
||||
this.messagingMenu.close();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-inherit="mail.MessagingMenu" t-inherit-mode="extension">
|
||||
<xpath expr="//NotificationList" position="attributes">
|
||||
<attribute name="t-on-o-odoobot-request-clicked" t-translation="off">_onOdoobotRequestClicked</attribute>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -1,175 +0,0 @@
|
||||
odoo.define('mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js', function (require) {
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
afterEach,
|
||||
afterNextRender,
|
||||
beforeEach,
|
||||
start,
|
||||
} = require('mail/static/src/utils/test_utils.js');
|
||||
|
||||
QUnit.module('mail_bot', {}, function () {
|
||||
QUnit.module('components', {}, function () {
|
||||
QUnit.module('messaging_menu', {}, function () {
|
||||
QUnit.module('messaging_menu_tests.js', {
|
||||
beforeEach() {
|
||||
beforeEach(this);
|
||||
|
||||
this.start = async params => {
|
||||
let { widget } = await start(Object.assign({}, params, {
|
||||
data: this.data,
|
||||
hasMessagingMenu: true,
|
||||
}));
|
||||
this.widget = widget;
|
||||
};
|
||||
},
|
||||
afterEach() {
|
||||
afterEach(this);
|
||||
},
|
||||
});
|
||||
|
||||
QUnit.test('rendering with OdooBot has a request (default)', async function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
await this.start({
|
||||
env: {
|
||||
browser: {
|
||||
Notification: {
|
||||
permission: 'default',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.ok(
|
||||
document.querySelector('.o_MessagingMenu_counter'),
|
||||
"should display a notification counter next to the messaging menu for OdooBot request"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelector('.o_MessagingMenu_counter').textContent,
|
||||
"1",
|
||||
"should display a counter of '1' next to the messaging menu"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_NotificationRequest',
|
||||
"should display a notification in the messaging menu"
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelector('.o_NotificationRequest_name').textContent.trim(),
|
||||
'OdooBot has a request',
|
||||
"notification should display that OdooBot has a request"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('rendering without OdooBot has a request (denied)', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
await this.start({
|
||||
env: {
|
||||
browser: {
|
||||
Notification: {
|
||||
permission: 'denied',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_MessagingMenu_counter',
|
||||
"should not display a notification counter next to the messaging menu"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_NotificationRequest',
|
||||
"should display no notification in the messaging menu"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('rendering without OdooBot has a request (accepted)', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
await this.start({
|
||||
env: {
|
||||
browser: {
|
||||
Notification: {
|
||||
permission: 'granted',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_MessagingMenu_counter',
|
||||
"should not display a notification counter next to the messaging menu"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_NotificationRequest',
|
||||
"should display no notification in the messaging menu"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('respond to notification prompt (denied)', async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
await this.start({
|
||||
env: {
|
||||
browser: {
|
||||
Notification: {
|
||||
permission: 'default',
|
||||
async requestPermission() {
|
||||
this.permission = 'denied';
|
||||
return this.permission;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_NotificationRequest').click()
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.toast .o_notification_content',
|
||||
"should display a toast notification with the deny confirmation"
|
||||
);
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_MessagingMenu_counter',
|
||||
"should not display a notification counter next to the messaging menu"
|
||||
);
|
||||
|
||||
await afterNextRender(() =>
|
||||
document.querySelector('.o_MessagingMenu_toggler').click()
|
||||
);
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_NotificationRequest',
|
||||
"should display no notification in the messaging menu"
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,44 +0,0 @@
|
||||
odoo.define('mail_bot/static/src/components/notification_list/notification_list.js', function (require) {
|
||||
'use strict';
|
||||
|
||||
const components = {
|
||||
mail: {
|
||||
NotificationList: require('mail/static/src/components/notification_list/notification_list.js'),
|
||||
},
|
||||
mail_bot: {
|
||||
NotificationRequest: require('mail_bot/static/src/components/notification_request/notification_request.js'),
|
||||
},
|
||||
};
|
||||
|
||||
const { patch } = require('web.utils');
|
||||
|
||||
Object.assign(components.mail.NotificationList.components, components.mail_bot);
|
||||
|
||||
patch(components.mail.NotificationList, 'mail_bot/static/src/components/notification_list/notification_list.js', {
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Override so that 'OdooBot has a request' is included at the top of the
|
||||
* list.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
_useStoreSelector(props) {
|
||||
const res = this._super(...arguments);
|
||||
if (
|
||||
props.filter === 'all' &&
|
||||
this.env.messaging.isNotificationPermissionDefault()
|
||||
) {
|
||||
res.notifications.unshift({
|
||||
type: 'odoobotRequest',
|
||||
uniqueId: `odoobotRequest`,
|
||||
});
|
||||
}
|
||||
return res;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-inherit="mail.NotificationList" t-inherit-mode="extension">
|
||||
<xpath expr="//*[@name='separatorCondition']" position="before">
|
||||
<t t-if="notification.type === 'odoobotRequest'">
|
||||
<NotificationRequest
|
||||
class="o_NotificationList_notificationRequest"
|
||||
t-att-class="{ 'o-mobile': env.messaging.device.isMobile }"
|
||||
/>
|
||||
</t>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -8,15 +8,6 @@ registerInstancePatchModel('mail.messaging', 'mail_bot/static/src/models/messagi
|
||||
// Public
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isNotificationPermissionDefault() {
|
||||
const windowNotification = this.env.browser.Notification;
|
||||
return windowNotification
|
||||
? windowNotification.permission === 'default'
|
||||
: false;
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
odoo.define('mail_bot/static/src/models/messaging_menu/messaging_menu.js', function (require) {
|
||||
'use strict';
|
||||
|
||||
const { registerInstancePatchModel } = require('mail/static/src/model/model_core.js');
|
||||
|
||||
registerInstancePatchModel('mail.messaging_menu', 'mail_bot/static/src/models/messaging_menu/messaging_menu.js', {
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Private
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_updateCounter() {
|
||||
let counter = this._super();
|
||||
if (!this.messaging) {
|
||||
// compute after delete
|
||||
return counter;
|
||||
}
|
||||
if (this.messaging.isNotificationPermissionDefault()) {
|
||||
counter += 1;
|
||||
}
|
||||
return counter;
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
@@ -4,19 +4,11 @@
|
||||
<template id="assets_backend" name="mailbot assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="script[last()]" position="after">
|
||||
<script type="text/javascript" src="/mail_bot/static/src/bugfix/bugfix.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/components/messaging_menu/messaging_menu.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/components/notification_alert/notification_alert.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/components/notification_list/notification_list.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/components/notification_request/notification_request.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/models/messaging/messaging.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/models/messaging_initializer/messaging_initializer.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/models/messaging_menu/messaging_menu.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/widgets/notification_alert/notification_alert.js"></script>
|
||||
</xpath>
|
||||
<xpath expr="link[last()]" position="after">
|
||||
<link rel="stylesheet" type="text/scss" href="/mail_bot/static/src/scss/odoobot_style.scss"/>
|
||||
<link rel="stylesheet" type="text/scss" href="/mail_bot/static/src/bugfix/bugfix.scss"/>
|
||||
<link rel="stylesheet" type="text/scss" href="/mail_bot/static/src/components/notification_request/notification_request.scss"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
@@ -29,9 +21,7 @@
|
||||
<template id="qunit_suite" name="mailbot_tests" inherit_id="web.qunit_suite_tests">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/mail_bot/static/src/bugfix/bugfix_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/widgets/notification_alert/notification_alert_tests.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
|
||||
@@ -27,17 +27,4 @@
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Blocked notification alert -->
|
||||
<record id="view_users_form_inherit_mail_notification_alert" model="ir.ui.view">
|
||||
<field name="name">res.users.preferences.form.notification.alert</field>
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base.view_users_form_simple_modif"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='image_1920']" position="before">
|
||||
<widget name="notification_alert"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data></odoo>
|
||||
|
||||
Reference in New Issue
Block a user