[IMP] mail_bot: Blocked notification alert to User
If user has blocked odoo push notifications then there's no way to enable via the OdooBot notification in the systray as it depends on the navigator so display the alert message under users preference section. Related Task ID: 1929547 closes odoo/odoo#30496
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
odoo.define('mail.NotificationAlert', function (require) {
|
||||
"use strict";
|
||||
|
||||
var Widget = require('web.Widget');
|
||||
var widgetRegistry = require('web.widget_registry');
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Display Notification alert on user preferences form view
|
||||
// -----------------------------------------------------------------------------
|
||||
var NotificationAlert = Widget.extend({
|
||||
template: 'mail.NotificationAlert',
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
var hasRequest = this.call('mailbot_service', 'isRequestingForNativeNotifications');
|
||||
this.isNotificationBlocked = window.Notification && window.Notification.permission !== "granted" && !hasRequest;
|
||||
},
|
||||
});
|
||||
|
||||
widgetRegistry.add('notification_alert', NotificationAlert);
|
||||
|
||||
return NotificationAlert;
|
||||
|
||||
});
|
||||
@@ -6,6 +6,7 @@ var mailTestUtils = require('mail.testUtils');
|
||||
|
||||
var MailBotService = require('mail_bot.MailBotService');
|
||||
|
||||
var FormView = require('web.FormView');
|
||||
var testUtils = require('web.test_utils');
|
||||
|
||||
QUnit.module('mail_bot', {}, function () {
|
||||
@@ -169,6 +170,27 @@ QUnit.test('messaging menu widget: respond to notification prompt', function (as
|
||||
messagingMenu.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('notification_alert widget: display blocked notification alert', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
window.Notification.permission = 'denied';
|
||||
|
||||
var form = testUtils.createView({
|
||||
View: FormView,
|
||||
model: 'mail.message',
|
||||
data: this.data,
|
||||
arch: '<form>' +
|
||||
'<widget name="notification_alert"/>' +
|
||||
'</form>',
|
||||
});
|
||||
assert.containsOnce(form, '.o_notification_alert', "Blocked notification alert should be displayed");
|
||||
|
||||
window.Notification.permission = 'granted';
|
||||
form.reload();
|
||||
assert.containsNone(form, '.o_notification_alert', "Blocked notification alert should not be displayed");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<template id="assets_backend" name="mailbot assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/mail_bot/static/src/js/mailbot_service.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/js/notification_alert.js"></script>
|
||||
<script type="text/javascript" src="/mail_bot/static/src/js/systray_messaging_menu.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
@@ -5,4 +5,13 @@
|
||||
<i t-if="status == 'bot'" class="o_mail_user_status o_user_online fa fa-heart" title="Bot" role="img" aria-label="User is a bot"/>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
<!--
|
||||
@param {mail.NotificationAlert} widget
|
||||
-->
|
||||
<t t-name="mail.NotificationAlert">
|
||||
<center t-if="widget.isNotificationBlocked" class="o_notification_alert alert alert-primary">
|
||||
Odoo Push notifications have been blocked. Go to your browser settings to allow them.
|
||||
</center>
|
||||
</t>
|
||||
</templates>
|
||||
|
||||
@@ -27,4 +27,17 @@
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
</data></odoo>
|
||||
|
||||
<!-- 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']" position="before">
|
||||
<widget name="notification_alert"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data></odoo>
|
||||
|
||||
Reference in New Issue
Block a user