mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 06:11:44 +08:00
FIX: delete duplicate invites
This commit is contained in:
parent
e5c3266c30
commit
4862a93804
|
@ -49,6 +49,7 @@ InviteRedeemer = Struct.new(:invite, :username, :name) do
|
||||||
approve_account_if_needed
|
approve_account_if_needed
|
||||||
notify_invitee
|
notify_invitee
|
||||||
send_password_instructions
|
send_password_instructions
|
||||||
|
delete_duplicate_invites
|
||||||
end
|
end
|
||||||
|
|
||||||
def invite_was_redeemed?
|
def invite_was_redeemed?
|
||||||
|
@ -114,4 +115,8 @@ InviteRedeemer = Struct.new(:invite, :username, :name) do
|
||||||
invite.invited_by.notifications.create(notification_type: Notification.types[:invitee_accepted],
|
invite.invited_by.notifications.create(notification_type: Notification.types[:invitee_accepted],
|
||||||
data: {display_username: invited_user.username}.to_json)
|
data: {display_username: invited_user.username}.to_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_duplicate_invites
|
||||||
|
Invite.where('invites.email = ? and invites.id != ?', invite.email, invite.id).delete_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -188,6 +188,18 @@ describe Invite do
|
||||||
expect(invite.redeem).to be_blank
|
expect(invite.redeem).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "deletes duplicate invites" do
|
||||||
|
let(:another_user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
it 'delete duplicate invite' do
|
||||||
|
another_invite = Fabricate(:invite, email: invite.email, invited_by: another_user)
|
||||||
|
invite.redeem
|
||||||
|
duplicate_invite = Invite.find_by(id: another_invite.id)
|
||||||
|
expect(duplicate_invite).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
context 'enqueues a job to email "set password" instructions' do
|
context 'enqueues a job to email "set password" instructions' do
|
||||||
|
|
||||||
it 'does not enqueue an email if sso is enabled' do
|
it 'does not enqueue an email if sso is enabled' do
|
||||||
|
@ -329,17 +341,14 @@ describe Invite do
|
||||||
it 'adds the user to the topic_users of the first topic' do
|
it 'adds the user to the topic_users of the first topic' do
|
||||||
expect(topic.allowed_users.include?(user)).to eq(true)
|
expect(topic.allowed_users.include?(user)).to eq(true)
|
||||||
expect(another_topic.allowed_users.include?(user)).to eq(true)
|
expect(another_topic.allowed_users.include?(user)).to eq(true)
|
||||||
another_invite.reload
|
duplicate_invite = Invite.find_by(id: another_invite.id)
|
||||||
expect(another_invite).not_to be_redeemed
|
expect(duplicate_invite).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'if they redeem the other invite afterwards' do
|
context 'if they redeem the other invite afterwards' do
|
||||||
|
|
||||||
it 'returns the same user' do
|
it 'wont redeem a duplicate invite' do
|
||||||
result = another_invite.redeem
|
expect(another_invite.redeem).to be_blank
|
||||||
expect(result).to eq(user)
|
|
||||||
another_invite.reload
|
|
||||||
expect(another_invite).to be_redeemed
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user