FIX: do not allow creation of topic if there is no category available for posting (#7786)

This commit is contained in:
Arpit Jalan 2019-06-26 16:32:53 +05:30 committed by GitHub
parent 01de7e1444
commit 3c64dc3e7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -39,7 +39,8 @@ module TopicGuardian
is_staff? ||
(user &&
user.trust_level >= SiteSetting.min_trust_to_create_topic.to_i &&
can_create_post?(parent))
can_create_post?(parent) &&
Category.topic_create_allowed(self).limit(1).count == 1)
end
def can_create_topic_on_category?(category)

View File

@ -1668,6 +1668,40 @@ describe Guardian do
end
end
context "can_create_topic?" do
it 'returns true for staff user' do
expect(Guardian.new(moderator).can_create_topic?(topic)).to eq(true)
end
it 'returns false for user with insufficient trust level' do
SiteSetting.min_trust_to_create_topic = 3
expect(Guardian.new(user).can_create_topic?(topic)).to eq(false)
end
it 'returns true for user with sufficient trust level' do
SiteSetting.min_trust_to_create_topic = 3
expect(Guardian.new(trust_level_4).can_create_topic?(topic)).to eq(true)
end
it 'returns false when posting in "uncategorized" is disabled and there is no other category available for posting' do
SiteSetting.allow_uncategorized_topics = false
plain_category.set_permissions(group => :readonly)
plain_category.save
expect(Guardian.new(user).can_create_topic?(topic)).to eq(false)
end
it 'returns true when there is a category available for posting' do
SiteSetting.allow_uncategorized_topics = false
plain_category.set_permissions(group => :full)
plain_category.save
group.add(user)
group.save
expect(Guardian.new(user).can_create_topic?(topic)).to eq(true)
end
end
context 'can_move_posts?' do
it 'returns false with a nil object' do