Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-25 18:50:27 +01:00
Added debugging
Dieser Commit ist enthalten in:
Ursprung
83243af22d
Commit
4c3e88beee
4 geänderte Dateien mit 54 neuen und 9 gelöschten Zeilen
|
@ -31,3 +31,4 @@ en:
|
||||||
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."
|
|
@ -21,3 +21,5 @@ plugins:
|
||||||
wizard_api_features:
|
wizard_api_features:
|
||||||
client: true
|
client: true
|
||||||
default: false
|
default: false
|
||||||
|
wizard_action_debug:
|
||||||
|
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
|
||||||
|
@ -30,10 +44,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(: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