A platform for community discussion. Free, open, simple.
FIX: Let users delete topics.
Bianca Nenciu034b8a7ecc40
diff --git a/lib/guardian/topic_guardian.rb b/lib/guardian/topic_guardian.rbindex e58b158955b..d001ab5909c 100644--- a/lib/guardian/topic_guardian.rb+++ b/lib/guardian/topic_guardian.rb@@ -95,7 +95,7 @@ module TopicGuardiandef can_delete_topic?(topic)!topic.trashed? &&- (is_staff? || (topic.posts_count <= 1 && topic.created_at && topic.created_at > 24.hours.ago)) &&+ (is_staff? || (is_my_own?(topic) && topic.posts_count <= 1 && topic.created_at && topic.created_at > 24.hours.ago)) &&!topic.is_category_topic? &&!Discourse.static_doc_topic_ids.include?(topic.id)enddiff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rbindex 48d033402fa..9fa878dd2b1 100644--- a/spec/components/guardian_spec.rb+++ b/spec/components/guardian_spec.rb@@ -1747,6 +1747,24 @@ describe Guardian doSiteSetting.tos_topic_id = tos_topic.idexpect(Guardian.new(admin).can_delete?(tos_topic)).to be_falseyend++ it "returns true for own topics" do+ topic.update_attribute(:posts_count, 1)+ topic.update_attribute(:created_at, Time.zone.now)+ expect(Guardian.new(topic.user).can_delete?(topic)).to be_truthy+ end++ it "returns false if delete their own topics" do+ topic.update_attribute(:posts_count, 2)+ topic.update_attribute(:created_at, Time.zone.now)+ expect(Guardian.new(topic.user).can_delete?(topic)).to be_falsey+ end++ it "returns false if delete their own topics" do+ topic.update_attribute(:posts_count, 1)+ topic.update_attribute(:created_at, 48.hours.ago)+ expect(Guardian.new(topic.user).can_delete?(topic)).to be_falsey+ endendcontext 'a Post' do@@ -1774,13 +1792,8 @@ describe Guardian doexpect(Guardian.new(Fabricate(:user)).can_delete?(post)).to be_falseyend- it "returns true when it's the OP" do- post.update!(post_number: 1)- expect(Guardian.new(moderator).can_delete?(post)).to be_falsey- end-it "returns false when it's the OP, even as a moderator if there are at least two posts" do- post.update!(post_number: 1)+ post.update_attribute(:post_number, 1)Fabricate(:post, topic: post.topic)expect(Guardian.new(moderator).can_delete?(post)).to be_falseyend