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.

Let members choose which email the others see

Guido Boykeb0a32c8b4cb5
diff --git a/app/models/admin/user.rb b/app/models/admin/user.rb
index 708c9d9..029d38f 100644
--- a/app/models/admin/user.rb
+++ b/app/models/admin/user.rb
@@ -291,6 +291,8 @@ module Admin
remember_created_at: nil,
unconfirmed_email: nil,
confirmation_token: nil,
+ contact_email: nil,
+ email_visibility: 'none',
unlock_token: nil,
locked_at: nil,
failed_attempts: 0
diff --git a/app/models/user.rb b/app/models/user.rb
index ec9bab0..f9e11ac 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -82,6 +82,10 @@ class User < ApplicationRecord
# methods, no Devise interplay, so the include position is not load-bearing.
include User::NameDisplay
+ # Which email the others see (login address, contact address or none) --
+ # the single owner, see User::EmailDisplay.
+ include User::EmailDisplay
+
# Allowed per-user session-timeout values (minutes). DELIBERATELY defined on
# the User class, NOT inside User::Authenticatable: it is referenced externally
# as User::ALLOWED_SESSION_TIMEOUTS (app/views/user_preferences/session.html.erb).
diff --git a/app/models/user/deletion_lifecycle.rb b/app/models/user/deletion_lifecycle.rb
index 90aca5d..8e78ad7 100644
--- a/app/models/user/deletion_lifecycle.rb
+++ b/app/models/user/deletion_lifecycle.rb
@@ -86,6 +86,10 @@ class User < ApplicationRecord
self.remember_created_at = nil
self.unconfirmed_email = nil
self.confirmation_token = nil
+ # The contact address is the member's own data like the login address;
+ # an erased member shows no email at all (User::EmailDisplay).
+ self.contact_email = nil
+ self.email_visibility = 'none'
# :lockable belongs to the "credential/recovery fields" promised blank
# above; a live unlock token on an erased row is a credential like any
# other (survived both paths until 2026-08-24).
diff --git a/app/models/user/email_display.rb b/app/models/user/email_display.rb
new file mode 100644
index 0000000..453c194
--- /dev/null
+++ b/app/models/user/email_display.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+class User < ApplicationRecord
+ # === Which email the others see ===
+ # THE single owner of the email a member shows to other people inside an
+ # organisation: the people directory (list, lane, search, form), the members
+ # page, the assistant, MCP and REST cards, pickers and name fallbacks. The
+ # member chooses it in the display preferences:
+ #
+ # login - the address they sign in with (default; what everyone saw before)
+ # contact - a separate contact address (contact_email)
+ # none - no email at all
+ #
+ # NOT for signing in, Devise, mails Lalabase sends, the member's own view of
+ # their account (GET /api/v1/me) or the instance admin area: those keep
+ # `email`. Lalabase never mails to contact_email.
+ #
+ # The check constraint users_email_visibility_known is the second line behind
+ # the inclusion validation. Guard: spec/architecture/shown_email_guard_spec.rb.
+ module EmailDisplay
+ extend ActiveSupport::Concern
+
+ EMAIL_VISIBILITIES = %w[login contact none].freeze
+ MAX_CONTACT_EMAIL_LENGTH = 255
+
+ included do
+ normalizes :contact_email, with: ->(value) { value.to_s.strip.presence }
+
+ validates :email_visibility, inclusion: { in: EMAIL_VISIBILITIES }
+ validates :contact_email, presence: true, if: -> { email_visibility == 'contact' }
+ validates :contact_email, format: { with: URI::MailTo::EMAIL_REGEXP },
+ length: { maximum: MAX_CONTACT_EMAIL_LENGTH }, allow_nil: true
+
+ # The users whose SHOWN email contains `fragment` (case-insensitive, LIKE
+ # wildcards taken as text). A hidden login address never matches, so a
+ # search cannot confirm that an address belongs to a member.
+ scope :matching_shown_email, lambda { |fragment|
+ pattern = "%#{sanitize_sql_like(fragment.to_s.downcase)}%"
+ shows_login = where(email_visibility: 'login').where('LOWER(users.email) LIKE ?', pattern)
+ shows_login.or(where(email_visibility: 'contact').where('LOWER(users.contact_email) LIKE ?', pattern))
+ }
+ end
+
+ # The email others see, or nil when the member shows none. An unknown
+ # value (impossible past the constraint) shows nothing rather than the
+ # login address.
+ def shown_email
+ case email_visibility
+ when 'login' then email
+ when 'contact' then contact_email
+ end
+ end
+ end
+end
diff --git a/app/models/user/name_display.rb b/app/models/user/name_display.rb
index 0c1a2c0..1689ae8 100644
--- a/app/models/user/name_display.rb
+++ b/app/models/user/name_display.rb
@@ -61,10 +61,11 @@ class User < ApplicationRecord
private
- # Bit-identical to the historic User#display_name: stripped full name,
- # email local part when both name parts are blank.
+ # Stripped full name; without one, the local part of the email the member
+ # shows to others (User::EmailDisplay), never of a hidden login address.
+ # A member who shows no email and has no name reads as a neutral word.
def default_display_name
- full_name.strip.presence || email.split('@').first
+ full_name.strip.presence || shown_email&.split('@')&.first.presence || I18n.t('users.unnamed')
end
def name_initial(part)
diff --git a/app/services/user_data_exports/registry.rb b/app/services/user_data_exports/registry.rb
index 8e0958c..d38aafd 100644
--- a/app/services/user_data_exports/registry.rb
+++ b/app/services/user_data_exports/registry.rb
@@ -62,6 +62,7 @@ module UserDataExports
# ── global (ZIP root) ────────────────────────────────────────────────
source(key: :account, model: 'User', tenant_scoped: false,
attributes: %w[email first_name last_name language_preference timezone
+ email_visibility contact_email
session_timeout_minutes active terms_accepted_at created_at
scheduled_deletion_at deletion_canceled_at deletion_recommended],
scope: ->(user) { User.where(id: user.id) }),
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 58758e0..c3fb11a 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -131,10 +131,12 @@ de:
user:
active: Aktiv
avatar: Profilbild
+ contact_email: Kontakt-E-Mail
created_at: Erstellt am
current_password: Aktuelles Passwort
display_name: Anzeigename
email: E-Mail
+ email_visibility: Sichtbare E-Mail
first_name: Vorname
is_ai: KI-Benutzer
items_per_page_preference: Einträge pro Seite
diff --git a/config/locales/en.yml b/config/locales/en.yml
index bb7bef8..96c07c1 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -125,10 +125,12 @@ en:
user:
active: Active
avatar: Profile picture
+ contact_email: Contact email
created_at: Created at
current_password: Current password
display_name: Display name
email: Email
+ email_visibility: Visible email
first_name: First name
is_ai: AI User
items_per_page_preference: Items per page
diff --git a/config/locales/models.de.yml b/config/locales/models.de.yml
index 0706e40..05075c8 100644
--- a/config/locales/models.de.yml
+++ b/config/locales/models.de.yml
@@ -526,3 +526,6 @@ de:
status:
active: "Aktiv"
inactive: "Inaktiv"
+ users:
+ # A member with neither a name nor a shown email (User::NameDisplay).
+ unnamed: "Mitglied ohne Namen"
diff --git a/config/locales/models.en.yml b/config/locales/models.en.yml
index 06703af..9ea2c7b 100644
--- a/config/locales/models.en.yml
+++ b/config/locales/models.en.yml
@@ -516,3 +516,6 @@ en:
status:
active: "Active"
inactive: "Inactive"
+ users:
+ # A member with neither a name nor a shown email (User::NameDisplay).
+ unnamed: "Member without a name"
diff --git a/db/migrate/20261029150000_add_email_visibility_to_users.rb b/db/migrate/20261029150000_add_email_visibility_to_users.rb
new file mode 100644
index 0000000..b1b47c5
--- /dev/null
+++ b/db/migrate/20261029150000_add_email_visibility_to_users.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+# Which email the others see of a member (User::EmailDisplay): the login
+# address (default, what everyone saw before), a separate contact address, or
+# none. The check constraint is the second line behind the model validation.
+# A constant default on a new column is a metadata-only change in PostgreSQL,
+# so the users table is not rewritten.
+class AddEmailVisibilityToUsers < ActiveRecord::Migration[8.1]
+ def change
+ add_column :users, :email_visibility, :string, null: false, default: 'login'
+ add_column :users, :contact_email, :string
+ add_check_constraint :users, "email_visibility IN ('login', 'contact', 'none')",
+ name: 'users_email_visibility_known'
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 44373bf..7ab338e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.1].define(version: 2026_10_28_120000) do
+ActiveRecord::Schema[8.1].define(version: 2026_10_29_150000) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pgcrypto"
@@ -1935,6 +1935,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_10_28_120000) do
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
+ t.string "email_visibility", default: "login", null: false
+ t.string "contact_email"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["deleted_at"], name: "index_users_on_deleted_at"
t.index ["deletion_recommended"], name: "index_users_on_deletion_recommended"
@@ -1947,6 +1949,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_10_28_120000) do
t.index ["scheduled_deletion_at"], name: "index_users_on_scheduled_deletion_at"
t.index ["timezone"], name: "index_users_on_timezone"
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
+ t.check_constraint "email_visibility::text = ANY (ARRAY['login'::character varying, 'contact'::character varying, 'none'::character varying]::text[])", name: "users_email_visibility_known"
end
create_table "view_configurations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
diff --git a/spec/models/user/email_display_spec.rb b/spec/models/user/email_display_spec.rb
new file mode 100644
index 0000000..797ee40
--- /dev/null
+++ b/spec/models/user/email_display_spec.rb
@@ -0,0 +1,180 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+# Which email the others see (User::EmailDisplay). The member chooses it in the
+# display preferences: the login address (default), a contact address, or none.
+RSpec.describe User::EmailDisplay, :ci_guard, type: :model do
+ let(:user) { create(:user, email: '[email protected]') }
+
+ describe 'the choice' do
+ it 'starts at the login address when nothing was chosen' do
+ fresh = User.create!(email: '[email protected]', password: 'password123', first_name: 'Frida', last_name: 'Frisch')
+
+ expect(fresh.reload).to have_attributes(email_visibility: 'login', contact_email: nil)
+ end
+
+ User::EmailDisplay::EMAIL_VISIBILITIES.each do |visibility|
+ it "accepts #{visibility}" do
+ user.assign_attributes(email_visibility: visibility, contact_email: '[email protected]')
+
+ expect(user).to be_valid
+ end
+ end
+
+ it 'knows exactly three choices' do
+ expect(User::EmailDisplay::EMAIL_VISIBILITIES).to eq(%w[login contact none])
+ end
+
+ %w[public Login hidden].push('').each do |bad|
+ it "refuses #{bad.inspect}" do
+ user.email_visibility = bad
+
+ expect(user).not_to be_valid
+ expect(user.errors.details[:email_visibility]).to include(a_hash_including(error: :inclusion))
+ end
+ end
+
+ it 'refuses the contact choice without an address' do
+ user.assign_attributes(email_visibility: 'contact', contact_email: ' ')
+
+ expect(user).not_to be_valid
+ expect(user.errors.details[:contact_email]).to include(a_hash_including(error: :blank))
+ end
+ end
+
+ describe 'the contact address' do
+ it "accepts #{good}" do
+ user.contact_email = good
+
+ expect(user).to be_valid
+ end
+ end
+
+ ['team@', '@example.com', 'team example.com'].each do |bad|
+ it "refuses #{bad.inspect}" do
+ user.contact_email = bad
+
+ expect(user).not_to be_valid
+ expect(user.errors.details[:contact_email]).to include(a_hash_including(error: :invalid))
+ end
+ end
+
+ it 'stores a blank address as nil' do
+ user.update!(contact_email: ' ')
+
+ expect(user.reload.contact_email).to be_nil
+ end
+
+ it 'strips the address' do
+ user.update!(contact_email: ' [email protected] ')
+
+ expect(user.reload.contact_email).to eq('[email protected]')
+ end
+
+ it 'accepts an address at the limit and refuses one character more' do
+ # Domain labels stay at 63 characters or fewer, so the format accepts
+ # both addresses and only the length decides.
+ local = 'a' * 64
+ at_limit = "#{local}@#{'b' * 61}.#{'c' * 61}.#{'d' * 62}.com"
+ expect(at_limit.length).to eq(User::EmailDisplay::MAX_CONTACT_EMAIL_LENGTH)
+
+ user.contact_email = at_limit
+ expect(user).to be_valid
+
+ user.contact_email = "#{local}@#{'b' * 62}.#{'c' * 61}.#{'d' * 62}.com"
+ expect(user).not_to be_valid
+ expect(user.errors.details[:contact_email]).to include(a_hash_including(error: :too_long))
+ end
+
+ it 'keeps the address when the member switches back to the login address or to none' do
+ user.update!(email_visibility: 'contact', contact_email: '[email protected]')
+ user.update!(email_visibility: 'none')
+
+ expect(user.reload.contact_email).to eq('[email protected]')
+ end
+ end
+
+ describe '#shown_email' do
+ it 'is the login address by default' do
+ expect(user.shown_email).to eq('[email protected]')
+ end
+
+ it 'is the contact address when the member chose it' do
+ user.update!(email_visibility: 'contact', contact_email: '[email protected]')
+
+ expect(user.shown_email).to eq('[email protected]')
+ end
+
+ it 'is nil when the member chose none, also with a stored contact address' do
+ user.update!(email_visibility: 'none', contact_email: '[email protected]')
+
+ expect(user.shown_email).to be_nil
+ end
+
+ it 'is the login address for login, even with a stored contact address' do
+ user.update!(email_visibility: 'login', contact_email: '[email protected]')
+
+ expect(user.shown_email).to eq('[email protected]')
+ end
+ end
+
+ describe '.matching_shown_email' do
+ let!(:plain) { create(:user, email: '[email protected]') }
+ let!(:contact) { create(:user, email: '[email protected]', email_visibility: 'contact', contact_email: '[email protected]') }
+ let!(:hidden) { create(:user, email: '[email protected]', email_visibility: 'none') }
+
+ it 'finds the login address of a member who shows it' do
+ expect(User.matching_shown_email('plain@')).to contain_exactly(plain)
+ end
+
+ it 'finds the contact address, case-insensitive' do
+ expect(User.matching_shown_email('SHOWN@')).to contain_exactly(contact)
+ end
+
+ it 'never finds a hidden login address' do
+ expect(User.matching_shown_email('secret-login')).to be_empty
+ expect(User.matching_shown_email('hidden-login')).to be_empty
+ end
+
+ it 'treats LIKE wildcards as text' do
+ expect(User.matching_shown_email('%')).to be_empty
+ expect(User.matching_shown_email('_')).to be_empty
+ end
+ end
+
+ describe 'the database behind the model' do
+ it 'refuses an unknown choice past the validation' do
+ user.email_visibility = 'public'
+
+ expect { user.save!(validate: false) }.to raise_error(ActiveRecord::StatementInvalid, /users_email_visibility_known/)
+ end
+
+ it 'refuses a missing choice past the validation' do
+ expect { user.update_column(:email_visibility, nil) }.to raise_error(ActiveRecord::NotNullViolation)
+ end
+ end
+
+ describe 'the name when there is none' do
+ let(:nameless) { create(:user, email: '[email protected]', first_name: nil, last_name: nil) }
+
+ it 'takes the part before the @ of the login address while the member shows it' do
+ expect(nameless.display_name).to eq('secret-login')
+ end
+
+ it 'takes the part before the @ of the contact address when the member chose it' do
+ nameless.update!(email_visibility: 'contact', contact_email: '[email protected]')
+
+ expect(nameless.display_name).to eq('team')
+ end
+
+ it 'never takes the login address when the member hides it' do
+ nameless.update!(email_visibility: 'none')
+
+ expect(nameless.display_name).not_to include('secret')
+ expect(nameless.display_name).to eq(I18n.t('users.unnamed'))
+ expect(nameless.initials).not_to start_with('S')
+ end
+ end
+end
diff --git a/spec/models/user_erasure_path_parity_spec.rb b/spec/models/user_erasure_path_parity_spec.rb
index 10ef7b9..6b6ba06 100644
--- a/spec/models/user_erasure_path_parity_spec.rb
+++ b/spec/models/user_erasure_path_parity_spec.rb
@@ -350,7 +350,8 @@ RSpec.describe 'Account erasure path parity', type: :model do
{ first_name: 'Max', last_name: 'Mustermann', unconfirmed_email: '[email protected]',
confirmation_token: "pending-#{user.id}", reset_password_token: "reset-#{user.id}",
reset_password_sent_at: 1.hour.ago, remember_created_at: 1.day.ago,
- unlock_token: "unlock-#{user.id}", locked_at: 30.minutes.ago, failed_attempts: 3 }
+ unlock_token: "unlock-#{user.id}", locked_at: 30.minutes.ago, failed_attempts: 3,
+ email_visibility: 'contact', contact_email: '[email protected]' }
end
before do
@@ -389,7 +390,9 @@ RSpec.describe 'Account erasure path parity', type: :model do
rows.each do |row|
expect(row.attributes.slice('unconfirmed_email', 'confirmation_token', 'reset_password_token',
'reset_password_sent_at', 'remember_created_at', 'unlock_token',
- 'locked_at').values).to all(be_nil)
+ 'locked_at', 'contact_email').values).to all(be_nil)
+ # An erased member shows no email at all, not even the tombstone address.
+ expect(row.email_visibility).to eq('none')
expect(row.failed_attempts).to eq(0)
expect(row.encrypted_password).to eq('')
expect([row.first_name, row.last_name]).to all(eq(User::DeletionLifecycle::ANONYMIZED_NAME))
diff --git a/spec/services/user_data_exports/builder_spec.rb b/spec/services/user_data_exports/builder_spec.rb
index 2bd2c24..f73a3c5 100644
--- a/spec/services/user_data_exports/builder_spec.rb
+++ b/spec/services/user_data_exports/builder_spec.rb
@@ -62,6 +62,14 @@ RSpec.describe UserDataExports::Builder,
# The README is rendered in a job with no request, so it must read the
# configured absolute privacy URL directly.
+ it 'exports which email the member shows and the contact address' do
+ user.update!(email_visibility: 'contact', contact_email: '[email protected]')
+ account = JSON.parse(described_class.new(user).files['account.json'])
+ row = account.is_a?(Array) ? account.first : account
+
+ expect(row).to include('email_visibility' => 'contact', 'contact_email' => '[email protected]')
+ end
+
it 'uses the configured privacy URL, never a renderer default' do
expect(files['README.txt']).to include('https://public.example/datenschutz')
expect(files['README.txt']).not_to include('example.org')