Prevent deleting the static page doc topics

This commit is contained in:
Neil Lalonde 2014-08-13 17:02:44 -04:00
parent 578d4ac5f4
commit 5caf72510c
2 changed files with 16 additions and 1 deletions

View file

@ -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)

View file

@ -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