diff --git a/rhodecode/apps/ssh_support/lib/backends/base.py b/rhodecode/apps/ssh_support/lib/backends/base.py --- a/rhodecode/apps/ssh_support/lib/backends/base.py +++ b/rhodecode/apps/ssh_support/lib/backends/base.py @@ -93,6 +93,7 @@ class VcsServer(object): scm_data = { 'ip': os.environ['SSH_CLIENT'].split()[0], 'username': self.user.username, + 'user_id': self.user.user_id, 'action': action, 'repository': self.repo_name, 'scm': self.backend, diff --git a/rhodecode/apps/ssh_support/tests/test_server_git.py b/rhodecode/apps/ssh_support/tests/test_server_git.py --- a/rhodecode/apps/ssh_support/tests/test_server_git.py +++ b/rhodecode/apps/ssh_support/tests/test_server_git.py @@ -127,6 +127,7 @@ class TestGitServer(object): expected_data = { 'username': git_server.user.username, + 'user_id': git_server.user.user_id, 'scm': 'git', 'repository': git_server.repo_name, 'make_lock': None, diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -169,19 +169,20 @@ def vcs_operation_context( make_lock = None locked_by = [None, None, None] is_anonymous = username == User.DEFAULT_USER + user = User.get_by_username(username) if not is_anonymous and check_locking: log.debug('Checking locking on repository "%s"', repo_name) - user = User.get_by_username(username) repo = Repository.get_by_repo_name(repo_name) make_lock, __, locked_by = repo.get_locking_state( action, user.user_id) - + user_id = user.user_id settings_model = VcsSettingsModel(repo=repo_name) ui_settings = settings_model.get_ui_settings() extras = { 'ip': get_ip_addr(environ), 'username': username, + 'user_id': user_id, 'action': action, 'repository': repo_name, 'scm': scm, diff --git a/rhodecode/tests/events/test_repo.py b/rhodecode/tests/events/test_repo.py --- a/rhodecode/tests/events/test_repo.py +++ b/rhodecode/tests/events/test_repo.py @@ -37,6 +37,7 @@ def scm_extras(user_regular, repo_stub): extras = utils2.AttributeDict({ 'ip': '127.0.0.1', 'username': user_regular.username, + 'user_id': user_regular.user_id, 'action': '', 'repository': repo_stub.repo_name, 'scm': repo_stub.scm_instance().alias, diff --git a/rhodecode/tests/integrations/conftest.py b/rhodecode/tests/integrations/conftest.py --- a/rhodecode/tests/integrations/conftest.py +++ b/rhodecode/tests/integrations/conftest.py @@ -37,6 +37,7 @@ def repo_push_event(backend, user_regula scm_extras = { 'ip': '127.0.0.1', 'username': user_regular.username, + 'user_id': user_regular.user_id, 'action': '', 'repository': repo.repo_name, 'scm': repo.scm_instance().alias, diff --git a/rhodecode/tests/lib/test_base.py b/rhodecode/tests/lib/test_base.py --- a/rhodecode/tests/lib/test_base.py +++ b/rhodecode/tests/lib/test_base.py @@ -72,6 +72,8 @@ def test_vcs_operation_context_can_skip_ base, 'get_enabled_hook_classes', Mock(return_value=['stub_hook'])) @patch('rhodecode.lib.utils2.get_server_url', Mock(return_value='https://example.com')) +@patch.object(db.User, 'get_by_username', + Mock(return_value=Mock(return_value=1))) def call_vcs_operation_context(**kwargs_override): kwargs = { 'repo_name': 'stub_repo_name', diff --git a/rhodecode/tests/lib/test_hooks_base.py b/rhodecode/tests/lib/test_hooks_base.py --- a/rhodecode/tests/lib/test_hooks_base.py +++ b/rhodecode/tests/lib/test_hooks_base.py @@ -28,6 +28,7 @@ def test_post_push_truncates_commits(use extras = { 'ip': '127.0.0.1', 'username': user_regular.username, + 'user_id': user_regular.user_id, 'action': 'push_local', 'repository': repo_stub.repo_name, 'scm': 'git', @@ -64,6 +65,7 @@ def hook_extras(user_regular, repo_stub) extras = utils2.AttributeDict({ 'ip': '127.0.0.1', 'username': user_regular.username, + 'user_id': user_regular.user_id, 'action': 'push', 'repository': repo_stub.repo_name, 'scm': '', diff --git a/rhodecode/tests/models/test_pullrequest.py b/rhodecode/tests/models/test_pullrequest.py --- a/rhodecode/tests/models/test_pullrequest.py +++ b/rhodecode/tests/models/test_pullrequest.py @@ -458,6 +458,7 @@ def merge_extras(user_regular): extras = { 'ip': '127.0.0.1', 'username': user_regular.username, + 'user_id': user_regular.user_id, 'action': 'push', 'repository': 'fake_target_repo_name', 'scm': 'git',