diff --git a/web_notify/README.rst b/web_notify/README.rst index 2fa24871..243dc229 100644 --- a/web_notify/README.rst +++ b/web_notify/README.rst @@ -1,11 +1,30 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 - ========== Web Notify ========== +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/12.0/web_notify + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_notify + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + 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. @@ -14,68 +33,82 @@ Two kinds of notification are supported. * Warning: Displayed in a red flying popup div * Information: Displayed in a light yellow flying popup div +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode. + +Usage +===== + + To send a notification to the user you just need to call one of the new methods defined on res.users: .. code-block:: python - self.env.user.notify_info('My information message') + self.env.user.notify_info(message='My information message') or .. code-block:: python - self.env.user.notify_warning('My marning message') + self.env.user.notify_warning(message='My marning message') .. figure:: static/description/notifications_screenshot.png :scale: 80 % :alt: Sample notifications -Installation -============ +You can test the behaviour of the notifications by installing this module in a demo database. + Click in your user logo in the top right corner of the screen then click "Preferences". -This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode. - - -Usage -===== - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/162/10.0 +.. figure:: static/description/test_notifications_demo.png + :scale: 80 % + :alt: Sample notifications Bug Tracker =========== -Bugs are tracked on `GitHub Issues -`_. In case of trouble, please -check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed feedback. +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* ACSONE SA/NV +* AdaptiveCity Contributors ------------- +~~~~~~~~~~~~ * Laurent Mignon * Serpent Consulting Services Pvt. Ltd. +* Aitor Bouzas -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit https://odoo-community.org. +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_notify/__init__.py b/web_notify/__init__.py index 0650744f..31660d6a 100644 --- a/web_notify/__init__.py +++ b/web_notify/__init__.py @@ -1 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + from . import models diff --git a/web_notify/__manifest__.py b/web_notify/__manifest__.py index 0ad8d42f..0643b87d 100644 --- a/web_notify/__manifest__.py +++ b/web_notify/__manifest__.py @@ -5,19 +5,23 @@ 'name': 'Web Notify', 'summary': """ Send notification messages to user""", - 'version': '11.0.1.1.0', + 'version': '12.0.1.0.0', 'description': 'Web Notify', 'license': 'AGPL-3', - 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', - 'website': 'https://acsone.eu/', + 'author': 'ACSONE SA/NV,' + 'AdaptiveCity,' + 'Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/web', 'depends': [ 'web', 'bus', + 'base', ], 'data': [ 'views/web_notify.xml' ], 'demo': [ + 'views/res_users_demo.xml' ], 'installable': True, } diff --git a/web_notify/models/__init__.py b/web_notify/models/__init__.py index 88351653..c39e40a1 100644 --- a/web_notify/models/__init__.py +++ b/web_notify/models/__init__.py @@ -1 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + from . import res_users diff --git a/web_notify/models/res_users.py b/web_notify/models/res_users.py index 25f65084..9e1f2f04 100644 --- a/web_notify/models/res_users.py +++ b/web_notify/models/res_users.py @@ -1,14 +1,12 @@ # Copyright 2016 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, exceptions, fields, models, _, SUPERUSER_ID +from odoo import api, exceptions, fields, models, _ class ResUsers(models.Model): - _inherit = 'res.users' - @api.multi @api.depends('create_date') def _compute_channel_names(self): for record in self: @@ -21,21 +19,19 @@ class ResUsers(models.Model): notify_warning_channel_name = fields.Char( compute='_compute_channel_names') - @api.multi - def notify_info(self, message, title=None, sticky=False): + def notify_info(self, message="Default message", title=None, sticky=False): title = title or _('Information') self._notify_channel( 'notify_info_channel_name', message, title, sticky) - @api.multi - def notify_warning(self, message, title=None, sticky=False): + def notify_warning(self, message="Default message", + title=None, sticky=False): title = title or _('Warning') self._notify_channel( 'notify_warning_channel_name', message, title, sticky) - @api.multi def _notify_channel(self, channel_name_field, message, title, sticky): - if (self.env.uid != SUPERUSER_ID + if (not self.env.user._is_admin() and any(user.id != self.env.uid for user in self)): raise exceptions.UserError( _('Sending a notification to another user is forbidden.') @@ -45,6 +41,6 @@ class ResUsers(models.Model): 'title': title, 'sticky': sticky } - notifications = [(getattr(record, channel_name_field), bus_message) + notifications = [(record[channel_name_field], bus_message) for record in self] self.env['bus.bus'].sendmany(notifications) diff --git a/web_notify/readme/CONTRIBUTORS.rst b/web_notify/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..70f99b04 --- /dev/null +++ b/web_notify/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Laurent Mignon +* Serpent Consulting Services Pvt. Ltd. +* Aitor Bouzas \ No newline at end of file diff --git a/web_notify/readme/DESCRIPTION.rst b/web_notify/readme/DESCRIPTION.rst new file mode 100644 index 00000000..7d7528a3 --- /dev/null +++ b/web_notify/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +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. + +* Warning: Displayed in a red flying popup div +* Information: Displayed in a light yellow flying popup div \ No newline at end of file diff --git a/web_notify/readme/INSTALL.rst b/web_notify/readme/INSTALL.rst new file mode 100644 index 00000000..a27ef894 --- /dev/null +++ b/web_notify/readme/INSTALL.rst @@ -0,0 +1 @@ +This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode. \ No newline at end of file diff --git a/web_notify/readme/USAGE.rst b/web_notify/readme/USAGE.rst new file mode 100644 index 00000000..3570a486 --- /dev/null +++ b/web_notify/readme/USAGE.rst @@ -0,0 +1,23 @@ + +To send a notification to the user you just need to call one of the new methods defined on res.users: + +.. code-block:: python + + self.env.user.notify_info(message='My information message') + +or + +.. code-block:: python + + self.env.user.notify_warning(message='My marning message') + +.. figure:: static/description/notifications_screenshot.png + :scale: 80 % + :alt: Sample notifications + +You can test the behaviour of the notifications by installing this module in a demo database. + Click in your user logo in the top right corner of the screen then click "Preferences". + +.. figure:: static/description/test_notifications_demo.png + :scale: 80 % + :alt: Sample notifications diff --git a/web_notify/static/description/index.html b/web_notify/static/description/index.html new file mode 100644 index 00000000..26f951bd --- /dev/null +++ b/web_notify/static/description/index.html @@ -0,0 +1,455 @@ + + + + + + +Web Notify + + + +
+

