changeset 6581:2d0de5aa95d1

lib: pass full user to _check_locking_state - not just user_id
author Mads Kiilerich <mads@kiilerich.com>
date Fri, 07 Apr 2017 04:22:42 +0200
parents 8eda7bc543cd
children 1ae319cb41b1
files kallithea/lib/base.py kallithea/lib/middleware/simplegit.py kallithea/lib/middleware/simplehg.py
diffstat 3 files changed, 5 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/base.py	Fri Apr 07 04:21:38 2017 +0200
+++ b/kallithea/lib/base.py	Fri Apr 07 04:22:42 2017 +0200
@@ -324,7 +324,7 @@
     def _get_ip_addr(self, environ):
         return _get_ip_addr(environ)
 
-    def _check_locking_state(self, action, repo, user_id):
+    def _check_locking_state(self, action, repo_name, user):
         """
         Checks locking on this repository, if locking is enabled, and if lock
         is present. Returns a tuple of make_lock, locked, locked_by. make_lock
@@ -334,9 +334,7 @@
         """
         locked = False  # defines that locked error should be thrown to user
         make_lock = None
-        repo = Repository.get_by_repo_name(repo)
-        user = User.get(user_id)
-
+        repo = Repository.get_by_repo_name(repo_name)
         locked_by = repo.locked
         if repo and repo.enable_locking:
             if action == 'push':
--- a/kallithea/lib/middleware/simplegit.py	Fri Apr 07 04:21:38 2017 +0200
+++ b/kallithea/lib/middleware/simplegit.py	Fri Apr 07 04:22:42 2017 +0200
@@ -36,7 +36,7 @@
 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \
     HTTPNotAcceptable
-from kallithea.model.db import User, Ui
+from kallithea.model.db import Ui
 
 from kallithea.lib.utils2 import safe_str, safe_unicode, fix_PATH, get_server_url, \
     _set_extras
@@ -124,9 +124,7 @@
         # CHECK LOCKING only if it's not ANONYMOUS USER
         if not user.is_default_user:
             log.debug('Checking locking on repository')
-            (make_lock,
-             locked,
-             locked_by) = self._check_locking_state(action, repo_name, user.user_id)
+            make_lock, locked, locked_by = self._check_locking_state(action, repo_name, user)
             # store the make_lock for later evaluation in hooks
             extras.update({'make_lock': make_lock,
                            'locked_by': locked_by})
--- a/kallithea/lib/middleware/simplehg.py	Fri Apr 07 04:21:38 2017 +0200
+++ b/kallithea/lib/middleware/simplehg.py	Fri Apr 07 04:22:42 2017 +0200
@@ -34,7 +34,6 @@
 
 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \
     HTTPNotAcceptable, HTTPBadRequest
-from kallithea.model.db import User
 
 from kallithea.lib.utils2 import safe_str, safe_unicode, fix_PATH, get_server_url, \
     _set_extras
@@ -134,9 +133,7 @@
         # CHECK LOCKING only if it's not ANONYMOUS USER
         elif not user.is_default_user:
             log.debug('Checking locking on repository')
-            (make_lock,
-             locked,
-             locked_by) = self._check_locking_state(action, repo_name, user.user_id)
+            make_lock, locked, locked_by = self._check_locking_state(action, repo_name, user)
             # store the make_lock for later evaluation in hooks
             extras.update({'make_lock': make_lock,
                            'locked_by': locked_by})