diff options
author | Amit Rathi <amit@hypertrack.io> | 2018-11-19 23:12:52 +0530 |
---|---|---|
committer | Amit Rathi <amit@hypertrack.io> | 2018-11-19 23:12:52 +0530 |
commit | 1c7372ad56cf50b992a77bf0f09bee8fa29c2026 (patch) | |
tree | 2c40f9e265b7db9ea85900713d7e9d8b584732c3 /app/models/user.rb | |
parent | 9737cc8ab0f421213a5e36309741589beea88aa5 (diff) | |
parent | af1ed0e2bbabb72aff521aa2d67a4325dd94f711 (diff) | |
download | gitlab-ce-1c7372ad56cf50b992a77bf0f09bee8fa29c2026.tar.gz |
Merge branch 'master' into certmanager-temp
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index a400058e87e..01eba7e0426 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -349,20 +349,28 @@ class User < ActiveRecord::Base def find_by_any_email(email, confirmed: false) return unless email - downcased = email.downcase - - find_by_private_commit_email(downcased) || by_any_email(downcased, confirmed: confirmed).take + by_any_email(email, confirmed: confirmed).take end - # Returns a relation containing all the users for the given Email address - def by_any_email(email, confirmed: false) - users = where(email: email) - users = users.confirmed if confirmed + # Returns a relation containing all the users for the given email addresses + # + # @param emails [String, Array<String>] email addresses to check + # @param confirmed [Boolean] Only return users where the email is confirmed + def by_any_email(emails, confirmed: false) + emails = Array(emails).map(&:downcase) + + from_users = where(email: emails) + from_users = from_users.confirmed if confirmed - emails = joins(:emails).where(emails: { email: email }) - emails = emails.confirmed if confirmed + from_emails = joins(:emails).where(emails: { email: emails }) + from_emails = from_emails.confirmed if confirmed - from_union([users, emails]) + items = [from_users, from_emails] + + user_ids = Gitlab::PrivateCommitEmail.user_ids_for_emails(emails) + items << where(id: user_ids) if user_ids.present? + + from_union(items) end def find_by_private_commit_email(email) @@ -1031,6 +1039,7 @@ class User < ActiveRecord::Base def all_emails all_emails = [] all_emails << email unless temp_oauth_email? + all_emails << private_commit_email all_emails.concat(emails.map(&:email)) all_emails end @@ -1043,16 +1052,24 @@ class User < ActiveRecord::Base verified_emails end + def any_email?(check_email) + downcased = check_email.downcase + + # handle the outdated private commit email case + return true if persisted? && + id == Gitlab::PrivateCommitEmail.user_id_for_email(downcased) + + all_emails.include?(check_email.downcase) + end + def verified_email?(check_email) downcased = check_email.downcase - if email == downcased - primary_email_verified? - else - user_id = Gitlab::PrivateCommitEmail.user_id_for_email(downcased) + # handle the outdated private commit email case + return true if persisted? && + id == Gitlab::PrivateCommitEmail.user_id_for_email(downcased) - user_id == id || emails.confirmed.where(email: downcased).exists? - end + verified_emails.include?(check_email.downcase) end def hook_attrs |