Added debugging
Dieser Commit ist enthalten in:
Ursprung
83243af22d
Commit
4c3e88beee
4 geänderte Dateien mit 54 neuen und 9 gelöschten Zeilen
|
@ -30,4 +30,5 @@ en:
|
||||||
wizard_redirect_exclude_paths: "Routes excluded from wizard redirects."
|
wizard_redirect_exclude_paths: "Routes excluded from wizard redirects."
|
||||||
wizard_recognised_image_upload_formats: "File types which will result in upload displaying an image preview"
|
wizard_recognised_image_upload_formats: "File types which will result in upload displaying an image preview"
|
||||||
wizard_step_advanced: "Enable advanced settings for wizard steps (experimental)."
|
wizard_step_advanced: "Enable advanced settings for wizard steps (experimental)."
|
||||||
wizard_api_features: "Enable API features (experimental)."
|
wizard_api_features: "Enable API features (experimental)."
|
||||||
|
wizard_action_debug: "Log action details for debugging."
|
|
@ -20,4 +20,6 @@ plugins:
|
||||||
default: false
|
default: false
|
||||||
wizard_api_features:
|
wizard_api_features:
|
||||||
client: true
|
client: true
|
||||||
|
default: false
|
||||||
|
wizard_action_debug:
|
||||||
default: false
|
default: false
|
|
@ -24,7 +24,7 @@ class CustomWizard::StepsController < ::ApplicationController
|
||||||
else
|
else
|
||||||
errors = []
|
errors = []
|
||||||
updater.errors.messages.each do |field, msg|
|
updater.errors.messages.each do |field, msg|
|
||||||
errors << { field: field, description: msg.join }
|
errors << { field: field, description: msg.join(',') }
|
||||||
end
|
end
|
||||||
render json: { errors: errors }, status: 422
|
render json: { errors: errors }, status: 422
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,8 @@ class CustomWizard::Action
|
||||||
attr_accessor :data,
|
attr_accessor :data,
|
||||||
:action,
|
:action,
|
||||||
:user,
|
:user,
|
||||||
:updater
|
:updater,
|
||||||
|
:result
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
@action = params[:action]
|
@action = params[:action]
|
||||||
|
@ -12,7 +13,20 @@ class CustomWizard::Action
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
ActiveRecord::Base.transaction { self.send(action['type'].to_sym) }
|
ActiveRecord::Base.transaction do
|
||||||
|
self.send(action['type'].to_sym)
|
||||||
|
|
||||||
|
if SiteSetting.wizard_action_debug
|
||||||
|
log = "action: #{action['type']}; "
|
||||||
|
log << "result: #{@result}"
|
||||||
|
|
||||||
|
updater.errors.messages.each do |field, msg|
|
||||||
|
log << "error: #{field.to_s}; #{msg.to_s}; "
|
||||||
|
end
|
||||||
|
|
||||||
|
Rails.logger.warn("Wizard Action: #{log.to_s}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mapper
|
def mapper
|
||||||
|
@ -21,19 +35,26 @@ class CustomWizard::Action
|
||||||
|
|
||||||
def create_topic
|
def create_topic
|
||||||
params = basic_topic_params
|
params = basic_topic_params
|
||||||
|
|
||||||
if params[:title].present? && params[:raw].present?
|
if params[:title].present? && params[:raw].present?
|
||||||
params[:category] = action_category
|
params[:category] = action_category
|
||||||
params[:tags] = action_tags
|
params[:tags] = action_tags
|
||||||
|
|
||||||
creator = PostCreator.new(user, params)
|
creator = PostCreator.new(user, params)
|
||||||
post = creator.create
|
post = creator.create
|
||||||
|
|
||||||
if creator.errors.present?
|
if creator.errors.present?
|
||||||
|
@result = "failed to create"
|
||||||
updater.errors.add(:create_topic, creator.errors.full_messages.join(" "))
|
updater.errors.add(:create_topic, creator.errors.full_messages.join(" "))
|
||||||
elsif action['skip_redirect'].blank?
|
elsif action['skip_redirect'].blank?
|
||||||
data['redirect_on_complete'] = post.topic.url
|
data['redirect_on_complete'] = post.topic.url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if creator.errors.blank?
|
||||||
|
@result = "success (created topic: #{post.topic.id})"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@result = "invalid params"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,10 +75,17 @@ class CustomWizard::Action
|
||||||
post = creator.create
|
post = creator.create
|
||||||
|
|
||||||
if creator.errors.present?
|
if creator.errors.present?
|
||||||
|
@result = "failed to create"
|
||||||
updater.errors.add(:send_message, creator.errors.full_messages.join(" "))
|
updater.errors.add(:send_message, creator.errors.full_messages.join(" "))
|
||||||
elsif action['skip_redirect'].blank?
|
elsif action['skip_redirect'].blank?
|
||||||
data['redirect_on_complete'] = post.topic.url
|
data['redirect_on_complete'] = post.topic.url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if creator.errors.blank?
|
||||||
|
@result = "success (created pm: #{post.topic.id})"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@result = "invalid params"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,11 +104,19 @@ class CustomWizard::Action
|
||||||
params = add_custom_fields(params)
|
params = add_custom_fields(params)
|
||||||
|
|
||||||
if params.present?
|
if params.present?
|
||||||
UserUpdater.new(Discourse.system_user, user).update(params)
|
result = UserUpdater.new(Discourse.system_user, user).update(params)
|
||||||
|
|
||||||
if params[:avatar].present?
|
if params[:avatar].present?
|
||||||
update_avatar(params[:avatar])
|
result = update_avatar(params[:avatar])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if result
|
||||||
|
@result = "success (updated fields #{params.keys.map{ |p| p.to_s }.join(',')})"
|
||||||
|
else
|
||||||
|
@result = "failed to update"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@result = "invalid params"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -160,9 +196,15 @@ class CustomWizard::Action
|
||||||
if groups.present?
|
if groups.present?
|
||||||
groups.each do |group_id|
|
groups.each do |group_id|
|
||||||
group = Group.find(group_id) if group_id
|
group = Group.find(group_id) if group_id
|
||||||
group.add(user) if group
|
result = group.add(user) if group
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if result
|
||||||
|
@result = "success (added to groups: #{groups.map { |g| g.id.to_s }.join(',')})"
|
||||||
|
else
|
||||||
|
@result = "failed to add"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def route_to
|
def route_to
|
||||||
|
|
Laden …
In neuem Issue referenzieren