DEV: Don't publish post messages to non-human users.

DEV: Don't publish post messages to non-human users.
From dcf9c6da59910d4b944e6ec8865f268ba4d0a7f2 Mon Sep 17 00:00:00 2001
From: Guo Xiang Tan <tgx_world@hotmail.com>
Date: Thu, 6 Dec 2018 08:20:36 +0800
Subject: [PATCH] DEV: Don't publish post messages to non-human users.


diff --git a/app/models/post.rb b/app/models/post.rb
index 6ea6765..42434c7 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -175,13 +175,15 @@ class Post < ActiveRecord::Base
 
     if Topic.visible_post_types.include?(post_type)
       if topic.private_message?
-        opts[:user_ids] = User.where("admin OR moderator").pluck(:id)
+        opts[:user_ids] = User.human_users.where("admin OR moderator").pluck(:id)
         opts[:user_ids] |= topic.allowed_users.pluck(:id)
       else
         opts[:group_ids] = topic.secure_group_ids
       end
     else
-      opts[:user_ids] = User.where("admin OR moderator OR id = ?", user_id).pluck(:id)
+      opts[:user_ids] = User.human_users
+        .where("admin OR moderator OR id = ?", user_id)
+        .pluck(:id)
     end
 
     MessageBus.publish(channel, message, opts)
diff --git a/plugins/poll/spec/controllers/polls_controller_spec.rb b/plugins/poll/spec/controllers/polls_controller_spec.rb
index fb4fe5e..6e08262 100644
--- a/plugins/poll/spec/controllers/polls_controller_spec.rb
+++ b/plugins/poll/spec/controllers/polls_controller_spec.rb
@@ -53,7 +53,7 @@ describe ::DiscoursePoll::PollsController do
       expect(json["vote"]).to eq(["5c24fc1df56d764b550ceae1b9319125"])
 
       expect(message.channel).to eq("/polls/#{poll.topic_id}")
-      expect(message.user_ids).to contain_exactly(-2, -1, user.id, user2.id)
+      expect(message.user_ids).to contain_exactly(user.id, user2.id)
       expect(message.group_ids).to eq(nil)
     end

GitHub

2 Likes