Commit a8603723 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '197790-hide-private-commit-emails-in-notification-settings' into 'master'

Hide the private commit email on the notification settings

Closes #197790

See merge request gitlab-org/gitlab!25099
parents fcbaaaff 134b80c5
......@@ -1186,14 +1186,18 @@ class User < ApplicationRecord
Member.where(invite_email: verified_emails).invite
end
def all_emails
def all_emails(include_private_email: true)
all_emails = []
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
end
def all_public_emails
all_emails(include_private_email: false)
end
def verified_emails
verified_emails = []
verified_emails << email if primary_email_verified?
......
......@@ -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
= 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") },
control_class: 'select2 input-lg', disabled: email_change_disabled
- commit_email_link_url = help_page_path('user/profile/index', anchor: 'commit-email', target: '_blank')
......
- form = local_assigns.fetch(:form)
.form-group
= 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
= local_assigns.fetch(:help_text, nil)
......@@ -13,4 +13,4 @@
.table-section.section-30
= 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,18 +1943,28 @@ describe User, :do_not_mock_admin_mode do
describe '#all_emails' do
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
expect(user.reload.all_emails).to contain_exactly(
user.email,
user.private_commit_email,
email_unconfirmed.email,
email_confirmed.email
)
end
end
it 'returns all emails' do
email_confirmed = create :email, user: user, confirmed_at: Time.now
email_unconfirmed = create :email, user: user
user.reload
expect(user.all_emails).to contain_exactly(
user.email,
user.private_commit_email,
email_unconfirmed.email,
email_confirmed.email
)
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
......
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