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 + + + + + + + + +