Commit 6b07127a authored by Dan Jensen's avatar Dan Jensen

Add default option to notification_email input

The User#notification_email attribute is assumed to be the primary
email when not set. Historically the notification preferences form has
automatically set an input value of the current primary email. However,
recent refactoring has made this problematic. The notification_email is
no longer proactively set in the database to match the primary email.
Instead, we now make default assumptions in the code, and want to rely
on user input for database values. Toward that goal, this introduces a
new default option to the notification_email input. It is a blank
option, meaning the default assumption in the code will be used (the
primary email). Now the notification_email value will not be set in
the database unless the user provides input requesting that.

Changelog: fixed
parent bde04273
- form = local_assigns.fetch(:form)
.form-group
= form.label :notification_email, class: "label-bold"
= form.select :notification_email, @user.public_verified_emails, { include_blank: false }, class: "select2", disabled: local_assigns.fetch(:email_change_disabled, nil)
= form.select :notification_email, @user.public_verified_emails, { include_blank: _('Use primary email (%{email})') % { email: @user.email }, selected: @user.read_attribute(:notification_email) }, class: "select2", disabled: local_assigns.fetch(:email_change_disabled, nil)
.help-block
= local_assigns.fetch(:help_text, nil)
.form-group
......
......@@ -70,6 +70,7 @@ Your **Global notification settings** are the default settings unless you select
different values for a project or a group.
- **Notification email**: the email address your notifications are sent to.
Defaults to your primary email address.
- **Receive product marketing emails**: select this checkbox to receive
[periodic emails](#product-marketing-emails) about GitLab features.
- **Global notification level**: the default [notification level](#notification-levels)
......
......@@ -36265,6 +36265,9 @@ msgstr ""
msgid "Use one line per URI"
msgstr ""
msgid "Use primary email (%{email})"
msgstr ""
msgid "Use shortcuts"
msgstr ""
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'profiles/notifications/show' do
let(:groups) { GroupsFinder.new(user).execute.page(1) }
let(:user) { create(:user) }
before do
assign(:group_notifications, [])
assign(:project_notifications, [])
assign(:user, user)
assign(:user_groups, groups)
allow(controller).to receive(:current_user).and_return(user)
allow(view).to receive(:experiment_enabled?)
end
context 'when there is no database value for User#notification_email' do
let(:option_default) { _('Use primary email (%{email})') % { email: user.email } }
let(:option_primary_email) { user.email }
let(:options) { [option_default, option_primary_email] }
it 'displays the correct elements' do
render
expect(rendered).to have_select('user_notification_email', options: options, selected: nil)
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