diff --git a/lib/user_comm_screener.rb b/lib/user_comm_screener.rb index 929c7c768d9..3612749991a 100644 --- a/lib/user_comm_screener.rb +++ b/lib/user_comm_screener.rb @@ -99,6 +99,7 @@ class UserCommScreener def initialize(acting_user: nil, acting_user_id: nil, target_user_ids:) raise ArgumentError if acting_user.blank? && acting_user_id.blank? @acting_user = acting_user.present? ? acting_user : User.find(acting_user_id) + target_user_ids = Array.wrap(target_user_ids) - [@acting_user.id] @target_users = User.where(id: target_user_ids).pluck(:id, :username).to_h @preferences = load_preference_map end diff --git a/spec/lib/user_comm_screener_spec.rb b/spec/lib/user_comm_screener_spec.rb index 542b39a5dcd..33483422cc0 100644 --- a/spec/lib/user_comm_screener_spec.rb +++ b/spec/lib/user_comm_screener_spec.rb @@ -31,6 +31,12 @@ RSpec.describe UserCommScreener do expect(screener.allowing_actor_communication).to eq([target_user1.id]) end + it "filters out the acting user from target_user_ids" do + acting_user = Fabricate(:user) + screener = described_class.new(acting_user: acting_user, target_user_ids: [target_user1.id, acting_user.id]) + expect(screener.allowing_actor_communication).to eq([target_user1.id]) + end + context "when the actor is not staff" do fab!(:acting_user) { Fabricate(:user) } fab!(:muted_user) { Fabricate(:muted_user, user: target_user1, muted_user: acting_user) }