api: attach the call context variables to request for later usage
in API calls.
This commit is contained in:
parent
091c9d9d99
commit
930c7eebbd
2 changed files with 13 additions and 3 deletions
|
|
@ -35,8 +35,9 @@ from pyramid.httpexceptions import HTTPNotFound
|
||||||
|
|
||||||
from rhodecode.api.exc import (
|
from rhodecode.api.exc import (
|
||||||
JSONRPCBaseError, JSONRPCError, JSONRPCForbidden, JSONRPCValidationError)
|
JSONRPCBaseError, JSONRPCError, JSONRPCForbidden, JSONRPCValidationError)
|
||||||
|
from rhodecode.apps._base import TemplateArgs
|
||||||
from rhodecode.lib.auth import AuthUser
|
from rhodecode.lib.auth import AuthUser
|
||||||
from rhodecode.lib.base import get_ip_addr
|
from rhodecode.lib.base import get_ip_addr, attach_context_attributes
|
||||||
from rhodecode.lib.ext_json import json
|
from rhodecode.lib.ext_json import json
|
||||||
from rhodecode.lib.utils2 import safe_str
|
from rhodecode.lib.utils2 import safe_str
|
||||||
from rhodecode.lib.plugins.utils import get_plugin_settings
|
from rhodecode.lib.plugins.utils import get_plugin_settings
|
||||||
|
|
@ -278,6 +279,11 @@ def request_view(request):
|
||||||
'request': request,
|
'request': request,
|
||||||
'apiuser': auth_u
|
'apiuser': auth_u
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# register some common functions for usage
|
||||||
|
attach_context_attributes(TemplateArgs(), request, request.rpc_user.user_id,
|
||||||
|
attach_to_request=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret_value = func(**call_params)
|
ret_value = func(**call_params)
|
||||||
return jsonrpc_response(request, ret_value)
|
return jsonrpc_response(request, ret_value)
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,7 @@ class BasicAuth(AuthBasicAuthenticator):
|
||||||
__call__ = authenticate
|
__call__ = authenticate
|
||||||
|
|
||||||
|
|
||||||
def attach_context_attributes(context, request, user_id):
|
def attach_context_attributes(context, request, user_id, attach_to_request=False):
|
||||||
"""
|
"""
|
||||||
Attach variables into template context called `c`, please note that
|
Attach variables into template context called `c`, please note that
|
||||||
request could be pylons or pyramid request in here.
|
request could be pylons or pyramid request in here.
|
||||||
|
|
@ -388,7 +388,11 @@ def attach_context_attributes(context, request, user_id):
|
||||||
context.backends = rhodecode.BACKENDS.keys()
|
context.backends = rhodecode.BACKENDS.keys()
|
||||||
context.backends.sort()
|
context.backends.sort()
|
||||||
context.unread_notifications = NotificationModel().get_unread_cnt_for_user(user_id)
|
context.unread_notifications = NotificationModel().get_unread_cnt_for_user(user_id)
|
||||||
context.pyramid_request = pyramid.threadlocal.get_current_request()
|
if attach_to_request:
|
||||||
|
request.call_context = context
|
||||||
|
else:
|
||||||
|
context.pyramid_request = pyramid.threadlocal.get_current_request()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_auth_user(environ):
|
def get_auth_user(environ):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue