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.

Give the admin user twin the same email choice

Guido Boyke4f235cda569b
diff --git a/app/models/admin/user.rb b/app/models/admin/user.rb
index 029d38f..e52d1ab 100644
--- a/app/models/admin/user.rb
+++ b/app/models/admin/user.rb
@@ -148,6 +148,12 @@ module Admin
# it), while the concern's stays the raw unstripped pair.
include ::User::NameDisplay
+ # Which email the others see (twin-parity with ::User, same guard). The
+ # admin backend itself keeps showing the login address; the concern keeps
+ # the validations and the check-constraint values the same on both sides,
+ # so an admin save cannot store a choice the app would refuse.
+ include ::User::EmailDisplay
+
# Display methods
def full_name
return email.split('@').first if first_name.blank? && last_name.blank?
diff --git a/app/views/user_preferences/display.html.erb b/app/views/user_preferences/display.html.erb
index 8529c48..09f105c 100644
--- a/app/views/user_preferences/display.html.erb
+++ b/app/views/user_preferences/display.html.erb
@@ -80,7 +80,7 @@
<% User::EmailDisplay::EMAIL_VISIBILITIES.each do |choice| %>
<label class="flex items-center gap-3 rounded border border-cream-300 bg-surface-raised px-4 py-3 cursor-pointer hover:border-ink transition-all">
<%= radio_button_tag 'user[email_visibility]', choice, @user.email_visibility == choice %>
- <span class="text-sm text-cream-900"><%= t("user_preferences.edit.display.email_visibility.#{choice}", email: @user.email) %></span>
+ <span class="text-sm text-cream-900"><%= t("user_preferences.edit.display.email_visibility.#{choice}", email: current_user.email) %></span>
</label>
<% end %>
</div>
diff --git a/spec/models/admin/user_spec.rb b/spec/models/admin/user_spec.rb
index d602d4d..a6e2b7e 100644
--- a/spec/models/admin/user_spec.rb
+++ b/spec/models/admin/user_spec.rb
@@ -305,6 +305,24 @@ RSpec.describe Admin::User, type: :model do
user = build(:admin_user, first_name: '', last_name: '', email: '[email protected]')
expect(user.display_name).to eq('test')
end
+
+ # The admin backend keeps the login address, whatever a member shows to
+ # others (User::EmailDisplay); the admin full_name shadow decides it.
+ it 'keeps the login address prefix for a nameless member who hides it' do
+ user = build(:admin_user, first_name: '', last_name: '', email: '[email protected]', email_visibility: 'none')
+ expect(user.display_name).to eq('test')
+ end
+ end
+
+ describe 'which email the others see (twin of ::User)' do
+ it 'answers shown_email like ::User and refuses the same values' do
+ user = build(:admin_user, email: '[email protected]', email_visibility: 'contact', contact_email: '[email protected]')
+ expect(user.shown_email).to eq('[email protected]')
+
+ user.email_visibility = 'public'
+ expect(user).not_to be_valid
+ expect(user.errors.details[:email_visibility]).to include(a_hash_including(error: :inclusion))
+ end
end
describe '#status_text' do