##// END OF EJS Templates
pyramid: moved extraction of user into a seperate subscriber.
marcink -
r1903:982ccdbd default
parent child Browse files
Show More
@@ -403,7 +403,10 b' def attach_context_attributes(context, r'
403 request.call_context = context
403 request.call_context = context
404
404
405
405
406 def get_auth_user(environ):
406 def get_auth_user(request):
407 environ = request.environ
408 session = request.session
409
407 ip_addr = get_ip_addr(environ)
410 ip_addr = get_ip_addr(environ)
408 # make sure that we update permissions each time we call controller
411 # make sure that we update permissions each time we call controller
409 _auth_token = (request.GET.get('auth_token', '') or
412 _auth_token = (request.GET.get('auth_token', '') or
@@ -87,6 +87,25 b' def set_user_lang(event):'
87 event.request._LOCALE_ = user_lang
87 event.request._LOCALE_ = user_lang
88
88
89
89
90 def add_request_user_context(event):
91 """
92 Adds auth user into request context
93 """
94 request = event.request
95
96 if hasattr(request, 'vcs_call'):
97 # skip vcs calls
98 return
99
100 if hasattr(request, 'rpc_method'):
101 # skip api calls
102 return
103
104 auth_user = get_auth_user(request)
105 request.user = auth_user
106 request.environ['rc_auth_user'] = auth_user
107
108
90 def add_pylons_context(event):
109 def add_pylons_context(event):
91 request = event.request
110 request = event.request
92
111
@@ -113,14 +132,9 b' def add_pylons_context(event):'
113 # skip api calls
132 # skip api calls
114 return
133 return
115
134
116 # Get the rhodecode auth user object and make it available.
117 auth_user = get_auth_user(environ)
118 request.user = auth_user
119 environ['rc_auth_user'] = auth_user
120
121 # Setup the pylons context object ('c')
135 # Setup the pylons context object ('c')
122 context = ContextObj()
136 context = ContextObj()
123 context.rhodecode_user = auth_user
137 context.rhodecode_user = request.user
124 attach_context_attributes(context, request, request.user.user_id)
138 attach_context_attributes(context, request, request.user.user_id)
125 pylons.tmpl_context._push_object(context)
139 pylons.tmpl_context._push_object(context)
126
140
@@ -60,6 +60,8 b' def includeme(config):'
60 'pyramid.events.NewRequest')
60 'pyramid.events.NewRequest')
61 config.add_subscriber('rhodecode.subscribers.add_localizer',
61 config.add_subscriber('rhodecode.subscribers.add_localizer',
62 'pyramid.events.NewRequest')
62 'pyramid.events.NewRequest')
63 config.add_subscriber('rhodecode.subscribers.add_request_user_context',
64 'pyramid.events.ContextFound')
63 config.add_subscriber('rhodecode.subscribers.add_pylons_context',
65 config.add_subscriber('rhodecode.subscribers.add_pylons_context',
64 'pyramid.events.ContextFound')
66 'pyramid.events.ContextFound')
65
67
General Comments 0
You need to be logged in to leave comments. Login now