Make info extraction method more safe

This commit is contained in:
Paul Chavard 2018-08-13 16:40:16 +02:00
parent 839b7627ac
commit 9de3e6e74b
3 changed files with 4 additions and 9 deletions

View file

@ -101,8 +101,6 @@ class ApplicationController < ActionController::Base
super
user = logged_user
payload[:xhr] = !!request.xhr?
payload.merge!({
user_agent: request.user_agent,
user_id: user&.id,

View file

@ -20,7 +20,7 @@ Rails.application.configure do
config.lograge.custom_payload do |controller|
{
xhr: !!controller.request.xhr?
xhr: !!controller&.request&.xhr?
}
end
end

View file

@ -42,8 +42,7 @@ describe ApplicationController, type: :controller do
end
expect(payload).to eq({
user_agent: 'Rails Testing',
user_roles: 'Guest',
xhr: false
user_roles: 'Guest'
})
end
end
@ -64,8 +63,7 @@ describe ApplicationController, type: :controller do
user_agent: 'Rails Testing',
user_id: current_user.id,
user_email: current_user.email,
user_roles: 'User',
xhr: false
user_roles: 'User'
})
end
end
@ -89,8 +87,7 @@ describe ApplicationController, type: :controller do
user_agent: 'Rails Testing',
user_id: current_user.id,
user_email: current_user.email,
user_roles: 'User, Gestionnaire, Administrateur, Administration',
xhr: false
user_roles: 'User, Gestionnaire, Administrateur, Administration'
})
end
end