##// END OF EJS Templates
channelstream: add simple method of posting message to notification channel.
marcink -
r1969:27a92529 default
parent child Browse files
Show More
@@ -18,12 +18,15 b''
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
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 os
21 import hashlib
22 import hashlib
22 import itsdangerous
23 import itsdangerous
23 import logging
24 import logging
24 import os
25 import requests
25 import requests
26 import datetime
27
26 from dogpile.core import ReadWriteMutex
28 from dogpile.core import ReadWriteMutex
29 from pyramid.threadlocal import get_current_registry
27
30
28 import rhodecode.lib.helpers as h
31 import rhodecode.lib.helpers as h
29 from rhodecode.lib.auth import HasRepoPermissionAny
32 from rhodecode.lib.auth import HasRepoPermissionAny
@@ -218,3 +221,33 b' def get_connection_validators(registry):'
218 if validator:
221 if validator:
219 validators.append(validator)
222 validators.append(validator)
220 return validators
223 return validators
224
225
226 def post_message(channel, message, username, registry=None):
227
228 if not registry:
229 registry = get_current_registry()
230
231 rhodecode_plugins = getattr(registry, 'rhodecode_plugins', {})
232 channelstream_config = rhodecode_plugins.get('channelstream', {})
233 if channelstream_config.get('enabled'):
234 payload = {
235 'type': 'message',
236 'timestamp': datetime.datetime.utcnow(),
237 'user': 'system',
238 'exclude_users': [username],
239 'channel': channel,
240 'message': {
241 'message': message,
242 'level': 'success',
243 'topic': '/notifications'
244 }
245 }
246
247 try:
248 return channelstream_request(
249 channelstream_config, [payload], '/message',
250 raise_exc=False)
251 except ChannelstreamException:
252 log.exception('Failed to send channelstream data')
253 raise
General Comments 0
You need to be logged in to leave comments. Login now