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