From 4d50d0d10915dd6bdcabc5ee400a0212a7df7ac1 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 9 Jun 2014 11:03:10 -0400 Subject: [PATCH] FIX: admins should be able to create topics, even if min_trust_to_create_topic is higher than their trust level --- lib/guardian/topic_guardian.rb | 7 ++++--- spec/components/guardian_spec.rb | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/guardian/topic_guardian.rb b/lib/guardian/topic_guardian.rb index ed0d8ad9053..f691942bc8d 100644 --- a/lib/guardian/topic_guardian.rb +++ b/lib/guardian/topic_guardian.rb @@ -7,9 +7,10 @@ module TopicGuardian # Creating Methods def can_create_topic?(parent) - user && - user.trust_level >= SiteSetting.min_trust_to_create_topic.to_i && - can_create_post?(parent) + is_admin? || + (user && + user.trust_level >= SiteSetting.min_trust_to_create_topic.to_i && + can_create_post?(parent)) end def can_create_topic_on_category?(category) diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 2866cb1311a..e6e4e95fdca 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -414,6 +414,7 @@ describe Guardian do 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: 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