Commit 134b80c5 authored by briankabiro's avatar briankabiro

Hide the private commit email on the notification settings

The private commit email is selectable in the notification settings.
This change removes the email from the list so that Gitlab doesn't
try to send emails to the non-existing addresses.
parent 12daefad
...@@ -1186,14 +1186,18 @@ class User < ApplicationRecord ...@@ -1186,14 +1186,18 @@ class User < ApplicationRecord
Member.where(invite_email: verified_emails).invite Member.where(invite_email: verified_emails).invite
end end
def all_emails def all_emails(include_private_email: true)
all_emails = [] all_emails = []
all_emails << email unless temp_oauth_email? all_emails << email unless temp_oauth_email?
all_emails << private_commit_email all_emails << private_commit_email if include_private_email
all_emails.concat(emails.map(&:email)) all_emails.concat(emails.map(&:email))
all_emails all_emails
end end
def all_public_emails
all_emails(include_private_email: false)
end
def verified_emails def verified_emails
verified_emails = [] verified_emails = []
verified_emails << email if primary_email_verified? verified_emails << email if primary_email_verified?
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
- help_text = email_change_disabled ? s_("Your account uses dedicated credentials for the \"%{group_name}\" group and can only be updated through SSO.") % { group_name: @user.managing_group.name } : read_only_help_text - help_text = email_change_disabled ? s_("Your account uses dedicated credentials for the \"%{group_name}\" group and can only be updated through SSO.") % { group_name: @user.managing_group.name } : read_only_help_text
= form.text_field :email, required: true, class: 'input-lg', value: (@user.email unless @user.temp_oauth_email?), help: help_text.html_safe, readonly: readonly || email_change_disabled = form.text_field :email, required: true, class: 'input-lg', value: (@user.email unless @user.temp_oauth_email?), help: help_text.html_safe, readonly: readonly || email_change_disabled
= form.select :public_email, options_for_select(@user.all_emails, selected: @user.public_email), = form.select :public_email, options_for_select(@user.all_public_emails, selected: @user.public_email),
{ help: s_("Profiles|This email will be displayed on your public profile"), include_blank: s_("Profiles|Do not show on profile") }, { help: s_("Profiles|This email will be displayed on your public profile"), include_blank: s_("Profiles|Do not show on profile") },
control_class: 'select2 input-lg', disabled: email_change_disabled control_class: 'select2 input-lg', disabled: email_change_disabled
- commit_email_link_url = help_page_path('user/profile/index', anchor: 'commit-email', target: '_blank') - commit_email_link_url = help_page_path('user/profile/index', anchor: 'commit-email', target: '_blank')
......
- form = local_assigns.fetch(:form) - form = local_assigns.fetch(:form)
.form-group .form-group
= form.label :notification_email, class: "label-bold" = form.label :notification_email, class: "label-bold"
= form.select :notification_email, @user.all_emails, { include_blank: false }, class: "select2", disabled: local_assigns.fetch(:email_change_disabled, nil) = form.select :notification_email, @user.all_public_emails, { include_blank: false }, class: "select2", disabled: local_assigns.fetch(:email_change_disabled, nil)
.help-block .help-block
= local_assigns.fetch(:help_text, nil) = local_assigns.fetch(:help_text, nil)
...@@ -13,4 +13,4 @@ ...@@ -13,4 +13,4 @@
.table-section.section-30 .table-section.section-30
= form_for setting, url: profile_notifications_group_path(group), method: :put, html: { class: 'update-notifications' } do |f| = form_for setting, url: profile_notifications_group_path(group), method: :put, html: { class: 'update-notifications' } do |f|
= f.select :notification_email, @user.all_emails, { include_blank: 'Global notification email' }, class: 'select2 js-group-notification-email' = f.select :notification_email, @user.all_public_emails, { include_blank: 'Global notification email' }, class: 'select2 js-group-notification-email'
---
title: Hide the private commit email in Notification email list
merge_request: 25099
author: briankabiro
type: changed
...@@ -1943,13 +1943,12 @@ describe User, :do_not_mock_admin_mode do ...@@ -1943,13 +1943,12 @@ describe User, :do_not_mock_admin_mode do
describe '#all_emails' do describe '#all_emails' do
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:email_confirmed) { create :email, user: user, confirmed_at: Time.now }
let!(:email_unconfirmed) { create :email, user: user }
context 'when `include_private_email` is true' do
it 'returns all emails' do it 'returns all emails' do
email_confirmed = create :email, user: user, confirmed_at: Time.now expect(user.reload.all_emails).to contain_exactly(
email_unconfirmed = create :email, user: user
user.reload
expect(user.all_emails).to contain_exactly(
user.email, user.email,
user.private_commit_email, user.private_commit_email,
email_unconfirmed.email, email_unconfirmed.email,
...@@ -1958,6 +1957,17 @@ describe User, :do_not_mock_admin_mode do ...@@ -1958,6 +1957,17 @@ describe User, :do_not_mock_admin_mode do
end end
end end
context 'when `include_private_email` is false' do
it 'does not include the private commit email' do
expect(user.reload.all_emails(include_private_email: false)).to contain_exactly(
user.email,
email_unconfirmed.email,
email_confirmed.email
)
end
end
end
describe '#verified_emails' do describe '#verified_emails' do
let(:user) { create(:user) } let(:user) { create(:user) }
......
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