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.

Pin that a name and a member never take the same row

Guido Boyke1ecf3c2b10c4
diff --git a/app/services/actors/save_meeting.rb b/app/services/actors/save_meeting.rb
index aac5d6c..5313462 100644
--- a/app/services/actors/save_meeting.rb
+++ b/app/services/actors/save_meeting.rb
@@ -177,14 +177,17 @@ module Actors
# The existing row for each desired participant, or nil for a new one: the
# row of its normalized name first, else the row of its member that no name
- # claimed. Name first, so a member's old row goes rather than collide with a
- # row that keeps the new name. Each user_id occurs once in desired
+ # claimed. Name first, so the row of a name keeps its name and its link:
+ # a member whose new name is already an external row of this meeting takes
+ # that row and its link, and the member's old row goes (as before the
+ # member match existed). Only unclaimed rows count for a member, so a name
+ # and a member never get the same row. Each user_id occurs once in desired
# (guard_against_duplicates!), so a row is never matched twice.
def match_participant_rows(existing, desired)
by_name = existing.index_by(&:normalized_name)
rows = desired.map { |d| by_name[d[:normalized_name]] }
by_user = (existing - rows.compact).select(&:user_id).index_by(&:user_id)
- desired.zip(rows).map { |d, row| row || (d[:user_id] && by_user[d[:user_id]]) }
+ desired.zip(rows).map { |d, row| row || by_user[d[:user_id]] }
end
# PII fail-safe (Gespräche Slice 6, plan §5/§7): a meeting that is NOT indexed
diff --git a/spec/services/actors/save_meeting_spec.rb b/spec/services/actors/save_meeting_spec.rb
index fae0e91..95f2aae 100644
--- a/spec/services/actors/save_meeting_spec.rb
+++ b/spec/services/actors/save_meeting_spec.rb
@@ -329,8 +329,8 @@ RSpec.describe Actors::SaveMeeting do
expect(rows).to eq([[row.id, 'Karl Krause-Meier', member.id, person.id]])
end
- # A row whose name is sent keeps its name; matching by member comes second,
- # so the member's old row goes instead of colliding with it.
+ # A row whose name is sent keeps its name; matching by member comes second.
+ # The member takes the row of its new name, and its old row goes.
it 'matches by name before it matches by member' do
member = org_member
meeting = described_class.call(
@@ -347,6 +347,24 @@ RSpec.describe Actors::SaveMeeting do
rows = meeting.reload.meeting_participants.pluck(:id, :user_id, :person_id)
expect(rows).to eq([[named.id, member.id, nil]])
end
+
+ # The member's old name comes back as an external participant: that name
+ # claims the row, so the member cannot take it too and gets a new one.
+ it 'never gives a name and a member the same row' do
+ member = org_member
+ meeting = described_class.call(
+ project: project, params: valid_params.merge(participants: [{ display_name: 'Karl Krause', user_id: member.id }]),
+ current_user: user
+ ).resource
+ row = linked_row(meeting, 'Karl Krause')
+
+ save(meeting, valid_params.merge(participants: [{ display_name: 'Karl Krause' },
+ { display_name: 'Karl Krause-Meier', user_id: member.id }]))
+
+ rows = meeting.reload.meeting_participants.order(:normalized_name).pluck(:id, :normalized_name, :user_id, :person_id)
+ expect(rows).to match([[row.id, 'karl krause', nil, person.id],
+ [satisfy { |id| id != row.id }, 'karl krause-meier', member.id, nil]])
+ end
end
end