FEATURE: Allow plugins to exclude wizard steps (#9275)

This commit is contained in:
Mark VanLandingham 2020-03-25 11:36:42 -05:00 committed by GitHub
parent 0025806b7e
commit c14f6d4ced
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -5,6 +5,8 @@ class Wizard
attr_reader :steps, :user attr_reader :steps, :user
attr_accessor :max_topics_to_require_completion attr_accessor :max_topics_to_require_completion
@@excluded_steps = []
def initialize(user) def initialize(user)
@steps = [] @steps = []
@user = user @user = user
@ -17,6 +19,8 @@ class Wizard
end end
def append_step(step) def append_step(step)
return if @@excluded_steps.include?(step)
step = create_step(step) if step.is_a?(String) step = create_step(step) if step.is_a?(String)
yield step if block_given? yield step if block_given?
@ -36,6 +40,10 @@ class Wizard
end end
end end
def self.exclude_step(step)
@@excluded_steps << step
end
def steps_with_fields def steps_with_fields
@steps_with_fields ||= @steps.select(&:has_fields?) @steps_with_fields ||= @steps.select(&:has_fields?)
end end

View File

@ -61,6 +61,26 @@ describe Wizard do
end end
end end
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?" do describe "completed?" do
let(:user) { Fabricate.build(:moderator) } let(:user) { Fabricate.build(:moderator) }
let(:wizard) { Wizard.new(user) } let(:wizard) { Wizard.new(user) }