audit-logs: store properly IP and user for certain comments types.

- before mostly IP could be missing from audit log data.
This commit is contained in:
Marcin Kuzminski 2018-04-26 00:59:07 +02:00
parent 7ba1dd57ac
commit 1a717208f4
5 changed files with 16 additions and 11 deletions

View file

@ -548,7 +548,8 @@ def comment_pull_request(
closing_pr=False,
renderer=renderer,
comment_type=comment_type,
resolves_comment_id=resolves_comment_id
resolves_comment_id=resolves_comment_id,
auth_user=apiuser
)
if allowed_to_change_status and status:

View file

@ -1469,7 +1469,8 @@ def comment_commit(
status_change_type=status,
renderer=renderer,
comment_type=comment_type,
resolves_comment_id=resolves_comment_id
resolves_comment_id=resolves_comment_id,
auth_user=apiuser
)
if status:
# also do a status change

View file

@ -437,7 +437,8 @@ class RepoCommitsView(RepoAppView):
if status else None),
status_change_type=status,
comment_type=comment_type,
resolves_comment_id=resolves_comment_id
resolves_comment_id=resolves_comment_id,
auth_user=self._rhodecode_user
)
# get status if set !
@ -528,7 +529,7 @@ class RepoCommitsView(RepoAppView):
comment_repo_admin = is_repo_admin and is_repo_comment
if super_admin or comment_owner or comment_repo_admin:
CommentsModel().delete(comment=comment, user=self._rhodecode_db_user)
CommentsModel().delete(comment=comment, auth_user=self._rhodecode_user)
Session().commit()
return True
else:

View file

@ -1285,7 +1285,7 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
if super_admin or comment_owner or comment_repo_admin:
old_calculated_status = comment.pull_request.calculated_review_status()
CommentsModel().delete(comment=comment, user=self._rhodecode_user)
CommentsModel().delete(comment=comment, auth_user=self._rhodecode_user)
Session().commit()
calculated_status = comment.pull_request.calculated_review_status()
if old_calculated_status != calculated_status:

View file

@ -159,18 +159,18 @@ class CommentsModel(BaseModel):
return todos
def _log_audit_action(self, action, action_data, user, comment):
def _log_audit_action(self, action, action_data, auth_user, comment):
audit_logger.store(
action=action,
action_data=action_data,
user=user,
user=auth_user,
repo=comment.repo)
def create(self, text, repo, user, commit_id=None, pull_request=None,
f_path=None, line_no=None, status_change=None,
status_change_type=None, comment_type=None,
resolves_comment_id=None, closing_pr=False, send_email=True,
renderer=None):
renderer=None, auth_user=None):
"""
Creates new comment for commit or pull request.
IF status_change is not none this comment is associated with a
@ -190,6 +190,8 @@ class CommentsModel(BaseModel):
:param send_email:
:param renderer: pick renderer for this comment
"""
auth_user = auth_user or user
if not text:
log.warning('Missing text for comment, skipping...')
return
@ -355,7 +357,7 @@ class CommentsModel(BaseModel):
comment_data = comment.get_api_data()
self._log_audit_action(
action, {'data': comment_data}, user, comment)
action, {'data': comment_data}, auth_user, comment)
msg_url = ''
channel = None
@ -388,7 +390,7 @@ class CommentsModel(BaseModel):
return comment
def delete(self, comment, user):
def delete(self, comment, auth_user):
"""
Deletes given comment
"""
@ -402,7 +404,7 @@ class CommentsModel(BaseModel):
action = 'repo.commit.comment.delete'
self._log_audit_action(
action, {'old_data': old_data}, user, comment)
action, {'old_data': old_data}, auth_user, comment)
return comment