mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:52:45 +08:00
FIX: auto-closing attribution when a TL4 user auto-closes a topic
This commit is contained in:
parent
27d78332c4
commit
10b5032188
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user