comparison rhodecode/lib/middleware/simplehg.py @ 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 d9972f76322e
children 044c31d67ccc
comparison
equal deleted inserted replaced
2499:c919d8c4f6a2 2500:94ef0b609d17
68 def _handle_request(self, environ, start_response): 68 def _handle_request(self, environ, start_response):
69 if not is_mercurial(environ): 69 if not is_mercurial(environ):
70 return self.application(environ, start_response) 70 return self.application(environ, start_response)
71 71
72 ipaddr = self._get_ip_addr(environ) 72 ipaddr = self._get_ip_addr(environ)
73 73 username = None
74 # skip passing error to error controller 74 # skip passing error to error controller
75 environ['pylons.status_code_redirect'] = True 75 environ['pylons.status_code_redirect'] = True
76 76
77 #====================================================================== 77 #======================================================================
78 # EXTRACT REPOSITORY NAME FROM ENV 78 # EXTRACT REPOSITORY NAME FROM ENV
129 return result.wsgi_application(environ, start_response) 129 return result.wsgi_application(environ, start_response)
130 130
131 #============================================================== 131 #==============================================================
132 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME 132 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME
133 #============================================================== 133 #==============================================================
134 if action in ['pull', 'push']: 134 try:
135 try: 135 user = self.__get_user(username)
136 user = self.__get_user(username) 136 if user is None or not user.active:
137 if user is None or not user.active:
138 return HTTPForbidden()(environ, start_response)
139 username = user.username
140 except:
141 log.error(traceback.format_exc())
142 return HTTPInternalServerError()(environ,
143 start_response)
144
145 #check permissions for this repository
146 perm = self._check_permission(action, user, repo_name)
147 if perm is not True:
148 return HTTPForbidden()(environ, start_response) 137 return HTTPForbidden()(environ, start_response)
138 username = user.username
139 except:
140 log.error(traceback.format_exc())
141 return HTTPInternalServerError()(environ, start_response)
142
143 #check permissions for this repository
144 perm = self._check_permission(action, user, repo_name)
145 if perm is not True:
146 return HTTPForbidden()(environ, start_response)
149 147
150 # extras are injected into mercurial UI object and later available 148 # extras are injected into mercurial UI object and later available
151 # in hg hooks executed by rhodecode 149 # in hg hooks executed by rhodecode
152 extras = { 150 extras = {
153 'ip': ipaddr, 151 'ip': ipaddr,