A platform for community discussion. Free, open, simple.
FEATURE: Allow plugins to exclude wizard steps (#9275)
Mark VanLandinghamc14f6d4ceda5
diff --git a/lib/wizard.rb b/lib/wizard.rbindex a254d8935d8..f3340814440 100644--- a/lib/wizard.rb+++ b/lib/wizard.rb@@ -5,6 +5,8 @@ class Wizardattr_reader :steps, :userattr_accessor :max_topics_to_require_completion+ @@excluded_steps = []+def initialize(user)@steps = []@user = user@@ -17,6 +19,8 @@ class Wizardenddef append_step(step)+ return if @@excluded_steps.include?(step)+step = create_step(step) if step.is_a?(String)yield step if block_given?@@ -36,6 +40,10 @@ class Wizardendend+ def self.exclude_step(step)+ @@excluded_steps << step+ end+def steps_with_fields@steps_with_fields ||= @steps.select(&:has_fields?)enddiff --git a/spec/components/wizard/wizard_spec.rb b/spec/components/wizard/wizard_spec.rbindex bf5490adefd..0faef408294 100644--- a/spec/components/wizard/wizard_spec.rb+++ b/spec/components/wizard/wizard_spec.rb@@ -61,6 +61,26 @@ describe Wizard doendend+ describe ".exclude_step" do+ let(:user) { Fabricate.build(:moderator) }+ let(:wizard) { Wizard.new(user) }++ it 'excludes steps even if they are added via append_step' do+ wizard.append_step('first') do |step|+ step.add_field(id: 'another_element', type: 'text')+ end++ Wizard.exclude_step("random-step123")++ wizard.append_step('random-step123') do |step|+ step.add_field(id: 'another_element', type: 'text')+ end+ wizard.append_step('finished')++ expect(wizard.steps.map(&:id)).to eq(['first', 'finished'])+ end+ end+describe "completed?" dolet(:user) { Fabricate.build(:moderator) }let(:wizard) { Wizard.new(user) }