From 60908a94ece0e62e4ffb3fb619deb3e242079f67 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Thu, 27 Feb 2020 14:45:20 +0200 Subject: [PATCH] FIX: Skip 'invited' small action if user is in an invited group (#9056) Inviting a user that is already invited through a group used to generate a small action and a notification. This commit skips that small action. --- app/models/topic.rb | 4 +++- spec/models/topic_spec.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index ff4b7857087..7947900b133 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1441,7 +1441,9 @@ class Topic < ActiveRecord::Base Topic.transaction do rate_limit_topic_invitation(invited_by) topic_allowed_users.create!(user_id: target_user.id) unless topic_allowed_users.exists?(user_id: target_user.id) - add_small_action(invited_by, "invited_user", target_user.username) + + user_in_allowed_group = (user.group_ids & topic_allowed_groups.map(&:group_id)).present? + add_small_action(invited_by, "invited_user", target_user.username) if !user_in_allowed_group create_invite_notification!( target_user, diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index ec2956d6608..e882c3fd052 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -618,6 +618,15 @@ describe Topic do expect(Post.last.action_code).to eq("removed_user") end + it 'should not create a small action if user is already invited through a group' do + group = Fabricate(:group, users: [user, another_user]) + expect(topic.invite_group(user, group)).to eq(true) + + expect { topic.invite(user, another_user.username) } + .to change { Notification.count }.by(1) + .and change { Post.where(post_type: Post.types[:small_action]).count }.by(0) + end + context "from a muted user" do before { MutedUser.create!(user: another_user, muted_user: user) }