Commit 92bfb3c5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'if-ce-54109-fix_user_by_any_email' into 'master'

User#find_by_any_email to respect confirmed flag on secondary emails

See merge request gitlab-org/gitlab-ce!23181
parents 397fd09a a937eabe
...@@ -363,7 +363,7 @@ class User < ActiveRecord::Base ...@@ -363,7 +363,7 @@ class User < ActiveRecord::Base
from_users = from_users.confirmed if confirmed from_users = from_users.confirmed if confirmed
from_emails = joins(:emails).where(emails: { email: emails }) from_emails = joins(:emails).where(emails: { email: emails })
from_emails = from_emails.confirmed if confirmed from_emails = from_emails.confirmed.merge(Email.confirmed) if confirmed
items = [from_users, from_emails] items = [from_users, from_emails]
......
---
title: Respect confirmed flag on secondary emails
merge_request: 23181
author:
type: fixed
...@@ -1137,12 +1137,38 @@ describe User do ...@@ -1137,12 +1137,38 @@ describe User do
expect(described_class.find_by_any_email(user.email.upcase, confirmed: true)).to eq user expect(described_class.find_by_any_email(user.email.upcase, confirmed: true)).to eq user
end end
it 'finds by secondary email' do context 'finds by secondary email' do
email = create(:email, email: 'foo@example.com') let(:user) { email.user }
user = email.user
expect(described_class.find_by_any_email(email.email)).to eq user context 'primary email confirmed' do
expect(described_class.find_by_any_email(email.email, confirmed: true)).to eq user context 'secondary email confirmed' do
let!(:email) { create(:email, :confirmed, email: 'foo@example.com') }
it 'finds user respecting the confirmed flag' do
expect(described_class.find_by_any_email(email.email)).to eq user
expect(described_class.find_by_any_email(email.email, confirmed: true)).to eq user
end
end
context 'secondary email not confirmed' do
let!(:email) { create(:email, email: 'foo@example.com') }
it 'finds user respecting the confirmed flag' do
expect(described_class.find_by_any_email(email.email)).to eq user
expect(described_class.find_by_any_email(email.email, confirmed: true)).to be_nil
end
end
end
context 'primary email not confirmed' do
let(:user) { create(:user, confirmed_at: nil) }
let!(:email) { create(:email, :confirmed, user: user, email: 'foo@example.com') }
it 'finds user respecting the confirmed flag' do
expect(described_class.find_by_any_email(email.email)).to eq user
expect(described_class.find_by_any_email(email.email, confirmed: true)).to be_nil
end
end
end end
it 'returns nil when nothing found' do it 'returns nil when nothing found' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment