Fix username and ID not logging in production_json.log for Git activity
Devise sets `current_user`, but not all controllers authenticate users by session tokens. Try to use the controller-defined `authenticated_user` if `current_user` is not available. Closes gitlab-org/gitlab-ee#3611
This commit is contained in:
parent
aaa57c9d35
commit
5d52bb59dc
|
@ -85,12 +85,21 @@ class ApplicationController < ActionController::Base
|
|||
super
|
||||
payload[:remote_ip] = request.remote_ip
|
||||
|
||||
if current_user.present?
|
||||
payload[:user_id] = current_user.id
|
||||
payload[:username] = current_user.username
|
||||
logged_user = auth_user
|
||||
|
||||
if logged_user.present?
|
||||
payload[:user_id] = logged_user.try(:id)
|
||||
payload[:username] = logged_user.try(:username)
|
||||
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
|
||||
|
||||
# This filter handles both private tokens and personal access tokens
|
||||
def authenticate_user_from_private_token!
|
||||
token = params[:private_token].presence || request.headers['PRIVATE-TOKEN'].presence
|
||||
|
|
|
@ -9,6 +9,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController
|
|||
delegate :actor, :authentication_abilities, to: :authentication_result, allow_nil: true
|
||||
|
||||
alias_method :user, :actor
|
||||
alias_method :authenticated_user, :actor
|
||||
|
||||
# Git clients will not know what authenticity token to send along
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix username and ID not logging in production_json.log for Git activity
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
Loading…
Reference in New Issue