summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-10-05 07:57:13 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-10-05 07:57:13 +0000
commit674106e3bc1944014f4903e844bb841a46ae7d93 (patch)
tree27bfb27e1313f3699134f46398c96d7590c07f69 /app
parent8921af39e74976e37e92c786bd957883110f6522 (diff)
parent5d52bb59dc632601f4028b430deae7348c5e279b (diff)
downloadgitlab-ce-674106e3bc1944014f4903e844bb841a46ae7d93.tar.gz
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
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb15
-rw-r--r--app/controllers/projects/git_http_client_controller.rb1
2 files changed, 13 insertions, 3 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 771c6f3034a..967fe39256a 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -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
diff --git a/app/controllers/projects/git_http_client_controller.rb b/app/controllers/projects/git_http_client_controller.rb
index 7d0e2b3e2ef..95d7a02e9e9 100644
--- a/app/controllers/projects/git_http_client_controller.rb
+++ b/app/controllers/projects/git_http_client_controller.rb
@@ -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