mirror of https://github.com/OCA/web.git
[IMP] web_notify: allow passing custom parameters to notifications
parent
59cce05f0c
commit
2a5e51457e
|
@ -32,28 +32,43 @@ class ResUsers(models.Model):
|
|||
notify_info_channel_name = fields.Char(compute="_compute_channel_names")
|
||||
notify_default_channel_name = fields.Char(compute="_compute_channel_names")
|
||||
|
||||
def notify_success(self, message="Default message", title=None, sticky=False):
|
||||
def notify_success(
|
||||
self, message="Default message", title=None, sticky=False, params=None
|
||||
):
|
||||
title = title or _("Success")
|
||||
self._notify_channel(SUCCESS, message, title, sticky)
|
||||
self._notify_channel(SUCCESS, message, title, sticky, params)
|
||||
|
||||
def notify_danger(self, message="Default message", title=None, sticky=False):
|
||||
def notify_danger(
|
||||
self, message="Default message", title=None, sticky=False, params=None
|
||||
):
|
||||
title = title or _("Danger")
|
||||
self._notify_channel(DANGER, message, title, sticky)
|
||||
self._notify_channel(DANGER, message, title, sticky, params)
|
||||
|
||||
def notify_warning(self, message="Default message", title=None, sticky=False):
|
||||
def notify_warning(
|
||||
self, message="Default message", title=None, sticky=False, params=None
|
||||
):
|
||||
title = title or _("Warning")
|
||||
self._notify_channel(WARNING, message, title, sticky)
|
||||
self._notify_channel(WARNING, message, title, sticky, params)
|
||||
|
||||
def notify_info(self, message="Default message", title=None, sticky=False):
|
||||
def notify_info(
|
||||
self, message="Default message", title=None, sticky=False, params=None
|
||||
):
|
||||
title = title or _("Information")
|
||||
self._notify_channel(INFO, message, title, sticky)
|
||||
self._notify_channel(INFO, message, title, sticky, params)
|
||||
|
||||
def notify_default(self, message="Default message", title=None, sticky=False):
|
||||
def notify_default(
|
||||
self, message="Default message", title=None, sticky=False, params=None
|
||||
):
|
||||
title = title or _("Default")
|
||||
self._notify_channel(DEFAULT, message, title, sticky)
|
||||
self._notify_channel(DEFAULT, message, title, sticky, params)
|
||||
|
||||
def _notify_channel(
|
||||
self, type_message=DEFAULT, message=DEFAULT_MESSAGE, title=None, sticky=False
|
||||
self,
|
||||
type_message=DEFAULT,
|
||||
message=DEFAULT_MESSAGE,
|
||||
title=None,
|
||||
sticky=False,
|
||||
params=None,
|
||||
):
|
||||
# pylint: disable=protected-access
|
||||
if not (self.env.user._is_admin() or self.env.su) and any(
|
||||
|
@ -68,6 +83,7 @@ class ResUsers(models.Model):
|
|||
"message": message,
|
||||
"title": title,
|
||||
"sticky": sticky,
|
||||
"params": dict(params or []),
|
||||
}
|
||||
notifications = [(record[channel_name_field], bus_message) for record in self]
|
||||
self.env["bus.bus"].sendmany(notifications)
|
||||
|
|
|
@ -19,7 +19,12 @@ class TestResUsers(common.TransactionCase):
|
|||
("channel", "=", json_dump(self.env.user.notify_success_channel_name))
|
||||
]
|
||||
existing = bus_bus.search(domain)
|
||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||
test_msg = {
|
||||
"message": "message",
|
||||
"title": "title",
|
||||
"sticky": True,
|
||||
"params": {},
|
||||
}
|
||||
self.env.user.notify_success(**test_msg)
|
||||
news = bus_bus.search(domain) - existing
|
||||
self.assertEqual(1, len(news))
|
||||
|
@ -30,7 +35,12 @@ class TestResUsers(common.TransactionCase):
|
|||
bus_bus = self.env["bus.bus"]
|
||||
domain = [("channel", "=", json_dump(self.env.user.notify_danger_channel_name))]
|
||||
existing = bus_bus.search(domain)
|
||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||
test_msg = {
|
||||
"message": "message",
|
||||
"title": "title",
|
||||
"sticky": True,
|
||||
"params": {},
|
||||
}
|
||||
self.env.user.notify_danger(**test_msg)
|
||||
news = bus_bus.search(domain) - existing
|
||||
self.assertEqual(1, len(news))
|
||||
|
@ -43,7 +53,12 @@ class TestResUsers(common.TransactionCase):
|
|||
("channel", "=", json_dump(self.env.user.notify_warning_channel_name))
|
||||
]
|
||||
existing = bus_bus.search(domain)
|
||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||
test_msg = {
|
||||
"message": "message",
|
||||
"title": "title",
|
||||
"sticky": True,
|
||||
"params": {},
|
||||
}
|
||||
self.env.user.notify_warning(**test_msg)
|
||||
news = bus_bus.search(domain) - existing
|
||||
self.assertEqual(1, len(news))
|
||||
|
@ -54,7 +69,12 @@ class TestResUsers(common.TransactionCase):
|
|||
bus_bus = self.env["bus.bus"]
|
||||
domain = [("channel", "=", json_dump(self.env.user.notify_info_channel_name))]
|
||||
existing = bus_bus.search(domain)
|
||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||
test_msg = {
|
||||
"message": "message",
|
||||
"title": "title",
|
||||
"sticky": True,
|
||||
"params": {},
|
||||
}
|
||||
self.env.user.notify_info(**test_msg)
|
||||
news = bus_bus.search(domain) - existing
|
||||
self.assertEqual(1, len(news))
|
||||
|
@ -67,7 +87,12 @@ class TestResUsers(common.TransactionCase):
|
|||
("channel", "=", json_dump(self.env.user.notify_default_channel_name))
|
||||
]
|
||||
existing = bus_bus.search(domain)
|
||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||
test_msg = {
|
||||
"message": "message",
|
||||
"title": "title",
|
||||
"sticky": True,
|
||||
"params": {},
|
||||
}
|
||||
self.env.user.notify_default(**test_msg)
|
||||
news = bus_bus.search(domain) - existing
|
||||
self.assertEqual(1, len(news))
|
||||
|
|
Loading…
Reference in New Issue