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.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Remove the older assignee address keys and pin the preselected choice
Guido Boyke490d3c06409f
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.ymlindex c427b01..361fd7f 100644--- a/.github/workflows/guards.yml+++ b/.github/workflows/guards.yml@@ -199,7 +199,7 @@ jobs:spec/lib/tasks/chats_purge_legacy_threads_spec.rbspec/lib/tasks/chats_scope_project_cleanup_spec.rbspec/lib/tasks/data_backfills_spec.rb- spec/lib/tasks/activities_drop_member_emails_spec.rb+ spec/lib/tasks/activities_drop_stored_emails_spec.rbspec/presenters/inbox/activity_line_spec.rbspec/mailers/spec/middleware/active_storage_tenant_bypass_spec.rbdiff --git a/app/controllers/organisations/notification_subscriptions_controller.rb b/app/controllers/organisations/notification_subscriptions_controller.rbindex 6e522c0..8f521da 100644--- a/app/controllers/organisations/notification_subscriptions_controller.rb+++ b/app/controllers/organisations/notification_subscriptions_controller.rb@@ -122,7 +122,7 @@ module Organisationsusers = by_name.or(users.merge(User.matching_shown_email(params[:q])))end- render json: users.limit(20).map { |u| { id: u.id, name: u.full_name, email: u.shown_email } }+ render json: users.limit(20).map { |u| { id: u.id, name: u.display_name, email: u.shown_email } }endprivatediff --git a/app/controllers/organisations/projects/activities_controller.rb b/app/controllers/organisations/projects/activities_controller.rbindex 6704182..3da1118 100644--- a/app/controllers/organisations/projects/activities_controller.rb+++ b/app/controllers/organisations/projects/activities_controller.rb@@ -163,11 +163,13 @@ class Organisations::Projects::ActivitiesController < Organisations::BaseControl<<~SQL.squish,activities.action ILIKE :pattern ORactivities.key ILIKE :pattern OR- CAST(activities.parameters - 'user_email' AS TEXT) ILIKE :pattern OR+ CAST(activities.parameters - ARRAY[:stored_email_keys]::text[] AS TEXT) ILIKE :pattern OR(activities.trackable_type = 'Ticket' AND activities.trackable_id IN (:ticket_ids)) OR(activities.secondary_type = 'Ticket' AND activities.secondary_id IN (:ticket_ids))SQLpattern:,+ # Older rows may still hold a member's login address (Activity::STORED_EMAIL_KEYS).+ stored_email_keys: Activity::STORED_EMAIL_KEYS,ticket_ids: matching_tickets)enddiff --git a/app/models/activity.rb b/app/models/activity.rbindex b29535b..0935cdd 100644--- a/app/models/activity.rb+++ b/app/models/activity.rb@@ -164,6 +164,15 @@ class Activity < ApplicationRecord# stopped recording them.NOISE_CHANGE_ATTRIBUTES = %w[updater_id].freeze+ # Parameter keys under which older activities stored a member's login address:+ # project.member_added (user_email, until 2026-10-29), ticket.assigned and+ # ticket.unassigned (assignee_email, unassignee_email, before they read the+ # user from `secondary`). Nothing writes them any more (shown_email guard). The+ # project activity search leaves them out and `activities:drop_stored_emails`+ # removes them, with their copies in notifications and outbox events: a+ # member chooses which email the others see (User::EmailDisplay).+ STORED_EMAIL_KEYS = %w[user_email assignee_email unassignee_email].freeze+# Checks whether the activity contains changes worth showingdef has_changes?formatted_changes.any?diff --git a/app/views/user_preferences/display.html.erb b/app/views/user_preferences/display.html.erbindex 09f105c..54d6bad 100644--- a/app/views/user_preferences/display.html.erb+++ b/app/views/user_preferences/display.html.erb@@ -72,7 +72,7 @@<%# Which email the others see (User::EmailDisplay): the login address,a separate contact address, or none. A column on users, saved by- UserPreferencesController#apply_email_visibility_update without the+ UserPreferencesController#apply_display_update without thecurrent password; signing in and Lalabase's mail keep the login address. %><div><span class="block text-sm font-bold mb-2 text-cream-900"><%= t('user_preferences.edit.display.email_visibility.label') %></span>diff --git a/lib/lalabase/data_backfills.rb b/lib/lalabase/data_backfills.rbindex ae69953..2ceafeb 100644--- a/lib/lalabase/data_backfills.rb+++ b/lib/lalabase/data_backfills.rb@@ -40,10 +40,11 @@ module Lalabase# the inbox rule as a system message. A row with a mail log stays (bounces).# Idempotent, and it may stay: it only deletes rows whose subject is gone.'notifications:purge_project_leftovers',- # member_added activities written before 2026-10-29 lose the login address- # they stored (`user_email`); a member chooses which email the others see.- # Idempotent, and it may go once no installation is older than that.- 'activities:drop_member_emails'+ # Activities written before 2026-10-29 lose the login addresses they stored+ # (Activity::STORED_EMAIL_KEYS), with their copies in notifications and+ # outbox events; a member chooses which email the others see. Idempotent,+ # and it may go once no installation is older than that.+ 'activities:drop_stored_emails'].freezeendenddiff --git a/lib/tasks/activities_drop_member_emails.rake b/lib/tasks/activities_drop_member_emails.rakedeleted file mode 100644index 32e14a4..0000000--- a/lib/tasks/activities_drop_member_emails.rake+++ /dev/null@@ -1,30 +0,0 @@-# frozen_string_literal: true--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`), 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- 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-enddiff --git a/lib/tasks/activities_drop_stored_emails.rake b/lib/tasks/activities_drop_stored_emails.rakenew file mode 100644index 0000000..9818625--- /dev/null+++ b/lib/tasks/activities_drop_stored_emails.rake@@ -0,0 +1,37 @@+# frozen_string_literal: true++namespace :activities do+ # A data backfill (Lalabase::DataBackfills::TASKS). Older activities stored a+ # member's login address in their parameters (Activity::STORED_EMAIL_KEYS:+ # project.member_added until 2026-10-29, ticket.assigned/unassigned before+ # they read the user from `secondary`), and Notifications::FanoutService and+ # OutboxEvent copied those parameters into their payload (an assignee+ # notification also at its top). Readers of the project saw the rows, the+ # activity and inbox searches read the JSON, and REST/MCP hand activity+ # parameters and notification payloads out: an address a member may now hide+ # (User::EmailDisplay). This removes the keys from all of them; other keys+ # stay. Both or neither, in one transaction, as Posts::ExcerptRedaction does+ # for comment excerpts. Idempotent: the second run finds no row with a key.+ #+ # Cost: `?|` on activities.parameters and on the nested payload has no index,+ # so each run reads activities, notifications and outbox_events once; the+ # top-level payload check can use the notifications GIN index.+ desc 'Remove stored login addresses from old activities and their copies (a data backfill)'+ task drop_stored_emails: :environment do+ keys = Activity::STORED_EMAIL_KEYS+ array = "ARRAY[#{keys.map { |key| ActiveRecord::Base.connection.quote(key) }.join(', ')}]::text[]"+ nested = "payload->'parameters' ?| #{array}"+ strip_nested = "jsonb_set(payload, '{parameters}', (payload->'parameters') - #{array})"++ removed = ActsAsTenant.without_tenant do+ ActiveRecord::Base.transaction do+ count = Activity.unscoped.where("parameters ?| #{array}").update_all("parameters = parameters - #{array}")+ Notification.unscoped.where("payload ?| #{array}").update_all("payload = payload - #{array}")+ Notification.unscoped.where(nested).update_all("payload = #{strip_nested}")+ OutboxEvent.unscoped.where(nested).update_all("payload = #{strip_nested}")+ count+ end+ end+ puts "activities:drop_stored_emails: #{removed} activities cleaned."+ end+enddiff --git a/spec/lib/tasks/activities_drop_member_emails_spec.rb b/spec/lib/tasks/activities_drop_stored_emails_spec.rbsimilarity index 53%rename from spec/lib/tasks/activities_drop_member_emails_spec.rbrename to spec/lib/tasks/activities_drop_stored_emails_spec.rbindex dc41cd0..36abb6c 100644--- a/spec/lib/tasks/activities_drop_member_emails_spec.rb+++ b/spec/lib/tasks/activities_drop_stored_emails_spec.rb@@ -3,17 +3,17 @@require 'rails_helper'require 'rake'-# What: `rake activities:drop_member_emails`, a data backfill.+# What: `rake activities:drop_stored_emails`, a data backfill.# Why: project.member_added stored the member's login address in its parameters# until 2026-10-29. Every reader of the project's members area sees and# searches those rows, and a member now chooses which email the others see# (User::EmailDisplay). The task removes the key from the old rows.-RSpec.describe 'activities:drop_member_emails', :ci_guard do+RSpec.describe 'activities:drop_stored_emails', :ci_guard dobefore(:all) do- Rails.application.load_tasks unless Rake::Task.task_defined?('activities:drop_member_emails')+ Rails.application.load_tasks unless Rake::Task.task_defined?('activities:drop_stored_emails')end- before { Rake::Task['activities:drop_member_emails'].reenable }+ before { Rake::Task['activities:drop_stored_emails'].reenable }let(:organisation) { create(:organisation) }let(:project) { create(:project, organisation: organisation) }@@ -29,7 +29,7 @@ RSpec.describe 'activities:drop_member_emails', :ci_guard doit 'removes the stored login address and keeps every other parameter' doold_row = activity_with('user_name' => 'Mia Mitglied', 'user_email' => '[email protected]', 'tickets_access' => 'read_only')- expect { Rake::Task['activities:drop_member_emails'].invoke }.to output(/1 activities/).to_stdout+ expect { Rake::Task['activities:drop_stored_emails'].invoke }.to output(/1 activities/).to_stdoutexpect(old_row.reload.parameters).to eq('user_name' => 'Mia Mitglied', 'tickets_access' => 'read_only')end@@ -46,25 +46,55 @@ RSpec.describe 'activities:drop_member_emails', :ci_guard docreate(:outbox_event, organisation: organisation, activity: activity, payload: copied)]end- expect { Rake::Task['activities:drop_member_emails'].invoke }.to output(/1 activities/).to_stdout+ expect { Rake::Task['activities:drop_stored_emails'].invoke }.to output(/1 activities/).to_stdoutexpected = { '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+ # ticket.assigned and ticket.unassigned stored the assignee's address under+ # assignee_email / unassignee_email before they read it from the user;+ # their notifications kept a copy at the top of the payload and under parameters.+ it 'removes the older assignee keys from activities and from both places of a notification' do+ ticket = ActsAsTenant.with_tenant(organisation) { create(:ticket, project: project) }+ activity = ActsAsTenant.with_tenant(organisation) do+ create(:activity, trackable: ticket, organisation: organisation, secondary: member, key: 'ticket.assigned',+ action: 'assigned', parameters: { 'assignee_email' => '[email protected]', 'display_name' => 'Kanban' })+ end+ unassigned = ActsAsTenant.with_tenant(organisation) do+ create(:activity, trackable: ticket, organisation: organisation, secondary: member, key: 'ticket.unassigned',+ action: 'unassigned', parameters: { 'unassignee_email' => '[email protected]' })+ end+ notification = ActsAsTenant.with_tenant(organisation) do+ create(:notification, organisation: organisation, recipient: create(:user),+ payload: { 'activity_id' => activity.id, 'assignee_email' => '[email protected]',+ 'parameters' => { 'assignee_email' => '[email protected]', 'display_name' => 'Kanban' } })+ end++ expect { Rake::Task['activities:drop_stored_emails'].invoke }.to output(/2 activities/).to_stdout++ expect(activity.reload.parameters).to eq('display_name' => 'Kanban')+ expect(unassigned.reload.parameters).to eq({})+ expect(notification.reload.payload).to eq('activity_id' => activity.id, 'parameters' => { 'display_name' => 'Kanban' })+ end++ it 'names every key it removes in one list' do+ expect(Activity::STORED_EMAIL_KEYS).to contain_exactly('user_email', 'assignee_email', 'unassignee_email')+ end+it 'leaves rows without the key alone and touches nothing the second time' donew_row = activity_with('user_name' => 'Mia Mitglied')activity_with('user_email' => '[email protected]')- expect { Rake::Task['activities:drop_member_emails'].invoke }.to output(/1 activities/).to_stdout- Rake::Task['activities:drop_member_emails'].reenable- expect { Rake::Task['activities:drop_member_emails'].invoke }.to output(/0 activities/).to_stdout+ expect { Rake::Task['activities:drop_stored_emails'].invoke }.to output(/1 activities/).to_stdout+ Rake::Task['activities:drop_stored_emails'].reenable+ expect { Rake::Task['activities:drop_stored_emails'].invoke }.to output(/0 activities/).to_stdoutexpect(new_row.reload.parameters).to eq('user_name' => 'Mia Mitglied')endit 'runs on every deploy' do- expect(Lalabase::DataBackfills::TASKS).to include('activities:drop_member_emails')+ expect(Lalabase::DataBackfills::TASKS).to include('activities:drop_stored_emails')endenddiff --git a/spec/models/user/email_display_spec.rb b/spec/models/user/email_display_spec.rbindex 797ee40..b863ce9 100644--- a/spec/models/user/email_display_spec.rb+++ b/spec/models/user/email_display_spec.rb@@ -123,7 +123,12 @@ RSpec.describe User::EmailDisplay, :ci_guard, type: :model dodescribe '.matching_shown_email' dolet!(: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') }+ let!(:hidden) do+ create(:user, email: '[email protected]', email_visibility: 'none', contact_email: '[email protected]')+ end+ let!(:back_to_login) do+ create(:user, email: '[email protected]', email_visibility: 'login', contact_email: '[email protected]')+ endit 'finds the login address of a member who shows it' doexpect(User.matching_shown_email('plain@')).to contain_exactly(plain)@@ -133,6 +138,14 @@ RSpec.describe User::EmailDisplay, :ci_guard, type: :model doexpect(User.matching_shown_email('SHOWN@')).to contain_exactly(contact)end+ # A stored contact address stays when the member switches away from it; it+ # is not shown then, so it must not be found either.+ it 'never finds a stored contact address the member does not show' do+ expect(User.matching_shown_email('kept-contact')).to be_empty+ expect(User.matching_shown_email('old-contact')).to be_empty+ expect(User.matching_shown_email('back-login')).to contain_exactly(back_to_login)+ end+it 'never finds a hidden login address' doexpect(User.matching_shown_email('secret-login')).to be_emptyexpect(User.matching_shown_email('hidden-login')).to be_emptydiff --git a/spec/requests/organisations/shown_email_spec.rb b/spec/requests/organisations/shown_email_spec.rbindex 334546d..bfa766c 100644--- a/spec/requests/organisations/shown_email_spec.rb+++ b/spec/requests/organisations/shown_email_spec.rb@@ -162,6 +162,23 @@ RSpec.describe 'The email a member shows to others', :ci_guard, type: :request dexpect(response.body).not_to include(row)end+ it 'never confirms a hidden login address from an older assignee key' do+ ticket = ActsAsTenant.with_tenant(organisation) { create(:ticket, project: project, title: 'Kanbanfreigabe') }+ ActsAsTenant.with_tenant(organisation) do+ create(:activity, trackable: ticket, organisation: organisation, actor: admin, secondary: nina,+ key: 'ticket.assigned', action: 'assigned', parameters: { 'assignee_email' => '[email protected]' })+ end+ path = ->(q) { organisation_project_activities_path(organisation_id: organisation.id, project_id: project.id, q: q) }++ get path.call('Kanbanfrei')+ expect(response).to have_http_status(:ok)+ expect(response.body).to include('Kanbanfreigabe')++ get path.call('[email protected]')+ expect(response).to have_http_status(:ok)+ expect(response.body).not_to include('Kanbanfreigabe')+ end+it 'stores no login address when a member joins a project' doactivity = ActsAsTenant.with_tenant(organisation) doCurrent.set(user: admin) { project.track_member_added(nina) }@@ -262,6 +279,18 @@ RSpec.describe 'The email a member shows to others', :ci_guard, type: :request dexpect_no_hidden_login_address(response.body)end+ it 'names a member without a name like everywhere else' do+ ghost = member(nil, '[email protected]', email_visibility: 'none')+ ghost.update_columns(last_name: nil)+ create(:project_permission, user: ghost, project: project, tickets_access: 'read_write')++ get path, as: :json++ row = response.parsed_body.find { |entry| entry['id'] == ghost.id }+ expect(row).to include('name' => I18n.t('users.unnamed'), 'email' => nil)+ expect(response.body).not_to include('ghost-login')+ end+it 'searches the shown email, never a hidden login address' doget path, params: { q: 'lena.team' }, as: :jsonexpect(response.parsed_body.pluck('id')).to include(lena.id)diff --git a/spec/requests/user_preferences_email_visibility_spec.rb b/spec/requests/user_preferences_email_visibility_spec.rbindex 0673320..8591e61 100644--- a/spec/requests/user_preferences_email_visibility_spec.rb+++ b/spec/requests/user_preferences_email_visibility_spec.rb@@ -29,6 +29,31 @@ RSpec.describe 'User preferences: the email the others see', :ci_guard, type: :rexpect(response.body).to include('value="login" checked="checked"')end+ # The form sends the choice with every save of the section; a wrong+ # preselection would reset a hidden address on the next name spelling change.+ %w[contact none].each do |choice|+ it "preselects #{choice} when the member chose it" do+ user.update!(email_visibility: choice, contact_email: '[email protected]')++ get display_user_preferences_path++ expect(response.body).to include(%(value="#{choice}" checked="checked"))+ expect(response.body).not_to include('value="login" checked')+ end+ end++ it 'keeps none when the section is saved again with its preselected form values' do+ user.update!(email_visibility: 'none')+ get display_user_preferences_path+ form = Nokogiri::HTML(response.body)+ chosen = form.at_css('input[name="user[email_visibility]"][checked]')['value']++ patch user_preferences_path, params: { current_section: 'display', user: { email_visibility: chosen, contact_email: '' },+ preferences: { name_display: 'first_last_initial' } }++ expect(user.reload.email_visibility).to eq('none')+ end+it 'saves a contact address without the current password' dosave(email_visibility: 'contact', contact_email: '[email protected]')