Commit 09726bdf authored by Brett Walker's avatar Brett Walker

small cleanup changes based on feedback

parent 30e3a49e
...@@ -810,6 +810,10 @@ class User < ActiveRecord::Base ...@@ -810,6 +810,10 @@ class User < ActiveRecord::Base
avatar_path(args) || GravatarService.new.execute(email, size, scale, username: username) avatar_path(args) || GravatarService.new.execute(email, size, scale, username: username)
end end
def primary_email_verified?
confirmed? && !temp_oauth_email?
end
def all_emails def all_emails
all_emails = [] all_emails = []
all_emails << email unless temp_oauth_email? all_emails << email unless temp_oauth_email?
...@@ -817,15 +821,15 @@ class User < ActiveRecord::Base ...@@ -817,15 +821,15 @@ class User < ActiveRecord::Base
all_emails all_emails
end end
def all_verified_emails def verified_emails
verified_emails = [] verified_emails = []
verified_emails << email if confirmed? && !temp_oauth_email? verified_emails << email if primary_email_verified?
verified_emails.concat(emails.select {|e| e.confirmed?}.map(&:email)) verified_emails.concat(emails.where.not(confirmed_at: nil).pluck(:email))
verified_emails verified_emails
end end
def verified_email?(email) def verified_email?(check_email)
all_verified_emails.include?(email) (email == check_email && primary_email_verified?) || verified_emails.include?(check_email)
end end
def hook_attrs def hook_attrs
......
- if @resource.is_a?(User) = render partial: "confirmation_instructions_#{@resource.is_a?(User) ? 'account' : 'secondary'}"
= render partial: 'confirmation_instructions_account' \ No newline at end of file
- else
= render partial: 'confirmation_instructions_secondary'
<% if @resource.is_a?(User) %> <%= render partial: "confirmation_instructions_#{@resource.is_a?(User) ? 'account' : 'secondary'}" %>
<%= render partial: 'confirmation_instructions_account' %> \ No newline at end of file
<% else %>
<%= render partial: 'confirmation_instructions_secondary' %>
<% end %>
...@@ -12,7 +12,7 @@ devise_scope :user do ...@@ -12,7 +12,7 @@ devise_scope :user do
end end
# for secondary email confirmations # for secondary email confirmations
devise_for :emails, controllers: { confirmations: :confirmations } devise_for :emails, controllers: { confirmations: :confirmations }
scope(constraints: { username: Gitlab::PathRegex.root_namespace_route_regex }) do scope(constraints: { username: Gitlab::PathRegex.root_namespace_route_regex }) do
scope(path: 'users/:username', scope(path: 'users/:username',
......
...@@ -1100,18 +1100,18 @@ describe User do ...@@ -1100,18 +1100,18 @@ describe User do
email_confirmed = create :email, user: user, confirmed_at: Time.now email_confirmed = create :email, user: user, confirmed_at: Time.now
email_unconfirmed = create :email, user: user email_unconfirmed = create :email, user: user
user.reload user.reload
expect(user.all_emails).to eq([user.email, email_unconfirmed.email, email_confirmed.email]) expect(user.all_emails).to match_array([user.email, email_unconfirmed.email, email_confirmed.email])
end end
end end
describe '#all_verified_emails' do describe '#verified_emails' do
let(:user) { create(:user) } let(:user) { create(:user) }
it 'returns only confirmed emails' do it 'returns only confirmed emails' do
email_confirmed = create :email, user: user, confirmed_at: Time.now email_confirmed = create :email, user: user, confirmed_at: Time.now
email_unconfirmed = create :email, user: user email_unconfirmed = create :email, user: user
user.reload user.reload
expect(user.all_verified_emails).to eq([user.email, email_confirmed.email]) expect(user.verified_emails).to match_array([user.email, email_confirmed.email])
end end
end end
......
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