diff options
-rw-r--r-- | app/models/user.rb | 14 | ||||
-rw-r--r-- | app/views/devise/mailer/confirmation_instructions.html.haml | 5 | ||||
-rw-r--r-- | app/views/devise/mailer/confirmation_instructions.text.erb | 6 | ||||
-rw-r--r-- | config/routes/user.rb | 2 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 6 |
5 files changed, 15 insertions, 18 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index cdc7c8ad84a..5e1355662b6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/devise/mailer/confirmation_instructions.html.haml b/app/views/devise/mailer/confirmation_instructions.html.haml index a0fb687e152..d2685140913 100644 --- a/app/views/devise/mailer/confirmation_instructions.html.haml +++ b/app/views/devise/mailer/confirmation_instructions.html.haml @@ -1,4 +1 @@ -- 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 diff --git a/app/views/devise/mailer/confirmation_instructions.text.erb b/app/views/devise/mailer/confirmation_instructions.text.erb index 057bb0b23f9..05fddddf415 100644 --- a/app/views/devise/mailer/confirmation_instructions.text.erb +++ b/app/views/devise/mailer/confirmation_instructions.text.erb @@ -1,5 +1 @@ -<% 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 diff --git a/config/routes/user.rb b/config/routes/user.rb index c4b34402068..8ee79e96836 100644 --- a/config/routes/user.rb +++ b/config/routes/user.rb @@ -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', diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e047027adab..08f58e6d069 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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 |