mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
DEV: Add tl3_custom_promotions plugin modifier to tl3_promotions.rb (#29834)
* DEV: Add tl3_custom_promotions plugin modifier to tl3_promotions.rb * added tests * added tests for demotions * changed argument order in test
This commit is contained in:
parent
0295b4165c
commit
08440b0035
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
|
|
Loading…
Reference in New Issue
Block a user