3
0
Fork 0

Merge PR #2697 into 15.0

Signed-off-by pedrobaeza
15.0-ocabot-merge-pr-2789-by-pedrobaeza-bump-patch
OCA-git-bot 2024-01-06 23:43:06 +00:00
commit f82258caf0
3 changed files with 68 additions and 15 deletions

View File

@ -42,34 +42,59 @@ class ResUsers(models.Model):
notify_default_channel_name = fields.Char(compute="_compute_channel_names") notify_default_channel_name = fields.Char(compute="_compute_channel_names")
def notify_success( def notify_success(
self, message="Default message", title=None, sticky=False, target=None self,
message="Default message",
title=None,
sticky=False,
target=None,
html=False,
): ):
title = title or _("Success") title = title or _("Success")
self._notify_channel(SUCCESS, message, title, sticky, target) self._notify_channel(SUCCESS, message, title, sticky, target, html)
def notify_danger( def notify_danger(
self, message="Default message", title=None, sticky=False, target=None self,
message="Default message",
title=None,
sticky=False,
target=None,
html=False,
): ):
title = title or _("Danger") title = title or _("Danger")
self._notify_channel(DANGER, message, title, sticky, target) self._notify_channel(DANGER, message, title, sticky, target, html)
def notify_warning( def notify_warning(
self, message="Default message", title=None, sticky=False, target=None self,
message="Default message",
title=None,
sticky=False,
target=None,
html=False,
): ):
title = title or _("Warning") title = title or _("Warning")
self._notify_channel(WARNING, message, title, sticky, target) self._notify_channel(WARNING, message, title, sticky, target, html)
def notify_info( def notify_info(
self, message="Default message", title=None, sticky=False, target=None self,
message="Default message",
title=None,
sticky=False,
target=None,
html=False,
): ):
title = title or _("Information") title = title or _("Information")
self._notify_channel(INFO, message, title, sticky, target) self._notify_channel(INFO, message, title, sticky, target, html)
def notify_default( def notify_default(
self, message="Default message", title=None, sticky=False, target=None self,
message="Default message",
title=None,
sticky=False,
target=None,
html=False,
): ):
title = title or _("Default") title = title or _("Default")
self._notify_channel(DEFAULT, message, title, sticky, target) self._notify_channel(DEFAULT, message, title, sticky, target, html)
def _notify_channel( def _notify_channel(
self, self,
@ -78,6 +103,7 @@ class ResUsers(models.Model):
title=None, title=None,
sticky=False, sticky=False,
target=None, target=None,
html=False,
): ):
if not (self.env.user._is_admin() or self.env.su) and any( if not (self.env.user._is_admin() or self.env.su) and any(
user.id != self.env.uid for user in self user.id != self.env.uid for user in self
@ -92,6 +118,7 @@ class ResUsers(models.Model):
"message": message, "message": message,
"title": title, "title": title,
"sticky": sticky, "sticky": sticky,
"html": html,
} }
notifications = [[partner, "web.notify", [bus_message]] for partner in target] notifications = [[partner, "web.notify", [bus_message]] for partner in target]

View File

@ -24,6 +24,7 @@ export const webNotificationService = {
type: notif.type, type: notif.type,
sticky: notif.sticky, sticky: notif.sticky,
className: notif.className, className: notif.className,
messageIsHtml: notif.html,
}); });
}); });
}); });

View File

@ -14,7 +14,12 @@ class TestResUsers(common.TransactionCase):
bus_bus = self.env["bus.bus"] bus_bus = self.env["bus.bus"]
domain = [("channel", "=", self.env.user.notify_success_channel_name)] domain = [("channel", "=", self.env.user.notify_success_channel_name)]
existing = bus_bus.search(domain) existing = bus_bus.search(domain)
test_msg = {"message": "message", "title": "title", "sticky": True} test_msg = {
"message": "message",
"title": "title",
"sticky": True,
"html": False,
}
self.env.user.notify_success(**test_msg) self.env.user.notify_success(**test_msg)
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))
@ -26,7 +31,12 @@ class TestResUsers(common.TransactionCase):
bus_bus = self.env["bus.bus"] bus_bus = self.env["bus.bus"]
domain = [("channel", "=", self.env.user.notify_danger_channel_name)] domain = [("channel", "=", self.env.user.notify_danger_channel_name)]
existing = bus_bus.search(domain) existing = bus_bus.search(domain)
test_msg = {"message": "message", "title": "title", "sticky": True} test_msg = {
"message": "message",
"title": "title",
"sticky": True,
"html": False,
}
self.env.user.notify_danger(**test_msg) self.env.user.notify_danger(**test_msg)
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))
@ -38,7 +48,12 @@ class TestResUsers(common.TransactionCase):
bus_bus = self.env["bus.bus"] bus_bus = self.env["bus.bus"]
domain = [("channel", "=", self.env.user.notify_warning_channel_name)] domain = [("channel", "=", self.env.user.notify_warning_channel_name)]
existing = bus_bus.search(domain) existing = bus_bus.search(domain)
test_msg = {"message": "message", "title": "title", "sticky": True} test_msg = {
"message": "message",
"title": "title",
"sticky": True,
"html": False,
}
self.env.user.notify_warning(**test_msg) self.env.user.notify_warning(**test_msg)
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))
@ -50,7 +65,12 @@ class TestResUsers(common.TransactionCase):
bus_bus = self.env["bus.bus"] bus_bus = self.env["bus.bus"]
domain = [("channel", "=", self.env.user.notify_info_channel_name)] domain = [("channel", "=", self.env.user.notify_info_channel_name)]
existing = bus_bus.search(domain) existing = bus_bus.search(domain)
test_msg = {"message": "message", "title": "title", "sticky": True} test_msg = {
"message": "message",
"title": "title",
"sticky": True,
"html": False,
}
self.env.user.notify_info(**test_msg) self.env.user.notify_info(**test_msg)
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))
@ -62,7 +82,12 @@ class TestResUsers(common.TransactionCase):
bus_bus = self.env["bus.bus"] bus_bus = self.env["bus.bus"]
domain = [("channel", "=", self.env.user.notify_default_channel_name)] domain = [("channel", "=", self.env.user.notify_default_channel_name)]
existing = bus_bus.search(domain) existing = bus_bus.search(domain)
test_msg = {"message": "message", "title": "title", "sticky": True} test_msg = {
"message": "message",
"title": "title",
"sticky": True,
"html": False,
}
self.env.user.notify_default(**test_msg) self.env.user.notify_default(**test_msg)
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))