FIX: Allow a single invite per email address (#11855)

This commit is contained in:
Bianca Nenciu 2021-01-28 13:38:36 +02:00 committed by GitHub
parent 8881ae4af4
commit 80f85167be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -94,8 +94,7 @@ class InvitesController < ApplicationController
guardian.ensure_can_invite_to_forum!(groups)
group_ids = groups.map(&:id)
invite_exists = Invite.exists?(email: params[:email], invited_by_id: current_user.id)
if invite_exists && !guardian.can_send_multiple_invites?(current_user)
if Invite.exists?(email: params[:email])
return render json: failed_json, status: 422
end

View File

@ -145,11 +145,11 @@ describe InvitesController do
expect(Invite.find_by(email: email).invited_groups.count).to eq(1)
end
it "allows admin to send multiple invites to same email" do
it "does not allow admins to send multiple invites to same email" do
user = sign_in(admin)
invite = Invite.invite_by_email("invite@example.com", user)
post "/invites.json", params: { email: invite.email }
expect(response.status).to eq(200)
expect(response.status).to eq(422)
end
it "responds with error message in case of validation failure" do