From 0a7dbf58e44e1ee886a79c0b518f48affff1618c Mon Sep 17 00:00:00 2001 From: SilvioC2C Date: Fri, 16 Feb 2024 12:58:43 +0100 Subject: [PATCH] [IMP] web_notify: allow passing custom parameters to notifications --- web_notify/models/res_users.py | 17 ++++++++++++----- web_notify/tests/test_res_users.py | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/web_notify/models/res_users.py b/web_notify/models/res_users.py index 1bea86266..11339fd6f 100644 --- a/web_notify/models/res_users.py +++ b/web_notify/models/res_users.py @@ -49,9 +49,10 @@ class ResUsers(models.Model): sticky=False, target=None, action=None, + params=None, ): title = title or _("Success") - self._notify_channel(SUCCESS, message, title, sticky, target, action) + self._notify_channel(SUCCESS, message, title, sticky, target, action, params) def notify_danger( self, @@ -60,9 +61,10 @@ class ResUsers(models.Model): sticky=False, target=None, action=None, + params=None, ): title = title or _("Danger") - self._notify_channel(DANGER, message, title, sticky, target, action) + self._notify_channel(DANGER, message, title, sticky, target, action, params) def notify_warning( self, @@ -71,9 +73,10 @@ class ResUsers(models.Model): sticky=False, target=None, action=None, + params=None, ): title = title or _("Warning") - self._notify_channel(WARNING, message, title, sticky, target, action) + self._notify_channel(WARNING, message, title, sticky, target, action, params) def notify_info( self, @@ -82,9 +85,10 @@ class ResUsers(models.Model): sticky=False, target=None, action=None, + params=None, ): title = title or _("Information") - self._notify_channel(INFO, message, title, sticky, target, action) + self._notify_channel(INFO, message, title, sticky, target, action, params) def notify_default( self, @@ -93,9 +97,10 @@ class ResUsers(models.Model): sticky=False, target=None, action=None, + params=None, ): title = title or _("Default") - self._notify_channel(DEFAULT, message, title, sticky, target, action) + self._notify_channel(DEFAULT, message, title, sticky, target, action, params) def _notify_channel( self, @@ -105,6 +110,7 @@ class ResUsers(models.Model): sticky=False, target=None, action=None, + params=None, ): if not (self.env.user._is_admin() or self.env.su) and any( user.id != self.env.uid for user in self @@ -122,6 +128,7 @@ class ResUsers(models.Model): "title": title, "sticky": sticky, "action": action, + "params": dict(params or []), } notifications = [[partner, "web.notify", [bus_message]] for partner in target] diff --git a/web_notify/tests/test_res_users.py b/web_notify/tests/test_res_users.py index 76fedc118..f05e6709a 100644 --- a/web_notify/tests/test_res_users.py +++ b/web_notify/tests/test_res_users.py @@ -19,6 +19,7 @@ class TestResUsers(common.TransactionCase): "title": "title", "sticky": True, "action": None, + "params": {}, } self.env.user.notify_success(**test_msg) news = bus_bus.search(domain) - existing @@ -36,6 +37,7 @@ class TestResUsers(common.TransactionCase): "title": "title", "sticky": True, "action": None, + "params": {}, } self.env.user.notify_danger(**test_msg) news = bus_bus.search(domain) - existing @@ -53,6 +55,7 @@ class TestResUsers(common.TransactionCase): "title": "title", "sticky": True, "action": None, + "params": {}, } self.env.user.notify_warning(**test_msg) news = bus_bus.search(domain) - existing @@ -70,6 +73,7 @@ class TestResUsers(common.TransactionCase): "title": "title", "sticky": True, "action": None, + "params": {}, } self.env.user.notify_info(**test_msg) news = bus_bus.search(domain) - existing @@ -87,6 +91,7 @@ class TestResUsers(common.TransactionCase): "title": "title", "sticky": True, "action": None, + "params": {}, } self.env.user.notify_default(**test_msg) news = bus_bus.search(domain) - existing