Skip to content

Commit b3ef995

Browse files
tonyvinceShpigford
andauthored
Fix duplicate invites (#1437)
Co-authored-by: Josh Pigford <[email protected]>
1 parent a113d57 commit b3ef995

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

app/models/invitation.rb

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Invitation < ApplicationRecord
55
validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP }
66
validates :role, presence: true, inclusion: { in: %w[admin member] }
77
validates :token, presence: true, uniqueness: true
8+
validates_uniqueness_of :email, scope: :family_id, message: "has already been invited to this family"
89
validate :inviter_is_admin
910

1011
before_validation :generate_token, on: :create
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddUniqueEmailIndexToInvitations < ActiveRecord::Migration[7.2]
2+
def change
3+
add_index :invitations, [ :email, :family_id ], unique: true
4+
end
5+
end

db/schema.rb

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)