FIX: process new invites when existing users are already group members (#11971)

If a list of email addresses is pasted into a group’s Add Members form
that has one or more email addresses of users who already belong to the
group and all other email addresses are for users who do not yet exist
on the forum then no invites were being sent. This commit ensures that
we send invites to new users.
This commit is contained in:
Arpit Jalan 2021-02-04 15:36:08 +05:30 committed by GitHub
parent 3da2e85855
commit 06225abe93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -351,7 +351,9 @@ class GroupsController < ApplicationController
end
usernames_already_in_group = group.users.where(id: users.map(&:id)).pluck(:username)
if usernames_already_in_group.present? && usernames_already_in_group.length == users.length
if usernames_already_in_group.present? &&
usernames_already_in_group.length == users.length &&
emails.blank?
render_json_error(I18n.t(
"groups.errors.member_already_exist",
username: usernames_already_in_group.sort.join(", "),

View File

@ -1246,6 +1246,23 @@ describe GroupsController do
expect(response.status).to eq(200)
end
it 'sends invites to new users and ignores existing users' do
user1.update!(username: 'john')
user2.update!(username: 'alice')
[user1, user2].each { |user| group.add(user) }
emails = ["something@gmail.com", "anotherone@yahoo.com"]
put "/groups/#{group.id}/members.json",
params: { user_emails: [user1.email, user2.email].join(","), emails: emails.join(",") }
expect(response.status).to eq(200)
expect(response.parsed_body["emails"]).to eq(emails)
emails.each do |email|
invite = Invite.find_by(email: email)
expect(invite.groups).to eq([group])
end
end
it 'displays warning when all members already exists' do
user1.update!(username: 'john')
user2.update!(username: 'alice')