Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

fix(account): keep email visibility hints accurate and readable

Guido Boykef8a87fa195ea
diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb
index c2ded6e..1173a38 100644
--- a/app/views/devise/registrations/edit.html.erb
+++ b/app/views/devise/registrations/edit.html.erb
@@ -53,10 +53,10 @@
<%= t('views.devise.registrations.edit.email_change_hint') %>
</small>
<% end %>
- <%# Who else sees this field is the member's choice (User::EmailDisplay),
- made on the profile page: said here, where the address stands. %>
- <small class="mt-1 block text-xs text-cream-700 dark:text-gray-300 leading-snug" data-shown-email-hint>
- <%= t("views.devise.registrations.edit.shown_email.#{resource.email_visibility}", email: resource.contact_email) %>
+ <%# Devise re-renders an unsaved resource after a rejected update.
+ The hint must describe the saved user, not the submitted address. %>
+ <small class="mt-1 block break-words text-xs text-cream-700 dark:text-gray-300 leading-snug" data-shown-email-hint>
+ <%= t("views.devise.registrations.edit.shown_email.#{current_user.email_visibility}", email: current_user.shown_email) %>
<%= link_to t('views.devise.registrations.edit.shown_email.change'), display_user_preferences_path, class: 'underline' %>
</small>
</div>
diff --git a/config/locales/views.de.yml b/config/locales/views.de.yml
index d283683..2c8d699 100644
--- a/config/locales/views.de.yml
+++ b/config/locales/views.de.yml
@@ -1079,7 +1079,7 @@ de:
last_name: Nachname
email_change_hint: Eine neue Adresse wird erst aktiv, wenn du den Bestätigungslink darin anklickst. Bis dahin gilt die bisherige.
shown_email:
- login: Andere in deinen Organisationen sehen diese Adresse.
+ login: "Andere in deinen Organisationen sehen %{email}."
contact: "Andere in deinen Organisationen sehen stattdessen %{email}."
none: Andere in deinen Organisationen sehen keine E-Mail von dir.
change: Im Profil ändern
diff --git a/config/locales/views.en.yml b/config/locales/views.en.yml
index d57a6b2..333a478 100644
--- a/config/locales/views.en.yml
+++ b/config/locales/views.en.yml
@@ -1077,7 +1077,7 @@ en:
last_name: Last name
email_change_hint: A new address only takes effect once you click the confirmation link sent to it. Until then the current one stays active.
shown_email:
- login: Others in your organisations see this address.
+ login: "Others in your organisations see %{email}."
contact: "Others in your organisations see %{email} instead."
none: Others in your organisations see no email of yours.
change: Change in your profile
diff --git a/spec/requests/users/registrations_shown_email_hint_spec.rb b/spec/requests/users/registrations_shown_email_hint_spec.rb
index 5f948ed..740c858 100644
--- a/spec/requests/users/registrations_shown_email_hint_spec.rb
+++ b/spec/requests/users/registrations_shown_email_hint_spec.rb
@@ -21,7 +21,8 @@ RSpec.describe 'Account page: who sees the email', type: :request do
it 'says that others see the login address, and links to the page that changes it' do
hint = hint_html
- expect(hint.text).to include(I18n.t('views.devise.registrations.edit.shown_email.login'))
+ expect(hint.text).to include(I18n.t('views.devise.registrations.edit.shown_email.login',
+ email: '[email protected]'))
expect(hint.at_css('a')['href']).to eq(display_user_preferences_path)
expect(hint.at_css('a').text).to eq(I18n.t('views.devise.registrations.edit.shown_email.change'))
end
@@ -47,6 +48,43 @@ RSpec.describe 'Account page: who sees the email', type: :request do
expect(hint.at_css('a')['href']).to eq(display_user_preferences_path)
end
+ %i[de en].each do |locale|
+ context "with a login email change in #{locale}" do
+ before { user.update!(language_preference: locale.to_s) }
+
+ it 'names the saved address when the submitted change is rejected' do
+ put user_registration_path, params: {
+ user: { email: '[email protected]', current_password: 'wrong-password' }
+ }
+
+ expect(response).to have_http_status(:unprocessable_content)
+ page = Nokogiri::HTML(response.body)
+ expect(page.at_css('input[name="user[email]"]')['value']).to eq('[email protected]')
+ expect(user.reload.shown_email).to eq('[email protected]')
+ expect(page.at_css('[data-shown-email-hint]').text).to include('[email protected]')
+ expect(page.at_css('[data-shown-email-hint]').text).not_to include('[email protected]')
+ end
+
+ it 'names the current address until the new address is confirmed' do
+ put user_registration_path, params: {
+ user: { email: '[email protected]', current_password: 'password123' }
+ }
+
+ expect(response).to have_http_status(:see_other)
+ expect(user.reload.unconfirmed_email).to eq('[email protected]')
+ expect(user.shown_email).to eq('[email protected]')
+ hint = hint_html
+ expect(hint.text).to include('[email protected]')
+ expect(hint.text).not_to include('[email protected]')
+
+ user.confirm
+
+ expect(user.reload.shown_email).to eq('[email protected]')
+ expect(hint_html.text).to include('[email protected]')
+ end
+ end
+ end
+
it 'has the hint in both languages' do
%i[de en].each do |locale|
%w[login contact none change].each do |key|