mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-18 20:59:39 +02:00
Fix duplicate invites (#1437)
Co-authored-by: Josh Pigford <josh@joshpigford.com>
This commit is contained in:
parent
a113d573d6
commit
b3ef995d1f
3 changed files with 8 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddUniqueEmailIndexToInvitations < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_index :invitations, [ :email, :family_id ], unique: true
|
||||
end
|
||||
end
|
3
db/schema.rb
generated
3
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2024_10_30_222235) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2024_11_08_150422) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -427,6 +427,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_30_222235) do
|
|||
t.datetime "expires_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["email", "family_id"], name: "index_invitations_on_email_and_family_id", unique: true
|
||||
t.index ["email"], name: "index_invitations_on_email"
|
||||
t.index ["family_id"], name: "index_invitations_on_family_id"
|
||||
t.index ["inviter_id"], name: "index_invitations_on_inviter_id"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue