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