From 1e7ddfe8dedd0dd7df136337ccffac3562067759 Mon Sep 17 00:00:00 2001 From: Nikul-OSI Date: Wed, 14 Feb 2024 11:30:20 +0530 Subject: [PATCH] [MIG] web_notify: Migrated in v17 --- web_notify/README.rst | 7 ++++ web_notify/pyproject.toml | 3 ++ web_notify/readme/CONTRIBUTORS.md | 9 +++++ web_notify/readme/DESCRIPTION.md | 11 ++++++ web_notify/readme/INSTALL.md | 2 + web_notify/readme/USAGE.md | 39 +++++++++++++++++++ web_notify/static/description/index.html | 1 + .../src/js/services/notification.esm.js | 4 +- .../js/services/notification_services.esm.js | 5 ++- web_notify/tests/test_res_users.py | 8 +++- web_notify/views/res_users_demo.xml | 30 +++++++------- 11 files changed, 99 insertions(+), 20 deletions(-) create mode 100644 web_notify/pyproject.toml create mode 100644 web_notify/readme/CONTRIBUTORS.md create mode 100644 web_notify/readme/DESCRIPTION.md create mode 100644 web_notify/readme/INSTALL.md create mode 100644 web_notify/readme/USAGE.md diff --git a/web_notify/README.rst b/web_notify/README.rst index da426a0e9316..c529e89eab94 100644 --- a/web_notify/README.rst +++ b/web_notify/README.rst @@ -120,14 +120,21 @@ Contributors ------------ - Laurent Mignon + - Serpent Consulting Services Pvt. Ltd. + - Aitor Bouzas + - Shepilov Vladislav + - Kevin Khao + - `Tecnativa `__: - David Vidal +- Nikul Chaudhary + Maintainers ----------- diff --git a/web_notify/pyproject.toml b/web_notify/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/web_notify/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_notify/readme/CONTRIBUTORS.md b/web_notify/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..32cdd9fd963b --- /dev/null +++ b/web_notify/readme/CONTRIBUTORS.md @@ -0,0 +1,9 @@ +- Laurent Mignon \<\> +- Serpent Consulting Services Pvt. Ltd.\<\> +- Aitor Bouzas \<\> +- Shepilov Vladislav \<\> +- Kevin Khao \<\> +- [Tecnativa](https://www.tecnativa.com): + - David Vidal + +- Nikul Chaudhary \<\> diff --git a/web_notify/readme/DESCRIPTION.md b/web_notify/readme/DESCRIPTION.md new file mode 100644 index 000000000000..003a0133e18a --- /dev/null +++ b/web_notify/readme/DESCRIPTION.md @@ -0,0 +1,11 @@ +Send instant notification messages to the user in live. + +This technical module allows you to send instant notification messages +from the server to the user in live. Two kinds of notification are +supported. + +- Success: Displayed in a success theme color flying popup div +- Danger: Displayed in a danger theme color flying popup div +- Warning: Displayed in a warning theme color flying popup div +- Information: Displayed in a info theme color flying popup div +- Default: Displayed in a default theme color flying popup div diff --git a/web_notify/readme/INSTALL.md b/web_notify/readme/INSTALL.md new file mode 100644 index 000000000000..0ec795793aaf --- /dev/null +++ b/web_notify/readme/INSTALL.md @@ -0,0 +1,2 @@ +This module is based on the Instant Messaging Bus. To work properly, the +server must be launched in gevent mode. diff --git a/web_notify/readme/USAGE.md b/web_notify/readme/USAGE.md new file mode 100644 index 000000000000..bd235a82a2df --- /dev/null +++ b/web_notify/readme/USAGE.md @@ -0,0 +1,39 @@ +To send a notification to the user you just need to call one of the new +methods defined on res.users: + +``` python +self.env.user.notify_success(message='My success message') +``` + +or + +``` python +self.env.user.notify_danger(message='My danger message') +``` + +or + +``` python +self.env.user.notify_warning(message='My warning message') +``` + +or + +``` python +self.env.user.notify_info(message='My information message') +``` + +or + +``` python +self.env.user.notify_default(message='My default message') +``` + +![](static/description/notifications_screenshot.gif) + +You can test the behaviour of the notifications by installing this +module in a demo database. Access the users form through Settings -\> +Users & Companies. You'll see a tab called "Test web notify", here +you'll find two buttons that'll allow you test the module. + +![](static/description/test_notifications_demo.png) diff --git a/web_notify/static/description/index.html b/web_notify/static/description/index.html index 0de9cf6a9658..876386a09a3b 100644 --- a/web_notify/static/description/index.html +++ b/web_notify/static/description/index.html @@ -459,6 +459,7 @@

Contributors

  • David Vidal
  • +
  • Nikul Chaudhary <nchaudhary@opensourceintegrators.com>
  • diff --git a/web_notify/static/src/js/services/notification.esm.js b/web_notify/static/src/js/services/notification.esm.js index 489faddd31e6..7f8c281367d2 100644 --- a/web_notify/static/src/js/services/notification.esm.js +++ b/web_notify/static/src/js/services/notification.esm.js @@ -1,8 +1,8 @@ /** @odoo-module */ import {Notification} from "@web/core/notifications/notification"; -import {patch} from "web.utils"; +import {patch} from "@web/core/utils/patch"; -patch(Notification.props, "webNotifyProps", { +patch(Notification.props, { type: { type: String, optional: true, diff --git a/web_notify/static/src/js/services/notification_services.esm.js b/web_notify/static/src/js/services/notification_services.esm.js index d364150a1c26..1a67665a77e9 100644 --- a/web_notify/static/src/js/services/notification_services.esm.js +++ b/web_notify/static/src/js/services/notification_services.esm.js @@ -1,5 +1,6 @@ /** @odoo-module **/ -import {Markup} from "web.utils"; + +import {markup} from "@odoo/owl"; import {browser} from "@web/core/browser/browser"; import {registry} from "@web/core/registry"; @@ -20,7 +21,7 @@ export const webNotificationService = { notifications.forEach(function (notif) { browser.setTimeout(function () { - notification.add(Markup(notif.message), { + notification.add(markup(notif.message), { title: notif.title, type: notif.type, sticky: notif.sticky, diff --git a/web_notify/tests/test_res_users.py b/web_notify/tests/test_res_users.py index 6f3f34493f28..ed48e2bf3d48 100644 --- a/web_notify/tests/test_res_users.py +++ b/web_notify/tests/test_res_users.py @@ -3,7 +3,7 @@ import json -from odoo import exceptions +from odoo import SUPERUSER_ID, exceptions from odoo.tests import common from ..models.res_users import DANGER, DEFAULT, INFO, SUCCESS, WARNING @@ -84,6 +84,12 @@ def test_notify_other_user(self): with self.assertRaises(exceptions.UserError): other_user_model.browse(self.env.uid).notify_info(message="hello") + def test_notify_sudo_user(self): + other_user = self.env.ref("base.user_demo") + other_user_model = self.env["res.users"].with_user(other_user) + with self.assertRaises(exceptions.UserError): + other_user_model.browse(SUPERUSER_ID).notify_info(message="hello") + def test_notify_admin_allowed_other_user(self): other_user = self.env.ref("base.user_demo") other_user.notify_info(message="hello") diff --git a/web_notify/views/res_users_demo.xml b/web_notify/views/res_users_demo.xml index d8f286ef04bf..0f2705236165 100644 --- a/web_notify/views/res_users_demo.xml +++ b/web_notify/views/res_users_demo.xml @@ -9,52 +9,52 @@ - -