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.

Clean the copied addresses from notifications and close three smaller leaks

Guido Boyke225615f61bd4
diff --git a/app/controllers/organisations/documents_controller.rb b/app/controllers/organisations/documents_controller.rb
index c280590..0aee1a2 100644
--- a/app/controllers/organisations/documents_controller.rb
+++ b/app/controllers/organisations/documents_controller.rb
@@ -13,7 +13,7 @@ class Organisations::DocumentsController < Organisations::BaseController
# Configure the Sortable functionality
setup_sortable Document, 'documents.created_at'
- add_sortable_columns 'document_versions.title', 'users.email'
+ add_sortable_columns 'document_versions.title'
# Configure the Pageable functionality
setup_pagination 5
diff --git a/app/helpers/smart_folder_helper.rb b/app/helpers/smart_folder_helper.rb
index 6300b3e..08300bf 100644
--- a/app/helpers/smart_folder_helper.rb
+++ b/app/helpers/smart_folder_helper.rb
@@ -179,9 +179,14 @@ module SmartFolderHelper
end
end
- # Optional: sort the options sensibly
- sort_column = %i[name title email].find { |col| model_class.column_names.include?(col.to_s) } || model_class.primary_key
- records = base_scope.order(sort_column)
+ # Optional: sort the options sensibly. People by name, never by email: the
+ # list is cut at 50 below, and an order by email would decide who appears
+ # by the alphabet of addresses a member may hide (User::EmailDisplay).
+ records = if model_class == User
+ base_scope.order(:last_name, :first_name, :id)
+ else
+ base_scope.order(%i[name title].find { |col| model_class.column_names.include?(col.to_s) } || model_class.primary_key)
+ end
# Filter by search term, if one is present
records = records.where('name ILIKE ?', "%#{search_term}%") if search_term.present? && model_class.column_names.include?('name')
diff --git a/app/models/user_activity.rb b/app/models/user_activity.rb
index f4f5f77..a890971 100644
--- a/app/models/user_activity.rb
+++ b/app/models/user_activity.rb
@@ -308,14 +308,11 @@ class UserActivity < ApplicationRecord
I18n.t('models.user_activity.descriptions.location_info', ip: ip_address)
end
+ # Names no address: organisation admins read this log on the member's
+ # activity page, and a member chooses which email the others see
+ # (User::EmailDisplay).
def email_change_description
- if attribute_changes['email'].present?
- I18n.t('models.user_activity.descriptions.email_changed_detail',
- old_email: attribute_changes['email'][0],
- new_email: attribute_changes['email'][1])
- else
- I18n.t('models.user_activity.descriptions.email_changed')
- end
+ I18n.t('models.user_activity.descriptions.email_changed')
end
def role_change_description(action_text)
diff --git a/config/locales/models.de.yml b/config/locales/models.de.yml
index 05075c8..82613fa 100644
--- a/config/locales/models.de.yml
+++ b/config/locales/models.de.yml
@@ -462,7 +462,6 @@ de:
account_locked: "Account gesperrt%{lock_reason}"
account_unlocked: "Account entsperrt"
email_changed: "E-Mail-Adresse geändert"
- email_changed_detail: "E-Mail geändert von %{old_email} zu %{new_email}"
role_changed: "Rolle '%{role_name}' %{action_text}"
role_changed_no_name: "Rolle %{action_text}"
role_action_assigned: "zugewiesen"
diff --git a/config/locales/models.en.yml b/config/locales/models.en.yml
index 9ea2c7b..2939d65 100644
--- a/config/locales/models.en.yml
+++ b/config/locales/models.en.yml
@@ -452,7 +452,6 @@ en:
account_locked: "Account locked%{lock_reason}"
account_unlocked: "Account unlocked"
email_changed: "Email address changed"
- email_changed_detail: "Email changed from %{old_email} to %{new_email}"
role_changed: "Role '%{role_name}' %{action_text}"
role_changed_no_name: "Role %{action_text}"
role_action_assigned: "assigned"
diff --git a/lib/tasks/activities_drop_member_emails.rake b/lib/tasks/activities_drop_member_emails.rake
index 0280118..32e14a4 100644
--- a/lib/tasks/activities_drop_member_emails.rake
+++ b/lib/tasks/activities_drop_member_emails.rake
@@ -3,16 +3,27 @@
namespace :activities do
# A data backfill (Lalabase::DataBackfills::TASKS). Until 2026-10-29
# ProjectTrackable#track_member_added stored the member's login address in the
- # activity's parameters (`user_email`). Everyone who reads the project's
- # members area sees those rows, and the activity search read the whole JSON,
- # so it confirmed an address a member may now hide (User::EmailDisplay). This
- # removes the key from the old rows; other parameters stay. Idempotent: the
- # second run finds no row with the key.
- desc 'Remove the stored login address from old member_added activities (a data backfill)'
+ # activity's parameters (`user_email`), and Notifications::FanoutService and
+ # OutboxEvent copied those parameters into their payload. Everyone who reads
+ # the project's members area saw the rows, the activity search and the inbox
+ # search read the JSON, and REST/MCP hand the notification payload out: an
+ # address a member may now hide (User::EmailDisplay). This removes the key
+ # from all three; other keys stay. Both or neither, in one transaction, as
+ # Posts::ExcerptRedaction does for comment excerpts. Idempotent: the second
+ # run finds no row with the key.
+ desc 'Remove the stored login address from old member_added activities and their copies (a data backfill)'
task drop_member_emails: :environment do
+ copied = "payload->'parameters' ? 'user_email'"
removed = ActsAsTenant.without_tenant do
- Activity.unscoped.where('parameters ? :key', key: 'user_email')
- .update_all(['parameters = parameters - :key', { key: 'user_email' }])
+ ActiveRecord::Base.transaction do
+ # key = 'project.member_added' first: the (organisation_id, key, created_at)
+ # index narrows the rows before the JSON is read.
+ count = Activity.unscoped.where(key: 'project.member_added').where("parameters ? 'user_email'")
+ .update_all("parameters = parameters - 'user_email'")
+ Notification.unscoped.where(copied).update_all("payload = payload #- '{parameters,user_email}'")
+ OutboxEvent.unscoped.where(copied).update_all("payload = payload #- '{parameters,user_email}'")
+ count
+ end
end
puts "activities:drop_member_emails: #{removed} activities cleaned."
end
diff --git a/spec/architecture/shown_email_guard_spec.rb b/spec/architecture/shown_email_guard_spec.rb
index 794972f..300df4f 100644
--- a/spec/architecture/shown_email_guard_spec.rb
+++ b/spec/architecture/shown_email_guard_spec.rb
@@ -45,8 +45,6 @@ module ShownEmailGuard
'the exact match of an import finds the account by its login address; the preview shows the shown email',
['app/services/codebase_import/ticket_update_importer.rb', 'new_assignee'] =>
'a debug log line on the server, never rendered',
- ['app/controllers/organisations/documents_controller.rb', 'users'] =>
- 'a whitelisted SQL sort column name, not a value shown to anyone',
['app/services/notifications/score_calculator.rb', '@recipient'] =>
"compares the recipient's own address with a rule value, nothing is shown",
['app/javascript/controllers/subscriber_picker_controller.js', 'user'] =>
diff --git a/spec/helpers/smart_folder_reference_scoping_spec.rb b/spec/helpers/smart_folder_reference_scoping_spec.rb
index e3953c4..9055a6e 100644
--- a/spec/helpers/smart_folder_reference_scoping_spec.rb
+++ b/spec/helpers/smart_folder_reference_scoping_spec.rb
@@ -47,6 +47,22 @@ RSpec.describe SmartFolderHelper, type: :helper do
expect(ids).not_to include(foreigner.id)
end
+ # By name, not by email: the list is cut at 50, so an order by email would
+ # decide who appears by the alphabet of addresses a member may hide.
+ it 'orders the people by name, not by their login address' do
+ zora = create(:user, first_name: 'Zora', last_name: 'Alpha', email: '[email protected]')
+ anna = create(:user, first_name: 'Anna', last_name: 'Zeta', email: '[email protected]')
+ [zora, anna].each do |user|
+ create(:membership, user: user, organisation: organisation, role: standard_role, active: true)
+ create(:project_permission, user: user, project: project_a, tickets_access: 'read_only')
+ end
+
+ ids = helper.available_reference_options('assignee', organisation, project: project_a,
+ accessible_project_ids: [project_a.id]).map { |o| o[:value] }
+
+ expect(ids.index(zora.id)).to be < ids.index(anna.id)
+ end
+
it 'includes the current user and project colleagues, scoped to the passed projects' do
colleague = member_in
create(:project_permission, user: colleague, project: project_a, tickets_access: 'read_only')
diff --git a/spec/lib/tasks/activities_drop_member_emails_spec.rb b/spec/lib/tasks/activities_drop_member_emails_spec.rb
index 20ea19f..dc41cd0 100644
--- a/spec/lib/tasks/activities_drop_member_emails_spec.rb
+++ b/spec/lib/tasks/activities_drop_member_emails_spec.rb
@@ -34,6 +34,25 @@ RSpec.describe 'activities:drop_member_emails', :ci_guard do
expect(old_row.reload.parameters).to eq('user_name' => 'Mia Mitglied', 'tickets_access' => 'read_only')
end
+ # FanoutService and OutboxEvent copy the activity's parameters into their
+ # payload; the REST and MCP inbox hand the payload out, and the inbox search
+ # reads it. Both or neither, as Posts::ExcerptRedaction does for excerpts.
+ it 'removes the copied login address from notifications and outbox events, keeping the rest' do
+ activity = activity_with('user_name' => 'Mia Mitglied', 'user_email' => '[email protected]')
+ copied = { 'activity_id' => activity.id, 'action' => 'member_added',
+ 'parameters' => { 'user_name' => 'Mia Mitglied', 'user_email' => '[email protected]' } }
+ notification, outbox = ActsAsTenant.with_tenant(organisation) do
+ [create(:notification, organisation: organisation, recipient: create(:user), payload: copied),
+ create(:outbox_event, organisation: organisation, activity: activity, payload: copied)]
+ end
+
+ expect { Rake::Task['activities:drop_member_emails'].invoke }.to output(/1 activities/).to_stdout
+
+ expected = { 'activity_id' => activity.id, 'action' => 'member_added', 'parameters' => { 'user_name' => 'Mia Mitglied' } }
+ expect(notification.reload.payload).to eq(expected)
+ expect(outbox.reload.payload).to eq(expected)
+ end
+
it 'leaves rows without the key alone and touches nothing the second time' do
new_row = activity_with('user_name' => 'Mia Mitglied')
activity_with('user_email' => '[email protected]')
diff --git a/spec/models/user_activity_spec.rb b/spec/models/user_activity_spec.rb
index c0c6aaa..d256b49 100644
--- a/spec/models/user_activity_spec.rb
+++ b/spec/models/user_activity_spec.rb
@@ -557,12 +557,15 @@ RSpec.describe UserActivity, type: :model do
expect(activity.description).to eq(I18n.t('models.user_activity.descriptions.logout'))
end
- it 'returns email_changed description with change details' do
+ # An organisation admin reads this log on the member's activity page, and a
+ # member chooses which email the others see (User::EmailDisplay): the
+ # description names no address, even when the change details are stored.
+ it 'returns the generic email_changed description even with change details' do
activity = build(:user_activity, user: user, organisation: organisation,
action: 'email_changed', category: 'profile',
attribute_changes: { 'email' => %w[[email protected] [email protected]] })
- expect(activity.description).to include('[email protected]')
- expect(activity.description).to include('[email protected]')
+ expect(activity.description).to eq(I18n.t('models.user_activity.descriptions.email_changed'))
+ expect(activity.description).not_to include('[email protected]', '[email protected]')
end
it 'returns generic email_changed description without change details' do