PERF: bypass wizard check after 15 topics are created

This commit is contained in:
Sam 2017-05-12 10:18:43 -04:00
parent 961dc0480d
commit 47ce674798
3 changed files with 32 additions and 2 deletions

View File

@ -1038,6 +1038,9 @@ developer:
wizard_enabled:
default: true
hidden: true
bypass_wizard_check:
default: false
hidden: true
embedding:
feed_polling_enabled:

View File

@ -4,12 +4,15 @@ require_dependency 'wizard/step_updater'
require_dependency 'wizard/builder'
class Wizard
attr_reader :steps, :user
attr_accessor :max_topics_to_require_completion
def initialize(user)
@steps = []
@user = user
@first_step = nil
@max_topics_to_require_completion = 15
end
def create_step(step_name)
@ -76,13 +79,20 @@ class Wizard
def requires_completion?
return false unless SiteSetting.wizard_enabled?
return false if SiteSetting.bypass_wizard_check?
first_admin = User.where(admin: true)
if Topic.limit(@max_topics_to_require_completion + 1).count > @max_topics_to_require_completion
SiteSetting.bypass_wizard_check = true
return false
end
first_admin_id = User.where(admin: true)
.where.not(id: Discourse.system_user.id)
.joins(:user_auth_tokens)
.order('user_auth_tokens.created_at')
.pluck(:id).first
if @user.present? && first_admin.first == @user && (Topic.count < 15)
if @user&.id && first_admin_id == @user.id
!Wizard::Builder.new(@user).build.completed?
else
false

View File

@ -120,6 +120,23 @@ describe Wizard do
expect(build_simple(admin).requires_completion?).to eq(false)
end
it "its false when the wizard is bypassed" do
SiteSetting.bypass_wizard_check = true
admin = Fabricate(:admin)
expect(build_simple(admin).requires_completion?).to eq(false)
end
it "its automatically bypasses after you reach topic limit" do
Fabricate(:topic)
admin = Fabricate(:admin)
wizard = build_simple(admin)
wizard.max_topics_to_require_completion = Topic.count-1
expect(wizard.requires_completion?).to eq(false)
expect(SiteSetting.bypass_wizard_check).to eq(true)
end
it "it's true for the first admin who logs in" do
admin = Fabricate(:admin)
second_admin = Fabricate(:admin)