Web Notify

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

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.

+
    +
  • Warning: Displayed in a red flying popup div
  • +
  • Information: Displayed in a light yellow flying popup div
  • +
+

Table of contents

+ +
+

Installation

+

This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode.

+
+
+

Usage

+

To send a notification to the user you just need to call one of the new methods defined on res.users:

+
+self.env.user.notify_info(message='My information message')
+
+

or

+
+self.env.user.notify_warning(message='My marning message')
+
+
+Sample notifications +
+
+
You can test the behaviour of the notifications by installing this module in a demo database.
+
Click in your user logo in the top right corner of the screen then click “Preferences”.
+
+
+Sample notifications +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
  • AdaptiveCity
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_notify/static/description/test_notifications_demo.png b/web_notify/static/description/test_notifications_demo.png new file mode 100644 index 00000000..fb2e4c3c Binary files /dev/null and b/web_notify/static/description/test_notifications_demo.png differ diff --git a/web_notify/static/src/js/web_client.js b/web_notify/static/src/js/web_client.js index 739251c8..c9b0139f 100644 --- a/web_notify/static/src/js/web_client.js +++ b/web_notify/static/src/js/web_client.js @@ -2,8 +2,9 @@ odoo.define('web_notify.WebClient', function (require) { "use strict"; var WebClient = require('web.WebClient'); -var base_bus = require('bus.bus'); +var base_bus = require('bus.Longpolling'); var session = require('web.session'); +require('bus.BusService'); WebClient.include({ @@ -15,10 +16,10 @@ WebClient.include({ start_polling: function() { this.channel_warning = 'notify_warning_' + session.uid; this.channel_info = 'notify_info_' + session.uid; - base_bus.bus.add_channel(this.channel_warning); - base_bus.bus.add_channel(this.channel_info); - base_bus.bus.on('notification', this, this.bus_notification); - base_bus.bus.start_polling(); + this.call('bus_service', 'addChannel', this.channel_warning); + this.call('bus_service', 'addChannel', this.channel_info); + this.call('bus_service', 'on', 'notification', this, this.bus_notification); + this.call('bus_service', 'startPolling'); }, bus_notification: function(notifications) { var self = this; @@ -33,14 +34,10 @@ WebClient.include({ }); }, on_message_warning: function(message){ - if(this.notification_manager) { - this.notification_manager.do_warn(message.title, message.message, message.sticky); - } + this.do_warn(message.title, message.message, message.sticky); }, on_message_info: function(message){ - if(this.notification_manager) { - this.notification_manager.do_notify(message.title, message.message, message.sticky); - } + this.do_notify(message.title, message.message, message.sticky); } }); diff --git a/web_notify/tests/__init__.py b/web_notify/tests/__init__.py index 03c963d7..f759b968 100644 --- a/web_notify/tests/__init__.py +++ b/web_notify/tests/__init__.py @@ -1 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + from . import test_res_users diff --git a/web_notify/tests/test_res_users.py b/web_notify/tests/test_res_users.py index 2f336a27..80a1a937 100644 --- a/web_notify/tests/test_res_users.py +++ b/web_notify/tests/test_res_users.py @@ -43,7 +43,7 @@ class TestResUsers(common.TransactionCase): ) as mockedSendMany: users = self.env.user.search([(1, "=", 1)]) self.assertTrue(len(users) > 1) - users.notify_warning('message') + users.notify_warning(message='message') self.assertEqual(1, mockedSendMany.call_count) @@ -61,8 +61,8 @@ class TestResUsers(common.TransactionCase): other_user = self.env.ref('base.user_demo') other_user_model = self.env['res.users'].sudo(other_user) with self.assertRaises(exceptions.UserError): - other_user_model.browse(self.env.uid).notify_info('hello') + other_user_model.browse(self.env.uid).notify_info(message='hello') def test_notify_admin_allowed_other_user(self): other_user = self.env.ref('base.user_demo') - other_user.notify_info('hello') + other_user.notify_info(message='hello') diff --git a/web_notify/views/res_users_demo.xml b/web_notify/views/res_users_demo.xml new file mode 100644 index 00000000..4ca9f422 --- /dev/null +++ b/web_notify/views/res_users_demo.xml @@ -0,0 +1,30 @@ + + + + + res.users.form.simple.view.modif.inherit + res.users + + + + + + +