diff --git a/rhodecode/lib/hooks_base.py b/rhodecode/lib/hooks_base.py --- a/rhodecode/lib/hooks_base.py +++ b/rhodecode/lib/hooks_base.py @@ -31,7 +31,6 @@ import rhodecode from rhodecode import events from rhodecode.lib import helpers as h from rhodecode.lib import audit_logger -from rhodecode.lib.utils import action_logger from rhodecode.lib.utils2 import safe_str from rhodecode.lib.exceptions import HTTPLockedRC, UserCreationError from rhodecode.model.db import Repository, User @@ -153,9 +152,6 @@ def pre_pull(extras): def post_pull(extras): """Hook executed after client pulls the code.""" - user = User.get_by_username(extras.username) - action = 'pull' - action_logger(user, action, extras.repository, extras.ip, commit=True) audit_user = audit_logger.UserWrap( username=extras.username, @@ -175,6 +171,7 @@ def post_pull(extras): output = '' # make lock is a tri state False, True, None. We only make lock on True if extras.make_lock is True and not is_shadow_repo(extras): + user = User.get_by_username(extras.username) Repository.lock(Repository.get_by_repo_name(extras.repository), user.user_id, lock_reason=Repository.LOCK_PULL) @@ -195,16 +192,11 @@ def post_pull(extras): def post_push(extras): """Hook executed after user pushes to the repository.""" - action_tmpl = extras.action + ':%s' - commit_ids = extras.commit_ids[:29000] + commit_ids = extras.commit_ids - action = action_tmpl % ','.join(commit_ids) - action_logger( - extras.username, action, extras.repository, extras.ip, commit=True) - + # log the push call audit_user = audit_logger.UserWrap( - username=extras.username, - ip_addr=extras.ip) + username=extras.username, ip_addr=extras.ip) repo = audit_logger.RepoWrap(repo_name=extras.repository) audit_logger.store( action='user.push', action_data={ diff --git a/rhodecode/tests/functional/test_pullrequests.py b/rhodecode/tests/functional/test_pullrequests.py --- a/rhodecode/tests/functional/test_pullrequests.py +++ b/rhodecode/tests/functional/test_pullrequests.py @@ -539,7 +539,7 @@ class TestPullrequestsController: # Check the relevant log entries were added user_logs = UserLog.query() \ .filter(UserLog.version == UserLog.VERSION_1) \ - .order_by('-user_log_id').limit(4) + .order_by('-user_log_id').limit(3) actions = [log.action for log in user_logs] pr_commit_ids = PullRequestModel()._get_commit_ids(pull_request) expected_actions = [ @@ -547,10 +547,16 @@ class TestPullrequestsController: u'user_merged_pull_request:%d' % pull_request_id, # The action below reflect that the post push actions were executed u'user_commented_pull_request:%d' % pull_request_id, - u'push:%s' % ','.join(pr_commit_ids), ] assert actions == expected_actions + user_logs = UserLog.query() \ + .filter(UserLog.version == UserLog.VERSION_2) \ + .order_by('-user_log_id').limit(1) + actions = [log.action for log in user_logs] + assert actions == ['user.push'] + assert user_logs[0].action_data['commit_ids'] == pr_commit_ids + # Check post_push rcextension was really executed push_calls = rhodecode.EXTENSIONS.calls['post_push'] assert len(push_calls) == 1 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 @@ -20,15 +20,10 @@ import mock import pytest - +from rhodecode.model.db import Session, UserLog from rhodecode.lib import hooks_base, utils2 -@mock.patch.multiple( - hooks_base, - action_logger=mock.Mock(), - post_push_extension=mock.Mock(), - Repository=mock.Mock()) def test_post_push_truncates_commits(user_regular, repo_stub): extras = { 'ip': '127.0.0.1', @@ -49,11 +44,13 @@ def test_post_push_truncates_commits(use hooks_base.post_push(extras) # Calculate appropriate action string here - expected_action = 'push_local:%s' % ','.join(extras.commit_ids[:29000]) + commit_ids = extras.commit_ids[:10000] - hooks_base.action_logger.assert_called_with( - extras.username, expected_action, extras.repository, extras.ip, - commit=True) + entry = UserLog.query().order_by('-user_log_id').first() + assert entry.action == 'user.push' + assert entry.action_data['commit_ids'] == commit_ids + Session().delete(entry) + Session().commit() def assert_called_with_mock(callable_, expected_mock_name):