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]
|
2024-10-16 14:18:23 +02:00
|
|
|
requires_plugin "discourse-custom-wizard"
|
2022-03-12 15:20:54 +01:00
|
|
|
|
2020-04-15 02:46:44 +02:00
|
|
|
def index
|
2024-10-16 13:52:03 +02: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),
|
2024-10-16 13:52:03 +02:00
|
|
|
logs:
|
|
|
|
ActiveModel::ArraySerializer.new(
|
|
|
|
log_list.logs,
|
|
|
|
each_serializer: CustomWizard::LogSerializer,
|
|
|
|
),
|
|
|
|
total: log_list.total,
|
2022-03-12 15:20:54 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def log_list
|
2024-10-16 13:52:03 +02:00
|
|
|
@log_list ||=
|
|
|
|
begin
|
|
|
|
list = CustomWizard::Log.list(params[:page].to_i, params[:limit].to_i, params[:wizard_id])
|
2022-03-12 15:20:54 +01:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
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
|
2022-03-12 15:20:54 +01:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
list.logs.each { |log_item| log_item.user = user_map[log_item.username] }
|
2022-03-12 15:20:54 +01:00
|
|
|
end
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
list
|
|
|
|
end
|
2022-03-12 15:20:54 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
end
|