2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2022-07-26 16:18:09 +02:00
|
|
|
class CustomWizard::WizardController < ::ApplicationController
|
2020-11-03 01:24:20 +01:00
|
|
|
before_action :ensure_plugin_enabled
|
2021-03-30 09:34:52 +02:00
|
|
|
|
2022-07-27 15:40:05 +02:00
|
|
|
def show
|
2022-07-26 16:18:09 +02:00
|
|
|
if wizard.present?
|
|
|
|
render json: CustomWizard::WizardSerializer.new(wizard, scope: guardian, root: false).as_json, status: 200
|
|
|
|
else
|
|
|
|
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
|
2018-05-09 07:06:43 +02:00
|
|
|
params.require(:wizard_id)
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2018-05-09 07:06:43 +02:00
|
|
|
if wizard.required && !wizard.completed? && wizard.permitted?
|
2017-11-01 05:21:14 +01:00
|
|
|
return render json: { error: I18n.t('wizard.no_skip') }
|
|
|
|
end
|
|
|
|
|
2022-06-15 08:36:40 +02:00
|
|
|
result = { success: 'OK' }
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2022-01-31 10:18:04 +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
|
|
|
|
2022-01-31 10:18:04 +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
|
|
|
|
@wizard ||= begin
|
|
|
|
builder = CustomWizard::Builder.new(params[:wizard_id].underscore, current_user)
|
|
|
|
return nil unless builder.present?
|
|
|
|
opts = {}
|
|
|
|
opts[:reset] = params[:reset]
|
|
|
|
builder.build(opts, params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
private
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
def ensure_plugin_enabled
|
|
|
|
unless SiteSetting.custom_wizard_enabled
|
|
|
|
redirect_to path("/")
|
|
|
|
end
|
|
|
|
end
|
2017-09-23 04:34:07 +02:00
|
|
|
end
|