changeset 2500:94ef0b609d17 beta

possible fix for #486 undefined variable username - cleaned a code on git/hg middleware
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 21 Jun 2012 17:48:41 +0200
parents c919d8c4f6a2
children 044c31d67ccc
files rhodecode/lib/middleware/simplegit.py rhodecode/lib/middleware/simplehg.py
diffstat 2 files changed, 26 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/middleware/simplegit.py	Thu Jun 21 01:34:11 2012 +0200
+++ b/rhodecode/lib/middleware/simplegit.py	Thu Jun 21 17:48:41 2012 +0200
@@ -167,21 +167,20 @@
                 #==============================================================
                 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME
                 #==============================================================
-                if action in ['pull', 'push']:
-                    try:
-                        user = self.__get_user(username)
-                        if user is None or not user.active:
-                            return HTTPForbidden()(environ, start_response)
-                        username = user.username
-                    except:
-                        log.error(traceback.format_exc())
-                        return HTTPInternalServerError()(environ,
-                                                         start_response)
+                try:
+                    user = self.__get_user(username)
+                    if user is None or not user.active:
+                        return HTTPForbidden()(environ, start_response)
+                    username = user.username
+                except:
+                    log.error(traceback.format_exc())
+                    return HTTPInternalServerError()(environ, start_response)
 
-                    #check permissions for this repository
-                    perm = self._check_permission(action, user, repo_name)
-                    if perm is not True:
-                        return HTTPForbidden()(environ, start_response)
+                #check permissions for this repository
+                perm = self._check_permission(action, user, repo_name)
+                if perm is not True:
+                    return HTTPForbidden()(environ, start_response)
+
         extras = {
             'ip': ipaddr,
             'username': username,
--- a/rhodecode/lib/middleware/simplehg.py	Thu Jun 21 01:34:11 2012 +0200
+++ b/rhodecode/lib/middleware/simplehg.py	Thu Jun 21 17:48:41 2012 +0200
@@ -70,7 +70,7 @@
             return self.application(environ, start_response)
 
         ipaddr = self._get_ip_addr(environ)
-
+        username = None 
         # skip passing error to error controller
         environ['pylons.status_code_redirect'] = True
 
@@ -131,21 +131,19 @@
                 #==============================================================
                 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME
                 #==============================================================
-                if action in ['pull', 'push']:
-                    try:
-                        user = self.__get_user(username)
-                        if user is None or not user.active:
-                            return HTTPForbidden()(environ, start_response)
-                        username = user.username
-                    except:
-                        log.error(traceback.format_exc())
-                        return HTTPInternalServerError()(environ,
-                                                         start_response)
+                try:
+                    user = self.__get_user(username)
+                    if user is None or not user.active:
+                        return HTTPForbidden()(environ, start_response)
+                    username = user.username
+                except:
+                    log.error(traceback.format_exc())
+                    return HTTPInternalServerError()(environ, start_response)
 
-                    #check permissions for this repository
-                    perm = self._check_permission(action, user, repo_name)
-                    if perm is not True:
-                        return HTTPForbidden()(environ, start_response)
+                #check permissions for this repository
+                perm = self._check_permission(action, user, repo_name)
+                if perm is not True:
+                    return HTTPForbidden()(environ, start_response)
 
         # extras are injected into mercurial UI object and later available
         # in hg hooks executed by rhodecode