##// END OF EJS Templates
hooks: deprecate old action_logger
marcink -
r1754:0436d3e6 default
parent child Browse files
Show More
@@ -31,7 +31,6 b' import rhodecode'
31 31 from rhodecode import events
32 32 from rhodecode.lib import helpers as h
33 33 from rhodecode.lib import audit_logger
34 from rhodecode.lib.utils import action_logger
35 34 from rhodecode.lib.utils2 import safe_str
36 35 from rhodecode.lib.exceptions import HTTPLockedRC, UserCreationError
37 36 from rhodecode.model.db import Repository, User
@@ -153,9 +152,6 b' def pre_pull(extras):'
153 152
154 153 def post_pull(extras):
155 154 """Hook executed after client pulls the code."""
156 user = User.get_by_username(extras.username)
157 action = 'pull'
158 action_logger(user, action, extras.repository, extras.ip, commit=True)
159 155
160 156 audit_user = audit_logger.UserWrap(
161 157 username=extras.username,
@@ -175,6 +171,7 b' def post_pull(extras):'
175 171 output = ''
176 172 # make lock is a tri state False, True, None. We only make lock on True
177 173 if extras.make_lock is True and not is_shadow_repo(extras):
174 user = User.get_by_username(extras.username)
178 175 Repository.lock(Repository.get_by_repo_name(extras.repository),
179 176 user.user_id,
180 177 lock_reason=Repository.LOCK_PULL)
@@ -195,16 +192,11 b' def post_pull(extras):'
195 192
196 193 def post_push(extras):
197 194 """Hook executed after user pushes to the repository."""
198 action_tmpl = extras.action + ':%s'
199 commit_ids = extras.commit_ids[:29000]
195 commit_ids = extras.commit_ids
200 196
201 action = action_tmpl % ','.join(commit_ids)
202 action_logger(
203 extras.username, action, extras.repository, extras.ip, commit=True)
204
197 # log the push call
205 198 audit_user = audit_logger.UserWrap(
206 username=extras.username,
207 ip_addr=extras.ip)
199 username=extras.username, ip_addr=extras.ip)
208 200 repo = audit_logger.RepoWrap(repo_name=extras.repository)
209 201 audit_logger.store(
210 202 action='user.push', action_data={
@@ -539,7 +539,7 b' class TestPullrequestsController:'
539 539 # Check the relevant log entries were added
540 540 user_logs = UserLog.query() \
541 541 .filter(UserLog.version == UserLog.VERSION_1) \
542 .order_by('-user_log_id').limit(4)
542 .order_by('-user_log_id').limit(3)
543 543 actions = [log.action for log in user_logs]
544 544 pr_commit_ids = PullRequestModel()._get_commit_ids(pull_request)
545 545 expected_actions = [
@@ -547,10 +547,16 b' class TestPullrequestsController:'
547 547 u'user_merged_pull_request:%d' % pull_request_id,
548 548 # The action below reflect that the post push actions were executed
549 549 u'user_commented_pull_request:%d' % pull_request_id,
550 u'push:%s' % ','.join(pr_commit_ids),
551 550 ]
552 551 assert actions == expected_actions
553 552
553 user_logs = UserLog.query() \
554 .filter(UserLog.version == UserLog.VERSION_2) \
555 .order_by('-user_log_id').limit(1)
556 actions = [log.action for log in user_logs]
557 assert actions == ['user.push']
558 assert user_logs[0].action_data['commit_ids'] == pr_commit_ids
559
554 560 # Check post_push rcextension was really executed
555 561 push_calls = rhodecode.EXTENSIONS.calls['post_push']
556 562 assert len(push_calls) == 1
@@ -20,15 +20,10 b''
20 20
21 21 import mock
22 22 import pytest
23
23 from rhodecode.model.db import Session, UserLog
24 24 from rhodecode.lib import hooks_base, utils2
25 25
26 26
27 @mock.patch.multiple(
28 hooks_base,
29 action_logger=mock.Mock(),
30 post_push_extension=mock.Mock(),
31 Repository=mock.Mock())
32 27 def test_post_push_truncates_commits(user_regular, repo_stub):
33 28 extras = {
34 29 'ip': '127.0.0.1',
@@ -49,11 +44,13 b' def test_post_push_truncates_commits(use'
49 44 hooks_base.post_push(extras)
50 45
51 46 # Calculate appropriate action string here
52 expected_action = 'push_local:%s' % ','.join(extras.commit_ids[:29000])
47 commit_ids = extras.commit_ids[:10000]
53 48
54 hooks_base.action_logger.assert_called_with(
55 extras.username, expected_action, extras.repository, extras.ip,
56 commit=True)
49 entry = UserLog.query().order_by('-user_log_id').first()
50 assert entry.action == 'user.push'
51 assert entry.action_data['commit_ids'] == commit_ids
52 Session().delete(entry)
53 Session().commit()
57 54
58 55
59 56 def assert_called_with_mock(callable_, expected_mock_name):
General Comments 0
You need to be logged in to leave comments. Login now