##// END OF EJS Templates
audit-logs: add push/pull actions to audit logs.
marcink -
r1736:70904f54 default
parent child Browse files
Show More
@@ -22,7 +22,7 b' import logging'
22 22 import datetime
23 23
24 24 from rhodecode.model import meta
25 from rhodecode.model.db import User, UserLog
25 from rhodecode.model.db import User, UserLog, Repository
26 26
27 27
28 28 log = logging.getLogger(__name__)
@@ -33,6 +33,8 b' ACTIONS = {'
33 33 'user.login.failure': {},
34 34 'user.logout': {},
35 35 'user.password.reset_request': {},
36 'user.push': {},
37 'user.pull': {},
36 38
37 39 'repo.add': {},
38 40 'repo.edit': {},
@@ -52,6 +54,16 b' class UserWrap(object):'
52 54 self.ip_addr = ip_addr
53 55
54 56
57 class RepoWrap(object):
58 """
59 Fake object used to imitate RepoObject that audit logger requires
60 """
61
62 def __init__(self, repo_id=None, repo_name=None):
63 self.repo_id = repo_id
64 self.repo_name = repo_name
65
66
55 67 def _store_log(action_name, action_data, user_id, username, user_data,
56 68 ip_address, repository_id, repository_name):
57 69 user_log = UserLog()
@@ -127,8 +139,13 b' def store('
127 139 'email': user.email,
128 140 }
129 141
142 repository_name = getattr(repo, 'repo_name', None)
130 143 repository_id = getattr(repo, 'repo_id', None)
131 repository_name = getattr(repo, 'repo_name', None)
144 if not repository_id:
145 # maybe we have repo_name ? Try to figure repo_id from repo_name
146 if repository_name:
147 repository_id = getattr(
148 Repository.get_by_repo_name(repository_name), 'repo_id', None)
132 149
133 150 user_log = _store_log(
134 151 action_name=safe_unicode(action),
@@ -30,6 +30,7 b' import logging'
30 30 import rhodecode
31 31 from rhodecode import events
32 32 from rhodecode.lib import helpers as h
33 from rhodecode.lib import audit_logger
33 34 from rhodecode.lib.utils import action_logger
34 35 from rhodecode.lib.utils2 import safe_str
35 36 from rhodecode.lib.exceptions import HTTPLockedRC, UserCreationError
@@ -156,6 +157,14 b' def post_pull(extras):'
156 157 action = 'pull'
157 158 action_logger(user, action, extras.repository, extras.ip, commit=True)
158 159
160 audit_user = audit_logger.UserWrap(
161 username=extras.username,
162 ip_addr=extras.ip)
163 audit_logger.store(
164 action='user.pull', action_data={
165 'user_agent': extras.user_agent},
166 user=audit_user, commit=True)
167
159 168 # Propagate to external components.
160 169 if not is_shadow_repo(extras):
161 170 post_pull_extension(**extras)
@@ -192,6 +201,16 b' def post_push(extras):'
192 201 action_logger(
193 202 extras.username, action, extras.repository, extras.ip, commit=True)
194 203
204 audit_user = audit_logger.UserWrap(
205 username=extras.username,
206 ip_addr=extras.ip)
207 repo = audit_logger.RepoWrap(repo_name=extras.repository)
208 audit_logger.store(
209 action='user.push', action_data={
210 'user_agent': extras.user_agent,
211 'commit_ids': commit_ids[:10000]},
212 user=audit_user, repo=repo, commit=True)
213
195 214 # Propagate to external components.
196 215 if not is_shadow_repo(extras):
197 216 post_push_extension(
@@ -537,7 +537,9 b' class TestPullrequestsController:'
537 537 pull_request, ChangesetStatus.STATUS_APPROVED)
538 538
539 539 # Check the relevant log entries were added
540 user_logs = UserLog.query().order_by('-user_log_id').limit(4)
540 user_logs = UserLog.query() \
541 .filter(UserLog.version == UserLog.VERSION_1) \
542 .order_by('-user_log_id').limit(4)
541 543 actions = [log.action for log in user_logs]
542 544 pr_commit_ids = PullRequestModel()._get_commit_ids(pull_request)
543 545 expected_actions = [
General Comments 0
You need to be logged in to leave comments. Login now