0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-10-19 04:02:39 +02:00
discourse-custom-wizard/app/controllers/custom_wizard/wizard.rb

44 Zeilen
1.004 B
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
2023-01-18 19:53:36 +01:00
class CustomWizard::WizardController < ::CustomWizard::WizardClientController
2024-10-16 14:18:23 +02:00
requires_plugin "discourse-custom-wizard"
def show
if wizard.present?
2024-10-16 13:52:03 +02:00
render json: CustomWizard::WizardSerializer.new(wizard, scope: guardian, root: false).as_json,
status: 200
else
2024-10-16 13:52:03 +02:00
render json: { error: I18n.t("wizard.none") }
2017-09-23 04:34:07 +02:00
end
end
2017-11-01 05:21:14 +01:00
def skip
params.require(:wizard_id)
2021-03-11 07:30:15 +01:00
if wizard.required && !wizard.completed? && wizard.permitted?
2024-10-16 13:52:03 +02:00
return render json: { error: I18n.t("wizard.no_skip") }
2017-11-01 05:21:14 +01:00
end
2024-10-16 13:52:03 +02:00
result = { success: "OK" }
2021-03-11 07:30:15 +01:00
if current_user && wizard.can_access?
2022-06-15 09:57:20 +02:00
if redirect_to = wizard.current_submission&.redirect_to
result.merge!(redirect_to: redirect_to)
2019-06-19 07:23:10 +02:00
end
2017-11-01 05:21:14 +01:00
wizard.cleanup_on_skip!
2017-11-01 05:21:14 +01:00
end
render json: result
end
2021-03-11 07:30:15 +01:00
2022-03-16 12:33:34 +01:00
protected
def wizard
2024-10-16 13:52:03 +02:00
@wizard ||=
begin
return nil if @builder.blank?
@builder.build({ reset: params[:reset] }, params)
end
2020-11-03 01:24:20 +01:00
end
2017-09-23 04:34:07 +02:00
end