diff --git a/app/models/topic.rb b/app/models/topic.rb index d37e93d5853..d8572832e08 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -797,10 +797,10 @@ class Topic < ActiveRecord::Base else self.auto_close_started_at ||= Time.zone.now end - if by_user.try(:staff?) + if by_user.try(:staff?) || by_user.try(:trust_level) == TrustLevel[4] self.auto_close_user = by_user else - self.auto_close_user ||= (self.user.staff? ? self.user : Discourse.system_user) + self.auto_close_user ||= (self.user.staff? || self.user.trust_level == TrustLevel[4] ? self.user : Discourse.system_user) end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index d78d7369fbc..b47c8c0332a 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1078,6 +1078,7 @@ describe Topic do let(:topic) { Fabricate.build(:topic) } let(:closing_topic) { Fabricate.build(:topic, auto_close_hours: 5, auto_close_at: 5.hours.from_now, auto_close_started_at: 5.hours.from_now) } let(:admin) { Fabricate.build(:user, id: 123) } + let(:trust_level_4) { Fabricate.build(:trust_level_4) } before { Discourse.stubs(:system_user).returns(admin) } @@ -1131,17 +1132,22 @@ describe Topic do end end - it 'sets auto_close_user to given user if it is a staff user' do + it 'sets auto_close_user to given user if it is a staff or TL4 user' do topic.set_auto_close(3, admin) expect(topic.auto_close_user_id).to eq(admin.id) end - it 'sets auto_close_user to system user if given user is not staff' do + it 'sets auto_close_user to given user if it is a TL4 user' do + topic.set_auto_close(3, trust_level_4) + expect(topic.auto_close_user_id).to eq(trust_level_4.id) + end + + it 'sets auto_close_user to system user if given user is not staff or a TL4 user' do topic.set_auto_close(3, Fabricate.build(:user, id: 444)) expect(topic.auto_close_user_id).to eq(admin.id) end - it 'sets auto_close_user to system_user if user is not given and topic creator is not staff' do + it 'sets auto_close_user to system user if user is not given and topic creator is not staff nor TL4 user' do topic.set_auto_close(3) expect(topic.auto_close_user_id).to eq(admin.id) end @@ -1152,6 +1158,12 @@ describe Topic do expect(staff_topic.auto_close_user_id).to eq(999) end + it 'sets auto_close_user to topic creator if it is a TL4 user' do + tl4_topic = Fabricate.build(:topic, user: Fabricate.build(:trust_level_4, id: 998)) + tl4_topic.set_auto_close(3) + expect(tl4_topic.auto_close_user_id).to eq(998) + end + it 'clears auto_close_at if arg is nil' do closing_topic.set_auto_close(nil) expect(closing_topic.auto_close_at).to be_nil