From 96c59c5b82afd471674f195718f4686300010eb4 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 8 May 2017 13:13:35 -0400 Subject: [PATCH] FIX: Don't notify or return flags on system users --- app/models/post_action.rb | 1 + lib/flag_query.rb | 1 + spec/components/flag_query_spec.rb | 11 +++++++++++ spec/models/post_action_spec.rb | 6 ++++++ 4 files changed, 19 insertions(+) diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 92310d30cde..f1fe1cc5290 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -57,6 +57,7 @@ class PostAction < ActiveRecord::Base .joins(post: :topic) .where('posts.deleted_at' => nil) .where('topics.deleted_at' => nil) + .where('posts.user_id > 0') .count('DISTINCT posts.id') $redis.set('posts_flagged_count', posts_flagged_count) diff --git a/lib/flag_query.rb b/lib/flag_query.rb index aed258c8274..11b21c8966f 100644 --- a/lib/flag_query.rb +++ b/lib/flag_query.rb @@ -114,6 +114,7 @@ module FlagQuery .joins("INNER JOIN posts ON posts.id = post_actions.post_id") .joins("INNER JOIN topics ON topics.id = posts.topic_id") .joins("LEFT JOIN users ON users.id = posts.user_id") + .where("posts.user_id > 0") if filter == "old" post_actions.where("post_actions.disagreed_at IS NOT NULL OR diff --git a/spec/components/flag_query_spec.rb b/spec/components/flag_query_spec.rb index 9609ab6acc3..cb2a3b5615c 100644 --- a/spec/components/flag_query_spec.rb +++ b/spec/components/flag_query_spec.rb @@ -6,6 +6,17 @@ describe FlagQuery do let(:codinghorror) { Fabricate(:coding_horror) } describe "flagged_posts_report" do + it "does not return flags on system posts" do + admin = Fabricate(:admin) + post = create_post(user: Discourse.system_user) + PostAction.act(codinghorror, post, PostActionType.types[:spam]) + posts, topics, users = FlagQuery.flagged_posts_report(admin, "") + + expect(posts).to be_blank + expect(topics).to be_blank + expect(users).to be_blank + end + it "operates correctly" do admin = Fabricate(:admin) moderator = Fabricate(:moderator) diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 9ed0e704991..4c94a2d0623 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -147,6 +147,12 @@ describe PostAction do expect(PostAction.flagged_posts_count).to eq(0) end + it "should ignore flags on non-human users" do + post = create_post(user: Discourse.system_user) + PostAction.act(codinghorror, post, PostActionType.types[:off_topic]) + expect(PostAction.flagged_posts_count).to eq(0) + end + it "should ignore validated flags" do post = create_post