##// END OF EJS Templates
auth: re-use the get_current_request in fetching request in decorators....
marcink -
r1775:f25110de default
parent child Browse files
Show More
@@ -1185,10 +1185,20 b' class LoginRequired(object):'
1185 1185 def __call__(self, func):
1186 1186 return get_cython_compat_decorator(self.__wrapper, func)
1187 1187
1188 def _get_request(self):
1189 from pyramid.threadlocal import get_current_request
1190 pyramid_request = get_current_request()
1191 if not pyramid_request:
1192 # return global request of pylons in case pyramid isn't available
1193 return request
1194 return pyramid_request
1195
1188 1196 def __wrapper(self, func, *fargs, **fkwargs):
1189 1197 from rhodecode.lib import helpers as h
1190 1198 cls = fargs[0]
1191 1199 user = cls._rhodecode_user
1200 request = self._get_request()
1201
1192 1202 loc = "%s:%s" % (cls.__class__.__name__, func.__name__)
1193 1203 log.debug('Starting login restriction checks for user: %s' % (user,))
1194 1204 # check if our IP is allowed
@@ -1262,7 +1272,8 b' class LoginRequired(object):'
1262 1272 class NotAnonymous(object):
1263 1273 """
1264 1274 Must be logged in to execute this function else
1265 redirect to login page"""
1275 redirect to login page
1276 """
1266 1277
1267 1278 def __call__(self, func):
1268 1279 return get_cython_compat_decorator(self.__wrapper, func)
@@ -1288,6 +1299,8 b' class NotAnonymous(object):'
1288 1299
1289 1300
1290 1301 class XHRRequired(object):
1302 # TODO(marcink): remove this in favor of the predicates in pyramid routes
1303
1291 1304 def __call__(self, func):
1292 1305 return get_cython_compat_decorator(self.__wrapper, func)
1293 1306
@@ -1303,9 +1316,9 b' class XHRRequired(object):'
1303 1316 class HasAcceptedRepoType(object):
1304 1317 """
1305 1318 Check if requested repo is within given repo type aliases
1319 """
1306 1320
1307 TODO: anderson: not sure where to put this decorator
1308 """
1321 # TODO(marcink): remove this in favor of the predicates in pyramid routes
1309 1322
1310 1323 def __init__(self, *repo_type_list):
1311 1324 self.repo_type_list = set(repo_type_list)
@@ -1595,6 +1608,7 b' class PermsFunction(object):'
1595 1608 if not user:
1596 1609 log.debug('Using user attribute from global request')
1597 1610 # TODO: remove this someday,put as user as attribute here
1611 request = self._get_request()
1598 1612 user = request.user
1599 1613
1600 1614 # init auth user if not already given
General Comments 0
You need to be logged in to leave comments. Login now