From f97da59deed6c31734e98d5360510f9746a3a0be Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Wed, 24 May 2023 11:45:50 +0530 Subject: [PATCH] FIX: don't invite user when already a member of an allowed group. (#473) Otherwise, when an allowed group member is assigned to the PM it invites the user (which is unnecessary) and creates a public small post for the invite. --- lib/assigner.rb | 2 +- spec/lib/assigner_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/assigner.rb b/lib/assigner.rb index 48c1a99..e4d083c 100644 --- a/lib/assigner.rb +++ b/lib/assigner.rb @@ -266,7 +266,7 @@ class ::Assigner topic.invite_group(@assigned_by, assign_to) end else - unless topic.topic_allowed_users.exists?(user_id: assign_to.id) + unless topic.all_allowed_users.exists?(id: assign_to.id) guardian.ensure_can_invite_to!(topic) topic.invite(@assigned_by, assign_to.username) end diff --git a/spec/lib/assigner_spec.rb b/spec/lib/assigner_spec.rb index 06813f7..a26dc77 100644 --- a/spec/lib/assigner_spec.rb +++ b/spec/lib/assigner_spec.rb @@ -725,6 +725,14 @@ RSpec.describe Assigner do expect(topic.allowed_users).to include(user) end + it "doesn't invite user to the PM when already a member of an allowed group" do + user = Fabricate(:user) + assign_allowed_group.add(user) + topic.allowed_groups << assign_allowed_group + assigner.assign(user) + expect(topic.allowed_users).not_to include(user) + end + it "invites group to the PM" do group = Fabricate(