##// END OF EJS Templates
core: properly handle new redirections set in decorators....
marcink -
r1499:d130151d default
parent child Browse files
Show More
@@ -32,7 +32,7 b' from pyramid.config import Configurator'
32 from pyramid.settings import asbool, aslist
32 from pyramid.settings import asbool, aslist
33 from pyramid.wsgi import wsgiapp
33 from pyramid.wsgi import wsgiapp
34 from pyramid.httpexceptions import (
34 from pyramid.httpexceptions import (
35 HTTPError, HTTPInternalServerError, HTTPFound)
35 HTTPException, HTTPError, HTTPInternalServerError, HTTPFound)
36 from pyramid.events import ApplicationCreated
36 from pyramid.events import ApplicationCreated
37 from pyramid.renderers import render_to_response
37 from pyramid.renderers import render_to_response
38 from routes.middleware import RoutesMiddleware
38 from routes.middleware import RoutesMiddleware
@@ -226,7 +226,7 b' def error_handler(exception, request):'
226
226
227 base_response = HTTPInternalServerError()
227 base_response = HTTPInternalServerError()
228 # prefer original exception for the response since it may have headers set
228 # prefer original exception for the response since it may have headers set
229 if isinstance(exception, HTTPError):
229 if isinstance(exception, HTTPException):
230 base_response = exception
230 base_response = exception
231
231
232 def is_http_error(response):
232 def is_http_error(response):
@@ -1268,6 +1268,7 b' class NotAnonymous(object):'
1268 return get_cython_compat_decorator(self.__wrapper, func)
1268 return get_cython_compat_decorator(self.__wrapper, func)
1269
1269
1270 def __wrapper(self, func, *fargs, **fkwargs):
1270 def __wrapper(self, func, *fargs, **fkwargs):
1271 import rhodecode.lib.helpers as h
1271 cls = fargs[0]
1272 cls = fargs[0]
1272 self.user = cls._rhodecode_user
1273 self.user = cls._rhodecode_user
1273
1274
@@ -1277,8 +1278,6 b' class NotAnonymous(object):'
1277
1278
1278 if anonymous:
1279 if anonymous:
1279 came_from = request.path_qs
1280 came_from = request.path_qs
1280
1281 import rhodecode.lib.helpers as h
1282 h.flash(_('You need to be a registered user to '
1281 h.flash(_('You need to be a registered user to '
1283 'perform this action'),
1282 'perform this action'),
1284 category='warning')
1283 category='warning')
@@ -1315,6 +1314,7 b' class HasAcceptedRepoType(object):'
1315 return get_cython_compat_decorator(self.__wrapper, func)
1314 return get_cython_compat_decorator(self.__wrapper, func)
1316
1315
1317 def __wrapper(self, func, *fargs, **fkwargs):
1316 def __wrapper(self, func, *fargs, **fkwargs):
1317 import rhodecode.lib.helpers as h
1318 cls = fargs[0]
1318 cls = fargs[0]
1319 rhodecode_repo = cls.rhodecode_repo
1319 rhodecode_repo = cls.rhodecode_repo
1320
1320
@@ -1325,7 +1325,6 b' class HasAcceptedRepoType(object):'
1325 if rhodecode_repo.alias in self.repo_type_list:
1325 if rhodecode_repo.alias in self.repo_type_list:
1326 return func(*fargs, **fkwargs)
1326 return func(*fargs, **fkwargs)
1327 else:
1327 else:
1328 import rhodecode.lib.helpers as h
1329 h.flash(h.literal(
1328 h.flash(h.literal(
1330 _('Action not supported for %s.' % rhodecode_repo.alias)),
1329 _('Action not supported for %s.' % rhodecode_repo.alias)),
1331 category='warning')
1330 category='warning')
@@ -1349,7 +1348,7 b' class PermsDecorator(object):'
1349 from pyramid.threadlocal import get_current_request
1348 from pyramid.threadlocal import get_current_request
1350 pyramid_request = get_current_request()
1349 pyramid_request = get_current_request()
1351 if not pyramid_request:
1350 if not pyramid_request:
1352 # return global request of pylons incase pyramid one isn't available
1351 # return global request of pylons in case pyramid isn't available
1353 return request
1352 return request
1354 return pyramid_request
1353 return pyramid_request
1355
1354
@@ -1360,6 +1359,7 b' class PermsDecorator(object):'
1360 return _request.path_qs
1359 return _request.path_qs
1361
1360
1362 def __wrapper(self, func, *fargs, **fkwargs):
1361 def __wrapper(self, func, *fargs, **fkwargs):
1362 import rhodecode.lib.helpers as h
1363 cls = fargs[0]
1363 cls = fargs[0]
1364 _user = cls._rhodecode_user
1364 _user = cls._rhodecode_user
1365
1365
@@ -1375,7 +1375,6 b' class PermsDecorator(object):'
1375 anonymous = _user.username == User.DEFAULT_USER
1375 anonymous = _user.username == User.DEFAULT_USER
1376
1376
1377 if anonymous:
1377 if anonymous:
1378 import rhodecode.lib.helpers as h
1379 came_from = self._get_came_from()
1378 came_from = self._get_came_from()
1380 h.flash(_('You need to be signed in to view this page'),
1379 h.flash(_('You need to be signed in to view this page'),
1381 category='warning')
1380 category='warning')
@@ -1970,3 +1969,5 b' def get_cython_compat_decorator(wrapper,'
1970 return wrapper(func, *args, **kwds)
1969 return wrapper(func, *args, **kwds)
1971 local_wrapper.__wrapped__ = func
1970 local_wrapper.__wrapped__ = func
1972 return local_wrapper
1971 return local_wrapper
1972
1973
@@ -21,7 +21,8 b''
21
21
22 import logging
22 import logging
23 from pyramid import httpexceptions
23 from pyramid import httpexceptions
24 from pyramid.httpexceptions import HTTPError, HTTPInternalServerError
24 from pyramid.httpexceptions import (
25 HTTPRedirection, HTTPError, HTTPInternalServerError)
25 from pyramid.threadlocal import get_current_request
26 from pyramid.threadlocal import get_current_request
26
27
27 from rhodecode.lib.exceptions import VCSServerUnavailable
28 from rhodecode.lib.exceptions import VCSServerUnavailable
@@ -53,7 +54,7 b' class PylonsErrorHandlingMiddleware(obje'
53
54
54 def is_http_error(self, response):
55 def is_http_error(self, response):
55 # webob type error responses
56 # webob type error responses
56 return (400 <= response.status_int <= 599)
57 return 400 <= response.status_int <= 599
57
58
58 def reraise(self):
59 def reraise(self):
59 return self._reraise
60 return self._reraise
@@ -73,9 +74,16 b' class PylonsErrorHandlingMiddleware(obje'
73 if self.is_http_error(response):
74 if self.is_http_error(response):
74 response = webob_to_pyramid_http_response(response)
75 response = webob_to_pyramid_http_response(response)
75 return self.error_view(response, request)
76 return self.error_view(response, request)
76 except HTTPError as e: # pyramid type exceptions
77 except HTTPRedirection as e:
78 # pyramid type redirection, with status codes in the 300s
79 log.debug('Handling pyramid HTTPRedirection: %s', e)
80 return e
81 except HTTPError as e:
82 # pyramid type exceptions, with status codes in the 400s and 500s
83 log.debug('Handling pyramid HTTPError: %s', e)
77 return self.error_view(e, request)
84 return self.error_view(e, request)
78 except Exception as e:
85 except Exception as e:
86 log.debug('Handling general error: %s', e)
79
87
80 if self.reraise():
88 if self.reraise():
81 raise
89 raise
@@ -89,6 +97,8 b' class PylonsErrorHandlingMiddleware(obje'
89
97
90
98
91 def webob_to_pyramid_http_response(webob_response):
99 def webob_to_pyramid_http_response(webob_response):
100 log.debug('response is webob http error[%s], handling now...',
101 webob_response.status_int)
92 ResponseClass = httpexceptions.status_map[webob_response.status_int]
102 ResponseClass = httpexceptions.status_map[webob_response.status_int]
93 pyramid_response = ResponseClass(webob_response.status)
103 pyramid_response = ResponseClass(webob_response.status)
94 pyramid_response.status = webob_response.status
104 pyramid_response.status = webob_response.status
General Comments 0
You need to be logged in to leave comments. Login now