Skip to content

Commit

Permalink
Fix duplicate invites (#1437)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Pigford <[email protected]>
  • Loading branch information
tonyvince and Shpigford authored Nov 8, 2024
1 parent a113d57 commit b3ef995
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Invitation < ApplicationRecord
validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :role, presence: true, inclusion: { in: %w[admin member] }
validates :token, presence: true, uniqueness: true
validates_uniqueness_of :email, scope: :family_id, message: "has already been invited to this family"
validate :inviter_is_admin

before_validation :generate_token, on: :create
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUniqueEmailIndexToInvitations < ActiveRecord::Migration[7.2]
def change
add_index :invitations, [ :email, :family_id ], unique: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b3ef995

Please sign in to comment.