##// END OF EJS Templates
core: moved channelstream test into pyramid.
marcink -
r1756:278bcf2a default
parent child Browse files
Show More
@@ -41,12 +41,15 b' def includeme(config):'
41 pattern=ADMIN_PREFIX + '/my_account/auth_tokens')
41 pattern=ADMIN_PREFIX + '/my_account/auth_tokens')
42 config.add_route(
42 config.add_route(
43 name='my_account_auth_tokens_add',
43 name='my_account_auth_tokens_add',
44 pattern=ADMIN_PREFIX + '/my_account/auth_tokens/new',
44 pattern=ADMIN_PREFIX + '/my_account/auth_tokens/new')
45 )
46 config.add_route(
45 config.add_route(
47 name='my_account_auth_tokens_delete',
46 name='my_account_auth_tokens_delete',
48 pattern=ADMIN_PREFIX + '/my_account/auth_tokens/delete',
47 pattern=ADMIN_PREFIX + '/my_account/auth_tokens/delete')
49 )
48
49 # channelstream test
50 config.add_route(
51 name='my_account_notifications_test_channelstream',
52 pattern=ADMIN_PREFIX + '/my_account/test_channelstream')
50
53
51 # Scan module for configuration decorators.
54 # Scan module for configuration decorators.
52 config.scan()
55 config.scan()
@@ -19,14 +19,17 b''
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import logging
21 import logging
22 import datetime
22
23
23 from pyramid.httpexceptions import HTTPFound
24 from pyramid.httpexceptions import HTTPFound
24 from pyramid.view import view_config
25 from pyramid.view import view_config
25
26
26 from rhodecode.apps._base import BaseAppView
27 from rhodecode.apps._base import BaseAppView
27 from rhodecode import forms
28 from rhodecode import forms
29 from rhodecode.lib import helpers as h
28 from rhodecode.lib.auth import LoginRequired, NotAnonymous, CSRFRequired
30 from rhodecode.lib.auth import LoginRequired, NotAnonymous, CSRFRequired
29 from rhodecode.lib import helpers as h
31 from rhodecode.lib.channelstream import channelstream_request, \
32 ChannelstreamException
30 from rhodecode.lib.utils2 import safe_int, md5
33 from rhodecode.lib.utils2 import safe_int, md5
31 from rhodecode.model.auth_token import AuthTokenModel
34 from rhodecode.model.auth_token import AuthTokenModel
32 from rhodecode.model.meta import Session
35 from rhodecode.model.meta import Session
@@ -192,3 +195,37 b' class MyAccountView(BaseAppView):'
192 h.flash(_("Auth token successfully deleted"), category='success')
195 h.flash(_("Auth token successfully deleted"), category='success')
193
196
194 return HTTPFound(h.route_path('my_account_auth_tokens'))
197 return HTTPFound(h.route_path('my_account_auth_tokens'))
198
199 @LoginRequired()
200 @NotAnonymous()
201 @CSRFRequired()
202 @view_config(
203 route_name='my_account_notifications_test_channelstream',
204 request_method='POST', renderer='json_ext')
205 def my_account_notifications_test_channelstream(self):
206 message = 'Test message sent via Channelstream by user: {}, on {}'.format(
207 self._rhodecode_user.username, datetime.datetime.now())
208 payload = {
209 # 'channel': 'broadcast',
210 'type': 'message',
211 'timestamp': datetime.datetime.utcnow(),
212 'user': 'system',
213 'pm_users': [self._rhodecode_user.username],
214 'message': {
215 'message': message,
216 'level': 'info',
217 'topic': '/notifications'
218 }
219 }
220
221 registry = self.request.registry
222 rhodecode_plugins = getattr(registry, 'rhodecode_plugins', {})
223 channelstream_config = rhodecode_plugins.get('channelstream', {})
224
225 try:
226 channelstream_request(channelstream_config, [payload], '/message')
227 except ChannelstreamException as e:
228 log.exception('Failed to send channelstream data')
229 return {"response": 'ERROR: {}'.format(e.__class__.__name__)}
230 return {"response": 'Channelstream data sent. '
231 'You should see a new live message now.'}
@@ -513,10 +513,6 b' def make_map(config):'
513 '/my_account/toggle_visibility',
513 '/my_account/toggle_visibility',
514 action='my_notifications_toggle_visibility',
514 action='my_notifications_toggle_visibility',
515 conditions={'method': ['POST']})
515 conditions={'method': ['POST']})
516 m.connect('my_account_notifications_test_channelstream',
517 '/my_account/test_channelstream',
518 action='my_account_notifications_test_channelstream',
519 conditions={'method': ['POST']})
520
516
521 # NOTIFICATION REST ROUTES
517 # NOTIFICATION REST ROUTES
522 with rmap.submapper(path_prefix=ADMIN_PREFIX,
518 with rmap.submapper(path_prefix=ADMIN_PREFIX,
@@ -24,11 +24,9 b' my account controller for RhodeCode admi'
24 """
24 """
25
25
26 import logging
26 import logging
27 import datetime
28
27
29 import formencode
28 import formencode
30 from formencode import htmlfill
29 from formencode import htmlfill
31 from pyramid.threadlocal import get_current_registry
32 from pyramid.httpexceptions import HTTPFound
30 from pyramid.httpexceptions import HTTPFound
33
31
34 from pylons import request, tmpl_context as c, url
32 from pylons import request, tmpl_context as c, url
@@ -44,8 +42,6 b' from rhodecode.lib.base import BaseContr'
44 from rhodecode.lib.utils import jsonify
42 from rhodecode.lib.utils import jsonify
45 from rhodecode.lib.utils2 import safe_int, str2bool
43 from rhodecode.lib.utils2 import safe_int, str2bool
46 from rhodecode.lib.ext_json import json
44 from rhodecode.lib.ext_json import json
47 from rhodecode.lib.channelstream import channelstream_request, \
48 ChannelstreamException
49
45
50 from rhodecode.model.db import (
46 from rhodecode.model.db import (
51 Repository, PullRequest, UserEmailMap, User, UserFollowing)
47 Repository, PullRequest, UserEmailMap, User, UserFollowing)
@@ -332,33 +328,3 b' class MyAccountController(BaseController'
332 user.update_userdata(notification_status=new_status)
328 user.update_userdata(notification_status=new_status)
333 Session().commit()
329 Session().commit()
334 return user.user_data['notification_status']
330 return user.user_data['notification_status']
335
336 @auth.CSRFRequired()
337 @jsonify
338 def my_account_notifications_test_channelstream(self):
339 message = 'Test message sent via Channelstream by user: {}, on {}'.format(
340 c.rhodecode_user.username, datetime.datetime.now())
341 payload = {
342 'type': 'message',
343 'timestamp': datetime.datetime.utcnow(),
344 'user': 'system',
345 #'channel': 'broadcast',
346 'pm_users': [c.rhodecode_user.username],
347 'message': {
348 'message': message,
349 'level': 'info',
350 'topic': '/notifications'
351 }
352 }
353
354 registry = get_current_registry()
355 rhodecode_plugins = getattr(registry, 'rhodecode_plugins', {})
356 channelstream_config = rhodecode_plugins.get('channelstream', {})
357
358 try:
359 channelstream_request(channelstream_config, [payload], '/message')
360 except ChannelstreamException as e:
361 log.exception('Failed to send channelstream data')
362 return {"response": 'ERROR: {}'.format(e.__class__.__name__)}
363 return {"response": 'Channelstream data sent. '
364 'You should see a new live message now.'}
@@ -123,5 +123,6 b' function registerRCRoutes() {'
123 pyroutes.register('my_account_auth_tokens', '/_admin/my_account/auth_tokens', []);
123 pyroutes.register('my_account_auth_tokens', '/_admin/my_account/auth_tokens', []);
124 pyroutes.register('my_account_auth_tokens_add', '/_admin/my_account/auth_tokens/new', []);
124 pyroutes.register('my_account_auth_tokens_add', '/_admin/my_account/auth_tokens/new', []);
125 pyroutes.register('my_account_auth_tokens_delete', '/_admin/my_account/auth_tokens/delete', []);
125 pyroutes.register('my_account_auth_tokens_delete', '/_admin/my_account/auth_tokens/delete', []);
126 pyroutes.register('my_account_notifications_test_channelstream', '/_admin/my_account/test_channelstream', []);
126 pyroutes.register('apiv2', '/_admin/api', []);
127 pyroutes.register('apiv2', '/_admin/api', []);
127 }
128 }
@@ -10,7 +10,7 b''
10
10
11 <iron-ajax id="sendTestNotification"
11 <iron-ajax id="sendTestNotification"
12 method="post"
12 method="post"
13 url="${url('my_account_notifications_test_channelstream')}"
13 url="${h.route_path('my_account_notifications_test_channelstream')}"
14 content-type="application/json"
14 content-type="application/json"
15 on-response="handleTestNotification"
15 on-response="handleTestNotification"
16 handle-as="json">
16 handle-as="json">
General Comments 0
You need to be logged in to leave comments. Login now