summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuhil Somaiya <jso@odoo.com>2019-01-23 09:32:01 +0000
committerJuhil Somaiya <jso@odoo.com>2019-02-15 09:05:54 +0000
commit02eebe15cd895b54f45cbcef1affcaa61ec8577c (patch)
tree85d7ddee92dbe048aabf43243a0e2c949ad516db
parentb35d103cc0fe64547c3212ef01ab329faf0bacc4 (diff)
[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
-rw-r--r--addons/mail_bot/static/src/js/notification_alert.js26
-rw-r--r--addons/mail_bot/static/tests/systray_messaging_menu_tests.js22
-rw-r--r--addons/mail_bot/views/assets.xml1
-rw-r--r--addons/mail_bot/views/discuss.xml9
-rw-r--r--addons/mail_bot/views/res_users_views.xml15
5 files changed, 72 insertions, 1 deletions
diff --git a/addons/mail_bot/static/src/js/notification_alert.js b/addons/mail_bot/static/src/js/notification_alert.js
new file mode 100644
index 00000000000..48b105dfe48
--- /dev/null
+++ b/addons/mail_bot/static/src/js/notification_alert.js
@@ -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;
+
+});
diff --git a/addons/mail_bot/static/tests/systray_messaging_menu_tests.js b/addons/mail_bot/static/tests/systray_messaging_menu_tests.js
index d22c9ca80da..9cae63a9b1c 100644
--- a/addons/mail_bot/static/tests/systray_messaging_menu_tests.js
+++ b/addons/mail_bot/static/tests/systray_messaging_menu_tests.js
@@ -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();
+});
});
});
diff --git a/addons/mail_bot/views/assets.xml b/addons/mail_bot/views/assets.xml
index 43c9a37e694..45189d82715 100644
--- a/addons/mail_bot/views/assets.xml
+++ b/addons/mail_bot/views/assets.xml
@@ -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>
diff --git a/addons/mail_bot/views/discuss.xml b/addons/mail_bot/views/discuss.xml
index 95526e6b11a..7f4de461193 100644
--- a/addons/mail_bot/views/discuss.xml
+++ b/addons/mail_bot/views/discuss.xml
@@ -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>
diff --git a/addons/mail_bot/views/res_users_views.xml b/addons/mail_bot/views/res_users_views.xml
index 066ae58bd48..296e5380485 100644
--- a/addons/mail_bot/views/res_users_views.xml
+++ b/addons/mail_bot/views/res_users_views.xml
@@ -27,4 +27,17 @@
</data>
</field>
</record>
-</data></odoo> \ No newline at end of file
+
+ <!-- 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>