From 02eebe15cd895b54f45cbcef1affcaa61ec8577c Mon Sep 17 00:00:00 2001 From: Juhil Somaiya Date: Wed, 23 Jan 2019 09:32:01 +0000 Subject: [PATCH] [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 --- .../static/src/js/notification_alert.js | 26 +++++++++++++++++++ .../tests/systray_messaging_menu_tests.js | 22 ++++++++++++++++ addons/mail_bot/views/assets.xml | 1 + addons/mail_bot/views/discuss.xml | 9 +++++++ addons/mail_bot/views/res_users_views.xml | 15 ++++++++++- 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 addons/mail_bot/static/src/js/notification_alert.js 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: '
' + + '' + + '', + }); + 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 @@ 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 @@ + + + +
+ Odoo Push notifications have been blocked. Go to your browser settings to allow them. +
+
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 @@ - \ No newline at end of file + + + + res.users.preferences.form.notification.alert + res.users + + + + + + + + +