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.

Address review round 2 of linking a meeting participant

Guido Boykeb063f5d0416c
diff --git a/app/helpers/meeting_participant_links_helper.rb b/app/helpers/meeting_participant_links_helper.rb
index 4d2f616..cc6e561 100644
--- a/app/helpers/meeting_participant_links_helper.rb
+++ b/app/helpers/meeting_participant_links_helper.rb
@@ -59,11 +59,14 @@ module MeetingParticipantLinksHelper
end
# The lines of the dialog: the suggestions (E6) first, marked, then the
- # people matching the search, at most limit of them.
- def participant_link_options(participant, query, limit:)
+ # people matching the search, at most limit of them. A pick sent back after a
+ # refusal (choice) stays in the list, wherever the search had found it.
+ def participant_link_options(participant, query, limit:, choice: nil)
directory = People::Directory.new(viewer: current_user, organisation: current_organisation, query: query)
suggested = query.blank? ? directory.suggestions_for(participant.display_name) : []
others = (directory.candidates - suggested).first(limit)
+ picked = participant_link_chosen_entry(directory, choice)
+ others.unshift(picked) if picked && !suggested.include?(picked) && !others.include?(picked)
suggested.map { |entry| [entry, true] } + others.map { |entry| [entry, false] }
end
@@ -87,6 +90,15 @@ module MeetingParticipantLinksHelper
private
+ # The entry a choice names, through the viewer's own directory, or nil.
+ def participant_link_chosen_entry(directory, choice)
+ kind, id = choice.to_s.split(':', 2)
+ case kind
+ when 'person' then directory.person_entry(id)
+ when 'member' then directory.member_entry(id)
+ end
+ end
+
def participant_directory_entry(directory, participant)
if participant.user_id
directory.member_entry(participant.user_id) || directory.former_member_entry(participant.user_id)
diff --git a/app/models/CLAUDE.md b/app/models/CLAUDE.md
index b9eb280..d45b8db 100644
--- a/app/models/CLAUDE.md
+++ b/app/models/CLAUDE.md
@@ -68,7 +68,9 @@ Verzeichnis-Layout nicht ablesbar — diese Karte gruppiert sie:
ein Mitglied über `user_id`, ein Kontakt (auch die Zeile eines früheren Mitglieds) über
`person_id`. Der Actor sperrt das Meeting (`lock_in_project!`) und löst Person und Mitglied
nur über `People::Directory` des Schreibenden auf. Das Meeting-Formular kennt `person_id`
- nicht; `SaveMeeting` behält die Zeile und damit den Link.
+ nicht; `SaveMeeting` behält die Zeile und damit den Link. Macht das Formular eine
+ Kontakt-Zeile zu der eines Mitglieds, fällt `person_id` weg (ein Schlüssel), und das
+ Zuordnen (`external_in_projects`) lässt Kontakt-Zeilen aus.
* **Activity/Notifications**: `activity`, `user_activity`, `outbox_event`, `notification`,
`notification_preference`, `notification_subscription`, `email_log` — Services dazu unter
`app/services/notifications/` (eigene Karte dort)
diff --git a/app/services/actors/claim_meeting_participants.rb b/app/services/actors/claim_meeting_participants.rb
index d0481a9..9d741a2 100644
--- a/app/services/actors/claim_meeting_participants.rb
+++ b/app/services/actors/claim_meeting_participants.rb
@@ -3,7 +3,7 @@
module Actors
# Tier 1 actor (BaseActor#call template): link a batch of EXTERNAL meeting
# participations to an org member (Nachtrag: Teilnehmer-Claim). It sets user_id on
- # every external row (user_id nil) whose normalized_name matches the target, but
+ # every external row (user_id and person_id nil, MeetingParticipant.external_in_projects) whose normalized_name matches the target, but
# only within meetings the ACTING user may WRITE (:meetings), and skipping meetings
# that already link this member — otherwise the partial unique index
# (meeting_id, user_id) would raise. display_name stays a snapshot (only user_id
diff --git a/app/services/actors/link_meeting_participant.rb b/app/services/actors/link_meeting_participant.rb
index 37f6dd8..0cb1e38 100644
--- a/app/services/actors/link_meeting_participant.rb
+++ b/app/services/actors/link_meeting_participant.rb
@@ -78,7 +78,8 @@ module Actors
@participant.update!(person_id: entry.person.id)
end
rescue ActiveRecord::RecordNotUnique
- # The same member linked twice at once: the unique index refuses the second.
+ # The meeting lock runs two links one after the other, so the check above
+ # sees the first. A writer that skips the lock still meets the unique index.
refuse!(:member_already_participant)
end
diff --git a/app/services/actors/save_meeting.rb b/app/services/actors/save_meeting.rb
index 5313462..c6978f4 100644
--- a/app/services/actors/save_meeting.rb
+++ b/app/services/actors/save_meeting.rb
@@ -155,6 +155,8 @@ module Actors
# comes back on the next save). A new name without such a member is a new
# row without a link: the form has no rename, a chip removed and another
# added is another participant, and the link dialog sets the link again.
+ # One key per participant: a row the form gives to another member is that
+ # member now and drops its contact link (person_id).
def reconcile_participants(desired)
# Load the rows once (no per-row SELECT / N+1) and upsert against them.
existing = @meeting.meeting_participants.to_a
@@ -170,6 +172,7 @@ module Actors
participant ||= @meeting.meeting_participants.build
participant.organisation = org
participant.display_name = d[:display_name]
+ participant.person_id = nil if d[:user_id] && d[:user_id] != participant.user_id
participant.user_id = d[:user_id]
participant.save!
end
diff --git a/app/services/meetings/participant_claim_matches.rb b/app/services/meetings/participant_claim_matches.rb
index 6deaf98..0a3912d 100644
--- a/app/services/meetings/participant_claim_matches.rb
+++ b/app/services/meetings/participant_claim_matches.rb
@@ -3,7 +3,7 @@
module Meetings
# Live claim matcher (Nachtrag: Teilnehmer-Claim) — a READ-ONLY query PORO, not an
# actor: it never writes. For the acting user it finds external participant rows
- # (user_id nil) whose normalized_name equals an active, real-named org member's,
+ # (user_id and person_id nil, MeetingParticipant.external_in_projects) whose normalized_name equals an active, real-named org member's,
# but ONLY within meetings the acting user may WRITE (:meetings area), and minus
# the (member, name) pairs that were explicitly rejected. Each returned group
# offers the writer "link this external name to this member" — the write itself is
diff --git a/app/views/organisations/meeting_participant_links/_results.html.erb b/app/views/organisations/meeting_participant_links/_results.html.erb
index 4fcce6c..be790b7 100644
--- a/app/views/organisations/meeting_participant_links/_results.html.erb
+++ b/app/views/organisations/meeting_participant_links/_results.html.erb
@@ -4,7 +4,7 @@
Members are offered by account, contacts by row (participant_link_choice). Picking one
only marks it; "Verknüpfen" links. %>
<% pl = 'views.organisations.meetings.participant_links' %>
-<% options = participant_link_options(participant, query, limit: Organisations::MeetingParticipantLinksController::LIST_LIMIT) %>
+<% options = participant_link_options(participant, query, limit: Organisations::MeetingParticipantLinksController::LIST_LIMIT, choice: choice) %>
<%= turbo_frame_tag participant_link_results_id(participant), class: 'block' do %>
<% if options.empty? %>
<p class="participant-link-none px-2 py-2 text-sm text-cream-600"><%= t("#{pl}.none") %></p>
diff --git a/spec/requests/organisations/meeting_participant_links_spec.rb b/spec/requests/organisations/meeting_participant_links_spec.rb
index e74fc47..82bb13b 100644
--- a/spec/requests/organisations/meeting_participant_links_spec.rb
+++ b/spec/requests/organisations/meeting_participant_links_spec.rb
@@ -176,6 +176,7 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
expect(body).to include(I18n.t("#{pl}.suggestion"))
expect(body).to include(I18n.t("#{pl}.new_person"), 'value="J. Weber"')
expect(body).not_to match(/<input[^>]*name="choice"[^>]*checked/)
+ expect(body.scan("value=\"person:#{contact.id}\"").size).to eq(1)
end
it 'searches in its list frame' do
@@ -243,12 +244,16 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
it 'refuses a member already in the meeting with the dialog and a reason' do
colleague = member_with(create(:role, organisation: organisation), first_name: 'Carl')
create(:meeting_participant, meeting: meeting, display_name: 'Carl Beispiel', user: colleague)
+ # A list of suggestions only: the pick is no suggestion and must still be there.
+ stub_const('Organisations::MeetingParticipantLinksController::LIST_LIMIT', 0)
sign_in admin
post_link("member:#{colleague.id}")
expect(response).to have_http_status(:unprocessable_content)
expect(response.body).to include("action=\"replace\" target=\"meeting-participant-link-modal-#{meeting.id}-#{modal_token}\"")
+ # The pick stays marked, also when it is not among the first lines of the list.
+ expect(response.body).to match(/<input[^>]*value="member:#{colleague.id}"[^>]*checked/)
expect(response.body).to include(I18n.t('services.actors.link_meeting_participant.member_already_participant'))
expect(participant.reload.user_id).to be_nil
end
@@ -399,6 +404,17 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :reque
expect(participant.reload.person_id).to eq(contact.id)
end
+ it 'keeps one key when the form makes a contact-linked row a member' do
+ colleague = member_with(create(:role, organisation: organisation), first_name: 'Carl')
+ sign_in admin
+ post_link("person:#{contact.id}")
+
+ edit_with(display_name: 'J. Weber (Hoster)', user_id: colleague.id)
+
+ expect(participant.reload.user_id).to eq(colleague.id)
+ expect(participant.person_id).to be_nil
+ end
+
# The form labels a member chip with the member's profile name, so the row is kept by
# its member, not by its name (SaveMeeting#match_participant_rows).
it 'keeps a member link, which the form sends as user_id under the profile name' do
diff --git a/spec/services/actors/link_meeting_participant_spec.rb b/spec/services/actors/link_meeting_participant_spec.rb
index 1219e97..8f1db9b 100644
--- a/spec/services/actors/link_meeting_participant_spec.rb
+++ b/spec/services/actors/link_meeting_participant_spec.rb
@@ -99,6 +99,13 @@ RSpec.describe Actors::LinkMeetingParticipant, :ci_guard do
expect(participant.reload.user_id).to be_nil
end
+ it 'links a participant that already carries the member\'s name' do
+ participant.update!(display_name: colleague.display_name)
+
+ expect(link(member_id: colleague.id)).to be_success
+ expect(participant.reload.user_id).to eq(colleague.id)
+ end
+
# The meeting form labels a member chip with the member's profile name: a second
# participant of that name would make every later save of the meeting fail.
it 'refuses a member whose name another participant of the meeting carries' do
diff --git a/spec/services/actors/save_meeting_spec.rb b/spec/services/actors/save_meeting_spec.rb
index df7d17e..0305f7d 100644
--- a/spec/services/actors/save_meeting_spec.rb
+++ b/spec/services/actors/save_meeting_spec.rb
@@ -266,15 +266,24 @@ RSpec.describe Actors::SaveMeeting do
expect(rows).to eq([[row.id, 'KARL krause', person.id]])
end
- it 'keeps person_id when only the user_id of the participant changes' do
+ # One key per participant (people directory, S2b): a contact row the form
+ # makes a member's is that member now. It keeps the row, not the contact.
+ it 'drops the contact link when the form makes the row a member' do
member = org_member
meeting = meeting_with('Karl Krause')
row = linked_row(meeting, 'Karl Krause')
save(meeting, valid_params.merge(participants: [{ display_name: 'Karl Krause', user_id: member.id }]))
- expect(MeetingParticipant.where(id: row.id).pluck(:user_id, :person_id)).to eq([[member.id, person.id]])
+
+ expect(MeetingParticipant.where(id: row.id).pluck(:user_id, :person_id)).to eq([[member.id, nil]])
+ end
+
+ it 'keeps person_id when a save sends the row without a member, as before' do
+ meeting = meeting_with('Karl Krause')
+ row = linked_row(meeting, 'Karl Krause')
save(meeting, valid_params.merge(participants: [{ display_name: 'Karl Krause', user_id: '' }]))
+
expect(MeetingParticipant.where(id: row.id).pluck(:user_id, :person_id)).to eq([[nil, person.id]])
end
diff --git a/spec/system/meeting_participant_link_spec.rb b/spec/system/meeting_participant_link_spec.rb
index 6cd2e30..a7baf83 100644
--- a/spec/system/meeting_participant_link_spec.rb
+++ b/spec/system/meeting_participant_link_spec.rb
@@ -36,6 +36,8 @@ RSpec.describe 'Linking a meeting participant to a person', type: :system do
def open_dialog
find("##{trigger_id}").click
expect(page).to have_css('[role="dialog"]', text: I18n.t("#{pl}.title"))
+ # The search has the focus at once: typing searches without a click first.
+ expect(page).to have_css('[role="dialog"] input[type="search"]:focus')
end
it 'searches, links, closes and gives the focus back' do