diff --git a/app/jobs/scheduled/tl3_promotions.rb b/app/jobs/scheduled/tl3_promotions.rb index 9de8f711d43..3d717d9f675 100644 --- a/app/jobs/scheduled/tl3_promotions.rb +++ b/app/jobs/scheduled/tl3_promotions.rb @@ -22,6 +22,19 @@ module Jobs # Don't demote too soon after being promoted next if u.on_tl3_grace_period? + modifier_applied, demoted_user_id = + DiscoursePluginRegistry.apply_modifier( + :tl3_custom_demotions, + false, + u, + demoted_user_ids, + ) + + if modifier_applied + demoted_user_ids << demoted_user_id + next + end + if Promotion.tl3_lost?(u) demoted_user_ids << u.id Promotion.new(u).change_trust_level!(TrustLevel[2]) @@ -29,6 +42,10 @@ module Jobs end end + override = + DiscoursePluginRegistry.apply_modifier(:tl3_custom_promotions, false, demoted_user_ids) + return override if override + # Promotions User .real diff --git a/spec/jobs/tl3_promotions_spec.rb b/spec/jobs/tl3_promotions_spec.rb index 28fc7439591..48e16a652f2 100644 --- a/spec/jobs/tl3_promotions_spec.rb +++ b/spec/jobs/tl3_promotions_spec.rb @@ -14,6 +14,10 @@ RSpec.describe Jobs::Tl3Promotions do subject(:run_job) { described_class.new.execute({}) } + let!(:plugin) { Plugin::Instance.new } + let!(:allow_block) { Proc.new { true } } + let!(:array_block) { Proc.new { [true, 1] } } + it "promotes tl2 user who qualifies for tl3" do tl2_user = Fabricate(:user, trust_level: TrustLevel[2]) create_qualifying_stats(tl2_user) @@ -43,6 +47,26 @@ RSpec.describe Jobs::Tl3Promotions do run_job end + it "allows plugins to control tl3_promotion's promotions" do + DiscoursePluginRegistry.register_modifier(plugin, :tl3_custom_promotions, &allow_block) + TrustLevel3Requirements.any_instance.stubs(:requirements_met?).never + tl2_user = Fabricate(:user, trust_level: TrustLevel[2]) + create_qualifying_stats(tl2_user) + run_job + ensure + DiscoursePluginRegistry.unregister_modifier(plugin, :tl3_custom_promotions, &allow_block) + end + + it "allows plugins to control tl3_promotion's demotions" do + DiscoursePluginRegistry.register_modifier(plugin, :tl3_custom_demotions, &array_block) + TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).never + Fabricate(:user, trust_level: TrustLevel[3]) + + run_job + ensure + DiscoursePluginRegistry.unregister_modifier(plugin, :tl3_custom_demotions, &array_block) + end + context "with tl3 user who doesn't qualify for tl3 anymore" do def create_leader_user user = Fabricate(:user, trust_level: TrustLevel[2])