Cleanup after merge
Dieser Commit ist enthalten in:
Ursprung
69fd3d451d
Commit
d57f260def
4 geänderte Dateien mit 70 neuen und 30 gelöschten Zeilen
|
@ -1,9 +1,44 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class CustomWizard::AdminLogsController < CustomWizard::AdminController
|
class CustomWizard::AdminLogsController < CustomWizard::AdminController
|
||||||
|
before_action :find_wizard, except: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render_serialized(
|
render json: ActiveModel::ArraySerializer.new(
|
||||||
CustomWizard::Log.list(params[:page].to_i, params[:limit].to_i),
|
CustomWizard::Wizard.list(current_user),
|
||||||
CustomWizard::LogSerializer
|
each_serializer: CustomWizard::BasicWizardSerializer
|
||||||
)
|
)
|
||||||
end
|
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 do |log_item|
|
||||||
|
log_item.user = user_map[log_item.username]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
list
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CustomWizard::LogSerializer < ApplicationSerializer
|
class CustomWizard::LogSerializer < ApplicationSerializer
|
||||||
attributes :message, :date
|
attributes :date,
|
||||||
|
:action,
|
||||||
|
:username,
|
||||||
|
:message
|
||||||
|
|
||||||
|
has_one :user, serializer: ::BasicUserSerializer, embed: :objects
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,16 +1,32 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class CustomWizard::SubmissionSerializer < ApplicationSerializer
|
class CustomWizard::SubmissionSerializer < ApplicationSerializer
|
||||||
attributes :id,
|
attributes :id,
|
||||||
:username,
|
|
||||||
:fields,
|
:fields,
|
||||||
:submitted_at,
|
:submitted_at
|
||||||
:route_to,
|
|
||||||
:redirect_on_complete,
|
|
||||||
:redirect_to
|
|
||||||
|
|
||||||
def username
|
has_one :user, serializer: ::BasicUserSerializer, embed: :objects
|
||||||
object.user.present? ?
|
|
||||||
object.user.username :
|
def include_user?
|
||||||
I18n.t('admin.wizard.submission.no_user', user_id: object.user_id)
|
object.user.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def fields
|
||||||
|
@fields ||= begin
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
object.wizard.template['steps'].each do |step|
|
||||||
|
step['fields'].each do |field|
|
||||||
|
if value = object.fields[field['id']]
|
||||||
|
result[field['id']] = {
|
||||||
|
value: value,
|
||||||
|
type: field['type'],
|
||||||
|
label: field['label']
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,22 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
if ENV['SIMPLECOV']
|
|
||||||
require 'simplecov'
|
|
||||||
|
|
||||||
SimpleCov.start do
|
|
||||||
root "plugins/discourse-custom-wizard"
|
|
||||||
track_files "plugins/discourse-custom-wizard/**/*.rb"
|
|
||||||
add_filter { |src| src.filename =~ /(\/spec\/|\/db\/|plugin\.rb|api|gems)/ }
|
|
||||||
SimpleCov.minimum_coverage 80
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
require 'oj'
|
|
||||||
Oj.default_options = Oj.default_options.merge(cache_str: -1)
|
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'webmock/rspec'
|
|
||||||
|
|
||||||
def get_wizard_fixture(path)
|
def get_wizard_fixture(path)
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
File.open(
|
File.open(
|
||||||
|
|
Laden …
In neuem Issue referenzieren