diff --git a/lib/guardian/topic_guardian.rb b/lib/guardian/topic_guardian.rb index 8dc5b27c5..7c134998a 100644 --- a/lib/guardian/topic_guardian.rb +++ b/lib/guardian/topic_guardian.rb @@ -41,7 +41,8 @@ module TopicGuardian def can_delete_topic?(topic) !topic.trashed? && is_staff? && - !(Category.exists?(topic_id: topic.id)) + !(Category.exists?(topic_id: topic.id)) && + !Discourse.static_doc_topic_ids.include?(topic.id) end def can_reply_as_new_topic?(topic) diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 8512afd11..19e801cf8 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -1024,6 +1024,12 @@ describe Guardian do it 'returns true when an admin' do Guardian.new(admin).can_delete?(topic).should be_true end + + it 'returns false for static doc topics' do + tos_topic = Fabricate(:topic, user: Discourse.system_user) + SiteSetting.stubs(:tos_topic_id).returns(tos_topic.id) + Guardian.new(admin).can_delete?(tos_topic).should be_false + end end context 'a Post' do @@ -1064,6 +1070,14 @@ describe Guardian do Guardian.new(admin).can_delete?(post).should be_true end + it 'returns false when post is first in a static doc topic' do + tos_topic = Fabricate(:topic, user: Discourse.system_user) + SiteSetting.stubs(:tos_topic_id).returns(tos_topic.id) + post.update_attribute :post_number, 1 + post.update_attribute :topic_id, tos_topic.id + Guardian.new(admin).can_delete?(post).should be_false + end + context 'post is older than post_edit_time_limit' do let(:old_post) { build(:post, topic: topic, user: topic.user, post_number: 2, created_at: 6.minutes.ago) } before do