2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-28 19:44:11 +01:00
|
|
|
module Manager
|
|
|
|
class ApplicationController < Administrate::ApplicationController
|
2020-11-05 15:09:11 +01:00
|
|
|
before_action :authenticate_super_admin!
|
2017-12-28 19:44:11 +01:00
|
|
|
before_action :default_params
|
|
|
|
|
|
|
|
def default_params
|
2023-01-10 00:11:54 +01:00
|
|
|
request.query_parameters[resource_name] ||= {
|
2023-03-30 15:33:01 +02:00
|
|
|
order: "id",
|
2018-11-06 18:32:35 +01:00
|
|
|
direction: "desc"
|
|
|
|
}
|
2017-12-28 19:44:11 +01:00
|
|
|
end
|
2018-01-17 12:13:26 +01:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
2020-11-05 15:09:11 +01:00
|
|
|
def authenticate_super_admin!
|
|
|
|
if super_admin_signed_in? && current_super_admin.otp_required_for_login?
|
2018-01-17 12:13:26 +01:00
|
|
|
super
|
2020-11-05 15:09:11 +01:00
|
|
|
elsif super_admin_signed_in?
|
2021-09-07 19:04:54 +02:00
|
|
|
SUPER_ADMIN_OTP_ENABLED ? (redirect_to edit_super_admin_otp_path) : super
|
2018-01-17 12:13:26 +01:00
|
|
|
else
|
2020-11-05 15:09:11 +01:00
|
|
|
redirect_to new_super_admin_session_path
|
2018-01-17 12:13:26 +01:00
|
|
|
end
|
|
|
|
end
|
2019-11-18 23:11:38 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-03-30 15:33:01 +02:00
|
|
|
def sorting_attribute
|
|
|
|
attribute = super
|
|
|
|
|
|
|
|
# do not sort by non-indexed created_at. This require a full table scan, locking every other transactions.
|
|
|
|
return :id if attribute.to_sym == :created_at
|
|
|
|
|
|
|
|
attribute
|
|
|
|
end
|
|
|
|
|
2019-11-18 23:11:38 +01:00
|
|
|
# private method called by rails fwk
|
|
|
|
# see https://github.com/roidrage/lograge
|
|
|
|
def append_info_to_payload(payload)
|
|
|
|
super
|
|
|
|
|
2023-11-08 12:19:03 +01:00
|
|
|
to_log = {
|
2019-11-18 23:11:38 +01:00
|
|
|
user_agent: request.user_agent,
|
|
|
|
user_id: current_user&.id,
|
|
|
|
user_email: current_user&.email
|
2023-11-08 12:19:03 +01:00
|
|
|
}
|
2019-11-18 23:11:38 +01:00
|
|
|
|
|
|
|
if browser.known?
|
2023-11-08 12:19:03 +01:00
|
|
|
to_log.merge!({
|
2019-11-18 23:11:38 +01:00
|
|
|
browser: browser.name,
|
|
|
|
browser_version: browser.version.to_s,
|
|
|
|
platform: browser.platform.name
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2023-11-08 12:19:03 +01:00
|
|
|
payload[:to_log] = to_log
|
2019-11-18 23:11:38 +01:00
|
|
|
end
|
2017-12-28 19:44:11 +01:00
|
|
|
end
|
|
|
|
end
|