Commit 674106e3 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'sh-fix-username-logging' into 'master'

Fix username and ID not logging in production_json.log for Git activity

Closes gitlab-ee#3611

See merge request gitlab-org/gitlab-ce!14647
parents 8921af39 5d52bb59
...@@ -85,10 +85,19 @@ class ApplicationController < ActionController::Base ...@@ -85,10 +85,19 @@ class ApplicationController < ActionController::Base
super super
payload[:remote_ip] = request.remote_ip payload[:remote_ip] = request.remote_ip
if current_user.present? logged_user = auth_user
payload[:user_id] = current_user.id
payload[:username] = current_user.username if logged_user.present?
payload[:user_id] = logged_user.try(:id)
payload[:username] = logged_user.try(:username)
end
end end
# Controllers such as GitHttpController may use alternative methods
# (e.g. tokens) to authenticate the user, whereas Devise sets current_user
def auth_user
return current_user if current_user.present?
return try(:authenticated_user)
end end
# This filter handles both private tokens and personal access tokens # This filter handles both private tokens and personal access tokens
......
...@@ -9,6 +9,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController ...@@ -9,6 +9,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController
delegate :actor, :authentication_abilities, to: :authentication_result, allow_nil: true delegate :actor, :authentication_abilities, to: :authentication_result, allow_nil: true
alias_method :user, :actor alias_method :user, :actor
alias_method :authenticated_user, :actor
# Git clients will not know what authenticity token to send along # Git clients will not know what authenticity token to send along
skip_before_action :verify_authenticity_token skip_before_action :verify_authenticity_token
......
---
title: Fix username and ID not logging in production_json.log for Git activity
merge_request:
author:
type: fixed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment