0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-27 03:20:27 +01:00
discourse-custom-wizard/app/controllers/custom_wizard/admin/logs.rb

45 Zeilen
1,1 KiB
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
2020-04-15 02:46:44 +02:00
class CustomWizard::AdminLogsController < CustomWizard::AdminController
2022-03-12 15:20:54 +01:00
before_action :find_wizard, except: [:index]
2020-04-15 02:46:44 +02:00
def index
2022-03-12 15:20:54 +01:00
render json: ActiveModel::ArraySerializer.new(
CustomWizard::Wizard.list(current_user),
each_serializer: CustomWizard::BasicWizardSerializer
2020-04-15 02:46:44 +02:00
)
end
2022-03-12 15:20:54 +01:00
def show
render_json_dump(
wizard: CustomWizard::BasicWizardSerializer.new(@wizard, root: false),
logs: ActiveModel::ArraySerializer.new(
log_list.logs,
each_serializer: CustomWizard::LogSerializer
),
total: log_list.total
)
end
protected
def log_list
@log_list ||= begin
list = CustomWizard::Log.list(params[:page].to_i, params[:limit].to_i, params[:wizard_id])
if list.logs.any? && (usernames = list.logs.map(&:username)).present?
user_map = User.where(username: usernames)
.reduce({}) do |result, user|
result[user.username] = user
result
end
list.logs.each do |log_item|
log_item.user = user_map[log_item.username]
end
end
list
end
end
2021-03-11 07:30:15 +01:00
end