From 7977deb3bf90cf77177e2f3b0eea9e0adda1d1f0 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 9 Jul 2013 16:48:26 -0400 Subject: [PATCH] Don't allow editing of title and category of an archived topic --- lib/guardian.rb | 2 +- spec/components/guardian_spec.rb | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/guardian.rb b/lib/guardian.rb index 4a7589f875a..ad3ba547022 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -259,7 +259,7 @@ class Guardian end def can_edit_topic?(topic) - is_staff? || is_my_own?(topic) + !topic.archived && (is_staff? || is_my_own?(topic)) end # Deleting Methods diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index b28612b91f4..a5587cdc1c4 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -456,12 +456,24 @@ describe Guardian do Guardian.new(coding_horror).can_edit?(topic).should be_false end - it 'returns true as a moderator' do - Guardian.new(moderator).can_edit?(topic).should be_true + context 'not archived' do + it 'returns true as a moderator' do + Guardian.new(moderator).can_edit?(topic).should be_true + end + + it 'returns true as an admin' do + Guardian.new(admin).can_edit?(topic).should be_true + end end - it 'returns true as an admin' do - Guardian.new(admin).can_edit?(topic).should be_true + context 'archived' do + it 'returns false as a moderator' do + Guardian.new(moderator).can_edit?(build(:topic, user: user, archived: true)).should be_false + end + + it 'returns false as an admin' do + Guardian.new(admin).can_edit?(build(:topic, user: user, archived: true)).should be_false + end end end