2019-08-14 09:48:44 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
|
|
|
include DeviseTokenAuth::Concerns::SetUserByToken
|
2021-09-14 06:25:02 +00:00
|
|
|
include RequestExceptionHandler
|
2022-06-13 14:48:38 +00:00
|
|
|
include Pundit::Authorization
|
2020-11-30 10:54:54 +00:00
|
|
|
include SwitchLocale
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2021-07-14 13:10:24 +00:00
|
|
|
skip_before_action :verify_authenticity_token
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
before_action :set_current_user, unless: :devise_controller?
|
2020-11-30 10:54:54 +00:00
|
|
|
around_action :switch_locale
|
2019-08-14 09:48:44 +00:00
|
|
|
around_action :handle_with_exception, unless: :devise_controller?
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_current_user
|
|
|
|
@user ||= current_user
|
|
|
|
Current.user = @user
|
|
|
|
end
|
|
|
|
|
2020-05-26 17:08:48 +00:00
|
|
|
def pundit_user
|
|
|
|
{
|
|
|
|
user: Current.user,
|
|
|
|
account: Current.account,
|
|
|
|
account_user: Current.account_user
|
|
|
|
}
|
|
|
|
end
|
2022-09-14 15:47:00 +00:00
|
|
|
|
|
|
|
def append_info_to_payload(payload)
|
|
|
|
super
|
2022-09-14 15:48:26 +00:00
|
|
|
payload[:level] = case payload[:status]
|
|
|
|
when 200
|
|
|
|
'INFO'
|
|
|
|
when 302
|
|
|
|
'WARN'
|
|
|
|
else
|
|
|
|
'ERROR'
|
|
|
|
end
|
2022-09-14 15:47:00 +00:00
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|