core: improve attach context attribute to rely strictly on already provided user.

This commit is contained in:
Marcin Kuzminski 2017-06-05 19:22:27 +02:00
parent 6a85677174
commit 6680a287da
2 changed files with 4 additions and 6 deletions

View file

@ -265,7 +265,7 @@ class BasicAuth(AuthBasicAuthenticator):
__call__ = authenticate
def attach_context_attributes(context, request):
def attach_context_attributes(context, request, user_id):
"""
Attach variables into template context called `c`, please note that
request could be pylons or pyramid request in here.
@ -387,9 +387,7 @@ def attach_context_attributes(context, request):
context.csrf_token = auth.get_csrf_token()
context.backends = rhodecode.BACKENDS.keys()
context.backends.sort()
context.unread_notifications = NotificationModel().get_unread_cnt_for_user(
context.rhodecode_user.user_id)
context.unread_notifications = NotificationModel().get_unread_cnt_for_user(user_id)
context.pyramid_request = pyramid.threadlocal.get_current_request()
@ -440,7 +438,7 @@ class BaseController(WSGIController):
"""
# on each call propagate settings calls into global settings.
set_rhodecode_config(config)
attach_context_attributes(c, request)
attach_context_attributes(c, request, c.rhodecode_user.user_id)
# TODO: Remove this when fixed in attach_context_attributes()
c.repo_name = get_repo_slug(request) # can be empty

View file

@ -121,7 +121,7 @@ def add_pylons_context(event):
# Setup the pylons context object ('c')
context = ContextObj()
context.rhodecode_user = auth_user
attach_context_attributes(context, request)
attach_context_attributes(context, request, request.user.user_id)
pylons.tmpl_context._push_object(context)