##// END OF EJS Templates
api: attach the call context variables to request for later usage...
dan -
r1794:1c6b274b default
parent child Browse files
Show More
@@ -35,8 +35,9 b' from pyramid.httpexceptions import HTTPN'
35
35
36 from rhodecode.api.exc import (
36 from rhodecode.api.exc import (
37 JSONRPCBaseError, JSONRPCError, JSONRPCForbidden, JSONRPCValidationError)
37 JSONRPCBaseError, JSONRPCError, JSONRPCForbidden, JSONRPCValidationError)
38 from rhodecode.apps._base import TemplateArgs
38 from rhodecode.lib.auth import AuthUser
39 from rhodecode.lib.auth import AuthUser
39 from rhodecode.lib.base import get_ip_addr
40 from rhodecode.lib.base import get_ip_addr, attach_context_attributes
40 from rhodecode.lib.ext_json import json
41 from rhodecode.lib.ext_json import json
41 from rhodecode.lib.utils2 import safe_str
42 from rhodecode.lib.utils2 import safe_str
42 from rhodecode.lib.plugins.utils import get_plugin_settings
43 from rhodecode.lib.plugins.utils import get_plugin_settings
@@ -278,6 +279,11 b' def request_view(request):'
278 'request': request,
279 'request': request,
279 'apiuser': auth_u
280 'apiuser': auth_u
280 })
281 })
282
283 # register some common functions for usage
284 attach_context_attributes(TemplateArgs(), request, request.rpc_user.user_id,
285 attach_to_request=True)
286
281 try:
287 try:
282 ret_value = func(**call_params)
288 ret_value = func(**call_params)
283 return jsonrpc_response(request, ret_value)
289 return jsonrpc_response(request, ret_value)
@@ -265,7 +265,7 b' class BasicAuth(AuthBasicAuthenticator):'
265 __call__ = authenticate
265 __call__ = authenticate
266
266
267
267
268 def attach_context_attributes(context, request, user_id):
268 def attach_context_attributes(context, request, user_id, attach_to_request=False):
269 """
269 """
270 Attach variables into template context called `c`, please note that
270 Attach variables into template context called `c`, please note that
271 request could be pylons or pyramid request in here.
271 request could be pylons or pyramid request in here.
@@ -388,9 +388,13 b' def attach_context_attributes(context, r'
388 context.backends = rhodecode.BACKENDS.keys()
388 context.backends = rhodecode.BACKENDS.keys()
389 context.backends.sort()
389 context.backends.sort()
390 context.unread_notifications = NotificationModel().get_unread_cnt_for_user(user_id)
390 context.unread_notifications = NotificationModel().get_unread_cnt_for_user(user_id)
391 if attach_to_request:
392 request.call_context = context
393 else:
391 context.pyramid_request = pyramid.threadlocal.get_current_request()
394 context.pyramid_request = pyramid.threadlocal.get_current_request()
392
395
393
396
397
394 def get_auth_user(environ):
398 def get_auth_user(environ):
395 ip_addr = get_ip_addr(environ)
399 ip_addr = get_ip_addr(environ)
396 # make sure that we update permissions each time we call controller
400 # make sure that we update permissions each time we call controller
General Comments 0
You need to be logged in to leave comments. Login now