FIX: admins should be able to create topics, even if min_trust_to_create_topic is higher than their trust level

This commit is contained in:
Neil Lalonde 2014-06-09 11:03:10 -04:00
parent b16c18e667
commit 4d50d0d109
2 changed files with 5 additions and 3 deletions

View File

@ -7,9 +7,10 @@ module TopicGuardian
# Creating Methods # Creating Methods
def can_create_topic?(parent) def can_create_topic?(parent)
user && is_admin? ||
user.trust_level >= SiteSetting.min_trust_to_create_topic.to_i && (user &&
can_create_post?(parent) user.trust_level >= SiteSetting.min_trust_to_create_topic.to_i &&
can_create_post?(parent))
end end
def can_create_topic_on_category?(category) def can_create_topic_on_category?(category)

View File

@ -414,6 +414,7 @@ describe Guardian do
SiteSetting.stubs(:min_trust_to_create_topic).returns(1) SiteSetting.stubs(:min_trust_to_create_topic).returns(1)
Guardian.new(build(:user, trust_level: 1)).can_create?(Topic,Fabricate(:category)).should be_true Guardian.new(build(:user, trust_level: 1)).can_create?(Topic,Fabricate(:category)).should be_true
Guardian.new(build(:user, trust_level: 2)).can_create?(Topic,Fabricate(:category)).should be_true Guardian.new(build(:user, trust_level: 2)).can_create?(Topic,Fabricate(:category)).should be_true
Guardian.new(build(:admin, trust_level: 0)).can_create?(Topic,Fabricate(:category)).should be_true
end end
end end