Changeset - 2d0de5aa95d1
[Not reviewed]
default
0 3 0
Mads Kiilerich - 9 years ago 2017-04-07 04:22:42
mads@kiilerich.com
lib: pass full user to _check_locking_state - not just user_id
3 files changed with 5 insertions and 12 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/base.py
Show inline comments
 
@@ -321,25 +321,23 @@ class BaseVCSController(object):
 

	
 
        return True
 

	
 
    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
 
        can have 3 states: None (do nothing), True (make lock), and False
 
        (release lock). This value is later propagated to hooks, telling them
 
        what to do.
 
        """
 
        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':
 
                # Check if repo already is locked !, if it is compare users
 
                user_id, _date = locked_by
 
                if user.user_id == user_id:
kallithea/lib/middleware/simplegit.py
Show inline comments
 
@@ -33,13 +33,13 @@ import re
 
import logging
 
import traceback
 

	
 
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
 
from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback
 
from kallithea.lib.utils import make_ui, is_valid_repo
 
from kallithea.lib.exceptions import HTTPLockedRC
 
@@ -121,15 +121,13 @@ class SimpleGit(BaseVCSController):
 
        repo_path = os.path.join(safe_str(self.basepath),str_repo_name)
 
        log.debug('Repository path is %s', repo_path)
 

	
 
        # 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})
 

	
 
        fix_PATH()
 
        log.debug('HOOKS extras is %s', extras)
kallithea/lib/middleware/simplehg.py
Show inline comments
 
@@ -31,13 +31,12 @@ Original author and date, and relevant c
 
import os
 
import logging
 
import traceback
 

	
 
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
 
from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback
 
from kallithea.lib.utils import make_ui, is_valid_repo, ui_sections
 
from kallithea.lib.vcs.utils.hgcompat import RepoError, hgweb_mod
 
@@ -131,15 +130,13 @@ class SimpleHg(BaseVCSController):
 
        # want to check locking on those
 
        if environ['QUERY_STRING'] == 'cmd=listkeys':
 
            pass
 
        # 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})
 

	
 
        fix_PATH()
 
        log.debug('HOOKS extras is %s', extras)
0 comments (0 inline, 0 general)