FIX: Ensure that login does not fail for users with invite records (#15647)

In the unlikely, but possible, scenario where a user has no email_tokens, and has an invite record for their email address, login would fail. This commit fixes the `Invite` `user_doesnt_already_exist` validation so that it only applies to new invites, or when changing the email address.

This regressed in d8fe0f4199 (based on `git bisect`)
This commit is contained in:
David Taylor
2022-01-20 10:54:38 +00:00
committed by GitHub
parent 5b7bddf966
commit 820564826e
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ class Invite < ActiveRecord::Base
validates :email, email: true, allow_blank: true
validate :ensure_max_redemptions_allowed
validate :valid_domain, if: :will_save_change_to_domain?
validate :user_doesnt_already_exist
validate :user_doesnt_already_exist, if: :will_save_change_to_email?
before_create do
self.invite_key ||= SecureRandom.base58(10)