Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-24 02:10:29 +01:00
48 Zeilen
1,3 KiB
Ruby
48 Zeilen
1,3 KiB
Ruby
# frozen_string_literal: true
|
|
class CustomWizard::AdminLogsController < CustomWizard::AdminController
|
|
before_action :find_wizard, except: [:index]
|
|
requires_plugin "discourse-custom-wizard"
|
|
|
|
def index
|
|
render json:
|
|
ActiveModel::ArraySerializer.new(
|
|
CustomWizard::Wizard.list(current_user),
|
|
each_serializer: CustomWizard::BasicWizardSerializer,
|
|
)
|
|
end
|
|
|
|
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 { |log_item| log_item.user = user_map[log_item.username] }
|
|
end
|
|
|
|
list
|
|
end
|
|
end
|
|
end
|