diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -566,6 +566,10 @@ def make_map(config): '/my_account/toggle_visibility', action='my_notifications_toggle_visibility', conditions={'method': ['POST']}) + m.connect('my_account_notifications_test_channelstream', + '/my_account/test_channelstream', + action='my_account_notifications_test_channelstream', + conditions={'method': ['POST']}) # NOTIFICATION REST ROUTES with rmap.submapper(path_prefix=ADMIN_PREFIX, diff --git a/rhodecode/controllers/admin/my_account.py b/rhodecode/controllers/admin/my_account.py --- a/rhodecode/controllers/admin/my_account.py +++ b/rhodecode/controllers/admin/my_account.py @@ -24,13 +24,16 @@ my account controller for RhodeCode admi """ import logging +import datetime import formencode from formencode import htmlfill +from pyramid.threadlocal import get_current_registry from pylons import request, tmpl_context as c, url, session from pylons.controllers.util import redirect from pylons.i18n.translation import _ from sqlalchemy.orm import joinedload +from webob.exc import HTTPBadGateway from rhodecode import forms from rhodecode.lib import helpers as h @@ -41,6 +44,8 @@ from rhodecode.lib.base import BaseContr from rhodecode.lib.utils import jsonify from rhodecode.lib.utils2 import safe_int, md5, str2bool from rhodecode.lib.ext_json import json +from rhodecode.lib.channelstream import channelstream_request, \ + ChannelstreamException from rhodecode.model.validation_schema.schemas import user_schema from rhodecode.model.db import ( @@ -430,3 +435,33 @@ class MyAccountController(BaseController user.update_userdata(notification_status=new_status) Session().commit() return user.user_data['notification_status'] + + @auth.CSRFRequired() + @jsonify + def my_account_notifications_test_channelstream(self): + message = 'Test message sent via Channelstream by user: {}, on {}'.format( + c.rhodecode_user.username, datetime.datetime.now()) + payload = { + 'type': 'message', + 'timestamp': datetime.datetime.utcnow(), + 'user': 'system', + #'channel': 'broadcast', + 'pm_users': [c.rhodecode_user.username], + 'message': { + 'message': message, + 'level': 'info', + 'topic': '/notifications' + } + } + + registry = get_current_registry() + rhodecode_plugins = getattr(registry, 'rhodecode_plugins', {}) + channelstream_config = rhodecode_plugins.get('channelstream', {}) + + try: + channelstream_request(channelstream_config, [payload], '/message') + except ChannelstreamException as e: + log.exception('Failed to send channelstream data') + return {"response": 'ERROR: {}'.format(e.__class__.__name__)} + return {"response": 'Channelstream data sent. ' + 'You should see a new live message now.'} diff --git a/rhodecode/templates/admin/my_account/my_account_notifications.html b/rhodecode/templates/admin/my_account/my_account_notifications.html --- a/rhodecode/templates/admin/my_account/my_account_notifications.html +++ b/rhodecode/templates/admin/my_account/my_account_notifications.html @@ -5,13 +5,22 @@ content-type="application/json" loading="{{changeNotificationsLoading}}" on-response="handleNotifications" - handle-as="json"> + handle-as="json"> + + + +

${_('Your Live Notification Settings')}

-
+

IMPORTANT: This feature requires enabled channelstream websocket server to function correctly.

@@ -27,13 +36,29 @@
-
- Test notification -
+ + - +
+
+

${_('Test Notifications')}

+
+
+ + +
+ + +
+

+
+ +
+ + + +