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
Give the participant link rules one owner each and close five gaps
Guido Boyke5e1785eba04f
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.ymlindex b8581c8..97230c0 100644--- a/.github/workflows/guards.yml+++ b/.github/workflows/guards.yml@@ -323,6 +323,7 @@ jobs:spec/requests/organisations/people_last_contact_spec.rbspec/requests/organisations/meeting_participant_links_spec.rbspec/services/actors/link_meeting_participant_spec.rb+ spec/services/meetings/account_participants_spec.rbspec/requests/organisations/note_editor_embed_spec.rbspec/requests/organisations/onboarding_banner_spec.rbspec/requests/organisations/panel_lane_markup_guard_spec.rbdiff --git a/app/controllers/organisations/meeting_participant_links_controller.rb b/app/controllers/organisations/meeting_participant_links_controller.rbindex 99039dd..72263f0 100644--- a/app/controllers/organisations/meeting_participant_links_controller.rb+++ b/app/controllers/organisations/meeting_participant_links_controller.rb@@ -7,11 +7,13 @@## Rights, before anything is read or written:# 1. write on meetings in the project of the route: the area gate of-# ProjectController and authorize @meeting, :update?;-# 2. view_people: authorize Person, :index? (the directory itself);-# 3. creating a person needs manage_people, which the actor asks again.+# ProjectController;+# 2. MeetingPolicy#link_participants?: the meeting write again, plus+# view_people (the dialog lists the directory). The participant row asks+# the same policy to show its link action;+# 3. creating a person needs manage_people, which the actor asks.# The actor resolves every id (Actors::LinkMeetingParticipant) and takes the-# meeting's row lock: a meeting moved out of this project meanwhile is a 404.+# meeting's row lock: a meeting moved out of this project meanwhile is gone.module Organisationsclass MeetingParticipantLinksController < Organisations::BaseControllerinclude ProjectController@@ -20,18 +22,16 @@ module OrganisationsMODAL_TOKEN = /\A\h{16}\z/# How many people the dialog lists besides the suggestions.LIST_LIMIT = 20- # A choice of the dialog: a person row, a member, or a new person.- CHOICE = /\A(?<kind>person|member):(?<id>\h{8}-\h{4}-\h{4}-\h{4}-\h{12})\z/- NEW_PERSON = 'new'INTERNAL_CODES = %i[internal_error].freezeNOT_FOUND_CODES = %i[not_found].freeze+ # The token first: an answer for a meeting that is gone still closes the+ # dialog instance that asked.+ before_action :read_modal_token, only: %i[create destroy]before_action :set_meeting_and_participant+ before_action :authorize_linkdef new- authorize @meeting, :update?- authorize Person, :index?-@query = scalar_param(:q).to_sif request.headers['Turbo-Frame'] == helpers.participant_link_results_id(@participant)render partial: 'organisations/meeting_participant_links/results',@@ -44,10 +44,6 @@ module Organisationsenddef create- authorize @meeting, :update?- authorize Person, :index?-- @modal_token = scalar_param(:modal_token).to_s[MODAL_TOKEN]@choice = scalar_param(:choice)@new_person_name = scalar_param(:new_person_name)result = ::Actors::LinkMeetingParticipant.call(**actor_arguments, **choice_arguments)@@ -57,10 +53,6 @@ module Organisationsenddef destroy- authorize @meeting, :update?- authorize Person, :index?-- @modal_token = scalar_param(:modal_token).to_s[MODAL_TOKEN]result = ::Actors::LinkMeetingParticipant.call(**actor_arguments, unlink: true)return changed(t('flash.meeting_participant_links.unlinked')) if result.success?@@ -75,24 +67,40 @@ module Organisations:meetingsend+ def read_modal_token+ @modal_token = scalar_param(:modal_token).to_s[MODAL_TOKEN]+ end+# Scoped to the route's project: a meeting of another project or another- # organisation, or a participant of another meeting, is not found.+ # organisation, or a participant of another meeting, is not found. That is+ # also what a dialog or a panel left open meets when the meeting was moved+ # or the participant removed meanwhile, so it gets an answer the dialog can+ # show, not an error page inside the frame.def set_meeting_and_participant- @meeting = @project.meetings.find(params[:meeting_id])- @participant = @meeting.meeting_participants.find(params[:participant_id])+ @meeting_id = params[:meeting_id].to_s+ @meeting = @project.meetings.find_by(id: @meeting_id)+ @participant = @meeting&.meeting_participants&.find_by(id: params[:participant_id])+ gone([t('services.actors.link_meeting_participant.not_found')]) if @participant.nil?+ end++ def authorize_link+ authorize @meeting, :link_participants?enddef actor_arguments{ meeting: @meeting, project: @project, participant_id: @participant.id, current_user: current_user }end+ # What the actor gets from the pick. Anything that is no pick is nothing,+ # and the actor answers "nothing picked".def choice_arguments- return { new_person: { name: @new_person_name.to_s } } if @choice == NEW_PERSON-- match = CHOICE.match(@choice.to_s)- return {} unless match-- match[:kind] == 'person' ? { person_id: match[:id] } : { member_id: match[:id] }+ choice = ::Meetings::ParticipantLinkChoice.parse(@choice)+ case choice&.kind+ when :new_person then { new_person: { name: @new_person_name.to_s } }+ when :person then { person_id: choice.id }+ when :member then { member_id: choice.id }+ else {}+ endend# The row of this meeting's participants, the dialog closed, the flash.@@ -111,9 +119,9 @@ module Organisations# meeting moved meanwhile, which the lock reloaded into its new project) closes# the dialog with the reason and draws nothing of the meeting again.def refused(result)- @errors = result.errors- return gone if NOT_FOUND_CODES.include?(result.code)+ return gone(result.errors) if NOT_FOUND_CODES.include?(result.code)+ @errors = result.errorsstatus = INTERNAL_CODES.include?(result.code) ? :internal_server_error : :unprocessable_contentrespond_to do |format|format.turbo_stream { render 'organisations/meeting_participant_links/refused', status: status }@@ -121,10 +129,21 @@ module Organisationsendend- def gone+ # Nothing of the meeting is drawn again: it may be in another project now.+ # A stream closes the dialog with a flash; the frame of the dialog (new)+ # shows the reason in place; a plain form submit goes back to the meetings.+ def gone(errors)+ @errors = errorsrespond_to do |format|format.turbo_stream { render 'organisations/meeting_participant_links/gone', status: :not_found }- format.html { redirect_to meeting_path, alert: @errors.to_sentence, status: :see_other }+ format.html do+ if action_name == 'new'+ render 'organisations/meeting_participant_links/not_found', layout: false, status: :not_found+ else+ redirect_to organisation_project_meetings_path(current_organisation, @project),+ alert: @errors.to_sentence, status: :see_other+ end+ endendenddiff --git a/app/helpers/meeting_participant_links_helper.rb b/app/helpers/meeting_participant_links_helper.rbindex 0ad2289..d80f437 100644--- a/app/helpers/meeting_participant_links_helper.rb+++ b/app/helpers/meeting_participant_links_helper.rb@@ -3,20 +3,24 @@# The participant row of a meeting and its dialog "Mit Person verknüpfen" (S2b,# Organisations::MeetingParticipantLinksController). The ids are a shared# contract between the row, the dialog and the controller's streams: they live-# here once.+# here once. The rules live elsewhere, so they can be tested without a page:+# who is linked through an account (Meetings::AccountParticipants), the lines of+# the dialog (Meetings::ParticipantLinkOptions), the value of a pick+# (Meetings::ParticipantLinkChoice), the entry of a participant+# (People::Directory#entry_for_participant).module MeetingParticipantLinksHelper# What the row may show the viewer: whether they may link, and for each# participant the address of its person, or nil. Read once per row, from the# viewer's own directory, so a person they may not see stays plain text.- # member_ids: the accounts among the participants with a membership here,- # active or not; their names are linked through the account, not the dialog.- ParticipantPeople = Struct.new(:can_link, :paths, :member_ids, keyword_init: true) do+ ParticipantPeople = Struct.new(:can_link, :paths, :account_participants, keyword_init: true) dodef path_for(participant)paths[participant.id]end+ # The dialog is for free names and contacts. A participant linked through+ # an account belongs to the meeting form.def linkable?(participant)- can_link && (participant.user_id.nil? || !member_ids.include?(participant.user_id))+ can_link && !account_participants.include?(participant)endend@@ -26,15 +30,17 @@ module MeetingParticipantLinksHelperdom_id(meeting, :participants)end- # The frame the dialog loads into, one per meeting, inside the row.- def participant_link_modal_id(meeting)- "meeting-participant-link-modal-#{meeting.id}"+ # The frame the dialog loads into, one per meeting, inside the row. By the+ # meeting's id, not the record: the answer for a meeting that is gone from+ # this project has only the id of its route.+ def participant_link_modal_id(meeting_id)+ "meeting-participant-link-modal-#{meeting_id}"end# One opening of the dialog: a refused save replaces exactly it, a save# removes it, a late answer to a dialog closed meanwhile finds nothing.- def participant_link_modal_instance_id(meeting, token)- "#{participant_link_modal_id(meeting)}-#{token}"+ def participant_link_modal_instance_id(meeting_id, token)+ "#{participant_link_modal_id(meeting_id)}-#{token}"end# The list of the dialog, reloaded by its search.@@ -48,16 +54,18 @@ module MeetingParticipantLinksHelperenddef meeting_participant_people(meeting, participants)- return ParticipantPeople.new(can_link: false, paths: {}, member_ids: Set.new) unless PersonPolicy.view_allowed?(current_user, current_organisation)+ accounts = Meetings::AccountParticipants.new(organisation: current_organisation, participants: participants)+ sees_people = PersonPolicy.view_allowed?(current_user, current_organisation)+ # Without view_people: no person links, no link action.+ return ParticipantPeople.new(can_link: false, paths: {}, account_participants: accounts) unless sees_peopledirectory = People::Directory.new(viewer: current_user, organisation: current_organisation)- paths = participants.each_with_object({}) do |participant, found|- entry = participant_directory_entry(directory, participant)- found[participant.id] = person_entry_path(entry) if entry+ paths = {}+ participants.each do |participant|+ entry = directory.entry_for_participant(participant)+ paths[participant.id] = person_entry_path(entry) if entryend- member_ids = Membership.where(organisation: current_organisation, user_id: participants.filter_map(&:user_id))- .pluck(:user_id).to_set- ParticipantPeople.new(can_link: policy(meeting).update?, paths: paths, member_ids: member_ids)+ ParticipantPeople.new(can_link: policy(meeting).link_participants?, paths: paths, account_participants: accounts)end# The person page of a directory entry: its row, or a member without one.@@ -66,52 +74,26 @@ module MeetingParticipantLinksHelperorganisation_people_path(current_organisation, selection)end- # The lines of the dialog: the suggestions (E6) first, marked, then the- # 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.+ # The lines of the dialog (Meetings::ParticipantLinkOptions), from the+ # viewer's directory.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] }+ Meetings::ParticipantLinkOptions.new(viewer: current_user, organisation: current_organisation,+ participant: participant, query: query, limit: limit,+ choice: choice).linesend- # The value a line of the dialog sends: a member by account, a contact by row.- def participant_link_choice(entry)- entry.member? ? "member:#{entry.user.id}" : "person:#{entry.person.id}"- end-- # The line under a name in the dialog, as in the people list: function and- # company of the row, else a member's email.- def participant_link_detail(entry)- [entry.person&.function, entry.person&.company].compact_blank.join(' · ').presence ||- (entry.user&.email if entry.member?)+ # The name of the person a participant is linked to, or nil when the viewer+ # may not see that person: the dialog then says only that a link exists.+ def participant_link_linked_name(participant)+ entry = People::Directory.new(viewer: current_user, organisation: current_organisation)+ .person_entry(participant.person_id)+ entry && person_display_name(person: entry.person, user: (entry.user if entry.member?))end# The name a new person starts with: the participant's, without a note in- # brackets ("J. Weber (Hoster)" -> "J. Weber").+ # brackets ("J. Weber (Hoster)" -> "J. Weber"). A name that is only a note+ # stays as it is, so the field is never empty.def participant_link_new_name(participant)- participant.display_name.gsub(/\([^)]*\)/, ' ').squish.presence || participant.display_name- end-- 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)- elsif participant.person_id- directory.person_entry(participant.person_id)- end+ PersonName.without_note(participant.display_name).presence || participant.display_nameendenddiff --git a/app/models/CLAUDE.md b/app/models/CLAUDE.mdindex eff0cc6..5212bd1 100644--- a/app/models/CLAUDE.md+++ b/app/models/CLAUDE.md@@ -66,12 +66,18 @@ Verzeichnis-Layout nicht ablesbar — diese Karte gruppiert sie:Seit S2b (27.10.2026) setzt `person_id` nur `Actors::LinkMeetingParticipant` (Dialog anden Teilnehmer-Chips, `MeetingParticipantLinksController`): EIN Schlüssel je Teilnehmer,ein Mitglied über `user_id`, ein Kontakt (auch die Zeile eines deaktivierten Mitglieds)- über `person_id`. Der Teilnehmer eines Mitglieds, dessen Mitgliedschaft entfernt ist, ist- wieder ein Name: der Dialog verknüpft ihn als Kontakt und leert die `user_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. 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.+ über `person_id`. Die Regel steht dreifach fest: Validierung `one_key`, Check-Constraint+ `meeting_participants_one_key` (fängt auch `update_all`), und jeder Schreiber leert den+ anderen Schlüssel selbst. Der Teilnehmer eines Mitglieds, dessen Mitgliedschaft entfernt+ ist, ist wieder ein Name: der Dialog verknüpft ihn als Kontakt und leert die `user_id`.+ Wer über ein Konto verknüpft ist, entscheidet EINE Stelle (`Meetings::AccountParticipants`):+ Mitglied per `user_id` (aktiv oder nicht) oder Kontakt, dessen Zeile inzwischen einem+ aktiven Mitglied gehört; den lässt der Dialog in Ruhe. 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. Macht das Formular eine Kontakt-Zeile zu der eines Mitglieds,+ fällt `person_id` weg, und das Zuordnen (Scope `external`) lässt Kontakt-Zeilen aus.+ Reihenfolge der Chip-Zeile: Scope `in_row_order` (Seite, Panel und Neuzeichnen).* **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/models/meeting_participant.rb b/app/models/meeting_participant.rbindex ffe032a..da2cdee 100644--- a/app/models/meeting_participant.rb+++ b/app/models/meeting_participant.rb@@ -61,17 +61,26 @@ class MeetingParticipant < ApplicationRecordvalidates :normalized_name, uniqueness: { scope: :meeting_id }, allow_blank: truevalidates :user_id, uniqueness: { scope: :meeting_id }, allow_nil: truevalidate :person_in_same_organisation, if: -> { person_id.present? && will_save_change_to_person_id? }+ validate :one_key- # External (name-only) participants in the given projects — the ONE definition of- # "an external participation eligible to be claimed", shared by the claim matcher- # (counts them) and the claim actor (links them). Callers pass an already- # access-scoped project_ids list. A name linked to a contact of the people- # directory (person_id) is that contact, not a free name: one key per- # participant, the link dialog relinks it.+ # A free name: neither a member (user_id) nor a contact of the people+ # directory (person_id). The ONE definition of "external", read by the claim+ # matcher (counts them) and the claim actor (links them, and asks again in+ # its UPDATE). A name linked to a contact is that contact, not a free name a+ # member could claim: one key per participant (see #one_key).+ scope :external, -> { where(user_id: nil, person_id: nil) }++ # External participants in the given projects. Callers pass an already+ # access-scoped project_ids list.scope :external_in_projects, lambda { |project_ids|- where(user_id: nil, person_id: nil).joins(:meeting).where(meetings: { project_id: project_ids })+ external.joins(:meeting).where(meetings: { project_id: project_ids })}+ # The order of the participant row: as they were added. The meeting page,+ # the panel beside a ticket and the redraw after a link (the stream replaces+ # the row in place) must agree, or the chips jump.+ scope :in_row_order, -> { order(:created_at) }+# Normalization contract: PersonName.normalize, the one normalizer shared# with the people directory (mirrored in name_normalizer.js). Pure function so# the contract spec can call it directly.@@ -107,4 +116,15 @@ class MeetingParticipant < ApplicationRecorderrors.add(:person, :invalid)end++ # One key per participant: a member is linked by user_id, a contact by+ # person_id, never both. With both, the person's lane would count the meeting+ # for the contact AND the member, and every writer would have to decide which+ # key wins. The writers (Actors::LinkMeetingParticipant, SaveMeeting,+ # ClaimMeetingParticipants) clear the other key themselves; this validation+ # names a writer that forgets, and the check constraint+ # meeting_participants_one_key catches a write past the model (update_all).+ def one_key+ errors.add(:base, :one_key) if user_id.present? && person_id.present?+ endenddiff --git a/app/models/person_name.rb b/app/models/person_name.rbindex bed56fc..38e3deb 100644--- a/app/models/person_name.rb+++ b/app/models/person_name.rb@@ -15,4 +15,14 @@ module PersonNames = s.downcases.gsub('ä', 'ae').gsub('ö', 'oe').gsub('ü', 'ue').gsub('ß', 'ss')end++ # A name without its notes in round brackets: "J. Weber (Hoster)" ->+ # "J. Weber". A meeting participant is often written with a note about the+ # role; the note is no part of the person's name. The surname of a+ # suggestion (People::Directory.surname) and the name a new person starts+ # with in the link dialog both read it, so the two never disagree. Empty+ # when the name is only a note.+ def self.without_note(value)+ value.to_s.gsub(/\([^)]*\)/, ' ').squish+ endenddiff --git a/app/policies/meeting_policy.rb b/app/policies/meeting_policy.rbindex 897f130..3ee5425 100644--- a/app/policies/meeting_policy.rb+++ b/app/policies/meeting_policy.rb@@ -41,6 +41,14 @@ class MeetingPolicy < ApplicationPolicyproject_policy.area_access?(:meetings, :write)end+ # Linking a participant to the people directory (S2b): a meeting write, and+ # the directory itself (view_people), because the dialog lists it. The+ # controller authorizes with this, and the participant row asks the same to+ # show its link action, so the button and the server cannot disagree.+ def link_participants?+ update? && PersonPolicy.view_allowed?(user, organisation)+ end+def destroy?account_admin? || project_policy.area_access?(:meetings, :write)enddiff --git a/app/services/CLAUDE.md b/app/services/CLAUDE.mdindex 2e2306d..b65407b 100644--- a/app/services/CLAUDE.md+++ b/app/services/CLAUDE.md@@ -164,10 +164,15 @@ Verzeichnis-Übersicht (Auswahl):aktiven Mitgliedern zählt eigene Ticket-Arbeit (`TICKET_ACTIONS`: angelegt, geändert,kommentiert), bei Kontakten nur Meetings. `Directory#entries` hängt den Kontakt an undsortiert nach `name` oder `last`.- S2b (27.10.2026): `Directory#person_entry`, `#candidates` (Suche ohne Kontakt) und- `#suggestions_for` (gleicher Name vor gleichem Nachnamen, E6) speisen den Dialog- „Mit Person verknüpfen“; geschrieben wird über `Actors::LinkMeetingParticipant`, der- jede ID über das gesperrte Meeting und das Directory des Schreibenden auflöst.+ S2b (27.10.2026): `Directory#person_entry`, `#entry_for_participant`, `#candidates`+ (Suche ohne Kontakt) und `#suggestions_for` (gleicher Name vor gleichem Nachnamen, E6)+ speisen den Dialog „Mit Person verknüpfen“. Seine Regeln liegen außerhalb des Helfers,+ einzeln testbar: `meetings/participant_link_options.rb` (Zeilen des Dialogs),+ `meetings/participant_link_choice.rb` (das Format `person:`/`member:`/`new`, einmal),+ `meetings/account_participants.rb` (wen der Dialog in Ruhe lässt). Die Zeile unter einem+ Namen ist `Directory::Entry#detail` (Liste und Dialog). Geschrieben wird über+ `Actors::LinkMeetingParticipant`, der jede ID über das gesperrte Meeting und das+ Directory des Schreibenden auflöst.* `notifications/` — Empfänger-Fanout, Broadcast, Scoring (eigene Karte im Ordner); dazu`inbox_query.rb` + `serializer.rb`, der EINE Besitzer der Token-Inbox (Reichweite,Argument-Vertrag, Zeilen-JSON), geteilt von `GET /api/v1/notifications` und demdiff --git a/app/services/actors/claim_meeting_participants.rb b/app/services/actors/claim_meeting_participants.rbindex 4142b34..6645a0e 100644--- a/app/services/actors/claim_meeting_participants.rb+++ b/app/services/actors/claim_meeting_participants.rb@@ -2,11 +2,11 @@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 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+ # participations to an org member (Nachtrag: Teilnehmer-Claim). It sets user_id+ # on every external row (no user_id and no person_id, MeetingParticipant.external)+ # 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# changes), consistent with the model's snapshot principle.## The read side (which names match which members) is Meetings::ParticipantClaimMatches;@@ -49,9 +49,9 @@ module Actors# and this UPDATE — the RecordNotUnique rescue below turns that race into a# clean, retryable failure.# intentional bulk link; see comment above- # Read again in the write: the link dialog may have given one of these rows- # a contact (person_id) in between, and a row keeps one key.- @linked_count = MeetingParticipant.where(id: ids, user_id: nil, person_id: nil)+ # Asks .external again in the write: the link dialog may have given one of+ # these rows a contact (person_id) in between, and a row keeps one key.+ @linked_count = MeetingParticipant.external.where(id: ids).update_all(user_id: @user.id, updated_at: Time.current)rescue ActiveRecord::RecordNotUnique# Another write linked this member to a target meeting between the skip-checkdiff --git a/app/services/actors/link_meeting_participant.rb b/app/services/actors/link_meeting_participant.rbindex 90e7a78..a964078 100644--- a/app/services/actors/link_meeting_participant.rb+++ b/app/services/actors/link_meeting_participant.rb@@ -6,14 +6,14 @@# (S2b). Afterwards the person's lane lists the meeting and counts it for# "Letzter Kontakt" (People::Contacts reads both keys).#-# One key per participant: a member is linked by user_id (the path the meeting-# form already uses), a contact by person_id. The row of a FORMER member is a-# contact, as the directory shows it. A participant of someone with a-# membership here is linked through its account and is left alone; one whose-# membership was removed may be linked as a contact.+# One key per participant (MeetingParticipant#one_key): a member is linked by+# user_id (the path the meeting form already uses), a contact by person_id. The+# row of a FORMER member is a contact, as the directory shows it. A participant+# linked through an account (Meetings::AccountParticipants) is left alone: the+# meeting form owns that link.#-# The caller authorizes the meeting write (MeetingPolicy#update?). This actor-# resolves every id itself, so a raw id never reaches a column:+# The caller authorizes the meeting write (MeetingPolicy#link_participants?).+# This actor resolves every id itself, so a raw id never reaches a column:# * the meeting under its row lock (Meeting#lock_in_project!): a meeting moved# out of the authorized project is gone, as is a participant of another one;# * the person or member through the writer's own directory (People::Directory:@@ -48,12 +48,13 @@ module Actors# participants without the meeting lock.@participant = @meeting.meeting_participants.lock.find_by(id: @participant_id)refuse!(:not_found) if @participant.nil?- # A member participant is linked by its account; the meeting form owns that.- refuse!(:member_participant) if member_participant?+ refuse!(:member_participant) if linked_through_account?- return @participant.update!(person_id: nil) if @unlink-- link_to_entry(chosen_entry)+ if @unlink+ @participant.update!(person_id: nil)+ else+ link_participant_to(chosen_entry)+ endendprivate@@ -64,55 +65,83 @@ module Actors@meeting.organisationend+ def linked_through_account?+ Meetings::AccountParticipants.new(organisation: organisation, participants: [@participant])+ .include?(@participant)+ end+def chosen_entryreturn created_entry if @new_person- return directory.member_entry(@member_id) || refuse!(:not_found) if @member_id- return directory.person_entry(@person_id) || refuse!(:not_found) if @person_id- refuse!(:nothing_picked)+ refuse!(:nothing_picked) if @member_id.nil? && @person_id.nil?++ entry = @member_id ? directory.member_entry(@member_id) : directory.person_entry(@person_id)+ # Someone the writer may not see is no one: the same answer as a wrong id.+ refuse!(:not_found) if entry.nil?+ entryend- def link_to_entry(entry)+ def link_participant_to(entry)if entry.member?- refuse!(:member_already_participant) if taken_by_another?(entry.user.id)- refuse!(:member_name_taken) if name_taken_by_another?(entry.user.display_name)- @participant.update!(user_id: entry.user.id, person_id: nil)+ link_member(entry.user)else- @participant.update!(person_id: entry.person.id, user_id: nil)+ link_contact(entry.person)end+ end++ # A member is linked by account. The model validates "one member once per+ # meeting" too; this check comes first to answer with its own reason+ # instead of a validation message.+ def link_member(user)+ refuse!(:member_already_participant) if other_participants.exists?(user_id: user.id)+ refuse!(:member_name_taken) if name_shown_by_another?(user.display_name)++ @participant.update!(user_id: user.id, person_id: nil)rescue ActiveRecord::RecordNotUnique- # 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.+ # Only a write that skips the meeting lock gets here (the lock runs two+ # links one after the other, so the check above sees the first). The+ # partial unique index (meeting_id, user_id) refuses it, with the same answer.refuse!(:member_already_participant)end- # A participant of someone with a membership here, active or not. One whose- # membership was removed is a name again (their row lost its account through- # PersonLinkRelease): it may be linked as a contact, and its account goes.- def member_participant?- @participant.user_id.present? &&- Membership.where(organisation: organisation, user_id: @participant.user_id).exists?+ # A contact is linked by its row, and one row only once per meeting: two+ # participants of one person would count the meeting twice in the person's+ # lane. No unique index backs this, because only this actor writes+ # person_id, and it runs under the meeting lock.+ def link_contact(person)+ refuse!(:person_already_participant) if other_participants.exists?(person_id: person.id)++ @participant.update!(person_id: person.id, user_id: nil)end- def taken_by_another?(user_id)- @meeting.meeting_participants.where(user_id: user_id).where.not(id: @participant.id).exists?+ def other_participants+ @meeting.meeting_participants.where.not(id: @participant.id)end- # The meeting form labels a member chip with the member's profile name- # (MeetingsController#meeting_participant_options); a second participant of- # that name would make every later save of the meeting fail on its unique- # name (SaveMeeting#guard_against_duplicates!).- def name_taken_by_another?(name)- @meeting.meeting_participants.where(normalized_name: PersonName.normalize(name))- .where.not(id: @participant.id).exists?+ # The meeting form shows a member under the profile name+ # (MeetingsController#meeting_participant_options) and refuses two+ # participants of one name (SaveMeeting#guard_against_duplicates!), so a+ # member whose name another participant shows would make every later save+ # of the meeting fail. Another participant shows its own name, or, when it+ # is a member, that member's profile name: both count. That is stricter+ # than the form in one rare case (a member outside the project, which the+ # form shows under its own name), and a refusal there is harmless.+ def name_shown_by_another?(name)+ wanted = PersonName.normalize(name)+ other_participants.includes(:user).any? do |other|+ other.normalized_name == wanted || (other.user && PersonName.normalize(other.user.display_name) == wanted)+ endenddef created_entryrefuse!(:not_allowed) unless PersonPolicy.manage_allowed?(current_user, organisation)+ # The dialog sends a name only; everything else is the person page's.params = @new_person.to_h.symbolize_keys.slice(:name)result = Actors::SavePerson.call(organisation: organisation, params: params, current_user: current_user)- raise ActorError.new(result.errors, code: :validation_failed) unless result.success?+ # Its own code: a stale or an internal failure of SavePerson is no+ # validation failure, and the controller answers our own failure with 500.+ raise ActorError.new(result.errors, code: result.code) unless result.success?People::Directory::Entry.new(kind: :contact, person: result.resource)enddiff --git a/app/services/actors/save_meeting.rb b/app/services/actors/save_meeting.rbindex 33058a3..8d22816 100644--- a/app/services/actors/save_meeting.rb+++ b/app/services/actors/save_meeting.rb@@ -155,8 +155,6 @@ 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@@ -172,7 +170,10 @@ module Actorsparticipant ||= @meeting.meeting_participants.buildparticipant.organisation = orgparticipant.display_name = d[:display_name]- participant.person_id = nil if d[:user_id] && d[:user_id] != participant.user_id+ # A row the form gives to a member is that member now, and a contact link+ # on it goes: one key per participant (MeetingParticipant#one_key).+ becomes_member = d[:user_id].present? && d[:user_id] != participant.user_id+ participant.person_id = nil if becomes_memberparticipant.user_id = d[:user_id]participant.save!end@@ -183,8 +184,8 @@ module Actors# 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 (a contact link on it goes, see reconcile_participants), 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+ # 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)diff --git a/app/services/meetings/account_participants.rb b/app/services/meetings/account_participants.rbnew file mode 100644index 0000000..9ab421f--- /dev/null+++ b/app/services/meetings/account_participants.rb@@ -0,0 +1,69 @@+# frozen_string_literal: true++# Which participants of a meeting are linked through an account (S2b of the+# people directory). Their link belongs to the meeting form, which offers+# members by account; the link dialog leaves them alone. One owner for the+# rule, asked by the actor that writes (Actors::LinkMeetingParticipant refuses+# them) and by the participant row that offers the dialog+# (MeetingParticipantLinksHelper#meeting_participant_people hides its action).+#+# Entry point: include?+module Meetings+ class AccountParticipants+ def initialize(organisation:, participants:)+ @organisation = organisation+ @participants = participants+ end++ # True for a participant that is+ # * a member by user_id, with a membership here, ACTIVE OR NOT: a+ # deactivated member keeps the account, and it comes back with the+ # membership. Once the membership is removed, the participant is a name+ # again (the dialog may link it to the row that keeps their meetings);+ # * a contact by person_id whose row belongs to an ACTIVE member now: the+ # row was linked to a member after the participant was linked to it+ # (SavePerson#assign_link, or a deactivated member came back). The+ # participant is that member, and a writer who may not see the member+ # must not be able to unlink or overwrite it. A row of a deactivated+ # member is a contact, as the directory shows it, so linking to it+ # stays possible.+ def include?(participant)+ ids.include?(participant.id)+ end++ private++ def ids+ @ids ||= @participants.select { |participant| through_account?(participant) }.to_set(&:id)+ end++ def through_account?(participant)+ if participant.user_id+ member_user_ids.include?(participant.user_id)+ elsif participant.person_id+ rows_of_active_members.include?(participant.person_id)+ else+ false+ end+ end++ def member_user_ids+ @member_user_ids ||= begin+ user_ids = @participants.filter_map(&:user_id)+ user_ids.empty? ? Set.new : Membership.where(organisation: @organisation, user_id: user_ids).pluck(:user_id).to_set+ end+ end++ def rows_of_active_members+ @rows_of_active_members ||= begin+ person_ids = @participants.filter_map(&:person_id)+ if person_ids.empty?+ Set.new+ else+ active_members = Membership.where(organisation: @organisation, active: true).select(:user_id)+ Person.where(organisation: @organisation, id: person_ids, user_id: active_members).pluck(:id).to_set+ end+ end+ end+ end+enddiff --git a/app/services/meetings/participant_claim_matches.rb b/app/services/meetings/participant_claim_matches.rbindex 0a3912d..9b193cb 100644--- a/app/services/meetings/participant_claim_matches.rb+++ b/app/services/meetings/participant_claim_matches.rb@@ -3,8 +3,9 @@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 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+ # (no user_id and no person_id, 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# Actors::ClaimMeetingParticipants.diff --git a/app/services/meetings/participant_link_choice.rb b/app/services/meetings/participant_link_choice.rbnew file mode 100644index 0000000..c27ffb5--- /dev/null+++ b/app/services/meetings/participant_link_choice.rb@@ -0,0 +1,34 @@+# frozen_string_literal: true++# The value one line of the link dialog sends (S2b): "person:<id>" for a row of+# the people directory, "member:<id>" for a member (by account, also one+# without a row), "new" for a person created in the same step. The dialog+# writes it (value_for), the controller reads it, and so does the dialog when+# it draws a refused pick again (parse). The format lives here once, so the+# writer and the two readers cannot drift apart.+#+# Entry point: parse+module Meetings+ module ParticipantLinkChoice+ NEW_PERSON = 'new'+ # Only a canonical id counts: the controller hands the id to the actor,+ # which looks it up in the writer's directory.+ PICK = /\A(?<kind>person|member):(?<id>\h{8}-\h{4}-\h{4}-\h{4}-\h{12})\z/++ # kind: :person, :member or :new_person; id: nil for :new_person.+ Choice = Data.define(:kind, :id)++ def self.value_for(entry)+ entry.member? ? "member:#{entry.user.id}" : "person:#{entry.person.id}"+ end++ # The choice a value names, or nil for anything else (nothing picked, a+ # tampered value, a nested parameter).+ def self.parse(value)+ return Choice.new(kind: :new_person, id: nil) if value == NEW_PERSON++ match = PICK.match(value.to_s)+ Choice.new(kind: match[:kind].to_sym, id: match[:id]) if match+ end+ end+enddiff --git a/app/services/meetings/participant_link_options.rb b/app/services/meetings/participant_link_options.rbnew file mode 100644index 0000000..9a511d3--- /dev/null+++ b/app/services/meetings/participant_link_options.rb@@ -0,0 +1,51 @@+# frozen_string_literal: true++# The lines of the link dialog for one meeting participant (S2b, E6), read from+# the viewer's own directory (People::Directory), so nobody the viewer may not+# see is listed:+# * without a search, the suggestions first (same full name, then same+# surname), marked as such;+# * then everyone the search finds, at most `limit` of them;+# * a pick that came back with a refusal (choice) is drawn again checked. It+# must be in the list for that, and in it once: wherever the search found it,+# or ahead of the others when it lies past the limit.+#+# Entry point: lines+module Meetings+ class ParticipantLinkOptions+ Line = Data.define(:entry, :suggested) do+ def suggested? = suggested+ end++ def initialize(viewer:, organisation:, participant:, query:, limit:, choice: nil)+ @directory = People::Directory.new(viewer: viewer, organisation: organisation, query: query)+ @participant = participant+ @query = query+ @limit = limit+ @choice = choice+ end++ def lines+ suggested = @query.blank? ? @directory.suggestions_for(@participant.display_name) : []+ others = (@directory.candidates - suggested).first(@limit)++ picked = picked_entry+ already_listed = suggested.include?(picked) || others.include?(picked)+ others.unshift(picked) if picked && !already_listed++ suggested.map { |entry| Line.new(entry: entry, suggested: true) } ++ others.map { |entry| Line.new(entry: entry, suggested: false) }+ end++ private++ # The entry the refused pick names, through the same directory, or nil.+ def picked_entry+ choice = ParticipantLinkChoice.parse(@choice)+ case choice&.kind+ when :person then @directory.person_entry(choice.id)+ when :member then @directory.member_entry(choice.id)+ end+ end+ end+enddiff --git a/app/services/people/directory.rb b/app/services/people/directory.rbindex 035dcd2..ba83ec2 100644--- a/app/services/people/directory.rb+++ b/app/services/people/directory.rb@@ -36,6 +36,15 @@ module Peopledef plain_namemember? ? user.display_name : person.nameend++ # The line under the name, in the list and in the link dialog: function+ # and company of the row, else a member's email. A contact without+ # either has none (nil). A contact never shows an email here: the row's+ # own email is a field of its page, not a label.+ def detail+ [person&.function, person&.company].compact_blank.join(' · ').presence ||+ (user&.email if member?)+ endenddef initialize(viewer:, organisation:, query: nil, kind: 'all', sort: 'name')@@ -86,6 +95,20 @@ module Peopleeveryone.find { |entry| !entry.member? && entry.person&.user_id == user_id.to_s }end+ # The entry a meeting participant stands for, or nil when the viewer may+ # not see it (or it is a free name). A participant carries one key:+ # * user_id: the member, or, once the membership is gone or inactive, the+ # row that keeps their meetings (former_member_entry);+ # * person_id: that row, which is a member's entry when the row belongs to+ # an active member (person_entry).+ def entry_for_participant(participant)+ if participant.user_id+ member_entry(participant.user_id) || former_member_entry(participant.user_id)+ elsif participant.person_id+ person_entry(participant.person_id)+ end+ end+# The entries matching the search, without last contacts: the list of the# dialog that links a meeting participant (S2b).def candidates@@ -108,7 +131,7 @@ module People# The last word of a name, normalized, without a note in brackets and# without initials: "J. Weber (Hoster)" -> "weber". Nil without one.def self.surname(name)- words = PersonName.normalize(name).gsub(/\([^)]*\)/, ' ').scan(/[[:alpha:]][[:alpha:]'-]*/)+ words = PersonName.normalize(PersonName.without_note(name)).scan(/[[:alpha:]][[:alpha:]'-]*/)words.reverse.find { |word| word.length > 1 }enddiff --git a/app/views/organisations/meeting_participant_links/_modal.html.erb b/app/views/organisations/meeting_participant_links/_modal.html.erbindex 8350295..8fd4bae 100644--- a/app/views/organisations/meeting_participant_links/_modal.html.erb+++ b/app/views/organisations/meeting_participant_links/_modal.html.erb@@ -9,10 +9,10 @@DELETE. Everything listed comes from the viewer's own directory (People::Directory):nothing hidden is shown or counted. %><% pl = 'views.organisations.meetings.participant_links' %>-<% modal_id = participant_link_modal_id(meeting) %>+<% modal_id = participant_link_modal_id(meeting.id) %><% form_id = "#{modal_id}-form" %><% can_create = PersonPolicy.manage_allowed?(current_user, current_organisation) %>-<div id="<%= participant_link_modal_instance_id(meeting, token) %>"+<div id="<%= participant_link_modal_instance_id(meeting.id, token) %>"data-controller="participant-link-modal"data-participant-link-modal-return-id-value="<%= participant_link_trigger_id(participant) %>"data-action="keydown@window->participant-link-modal#closeOnEscape keydown@window->participant-link-modal#trapFocus">@@ -49,10 +49,10 @@<% end %><% if participant.person_id %>- <% current = People::Directory.new(viewer: current_user, organisation: current_organisation).person_entry(participant.person_id) %>+ <% linked_name = participant_link_linked_name(participant) %><div class="flex items-center justify-between gap-3 rounded border border-cream-200 bg-cream-50 px-3 py-2 text-sm"><span class="min-w-0 break-words text-cream-800">- <%= current ? t("#{pl}.linked_to", name: person_display_name(person: current.person, user: (current.user if current.member?))) : t("#{pl}.linked") %>+ <%= linked_name ? t("#{pl}.linked_to", name: linked_name) : t("#{pl}.linked") %></span><%= button_to t("#{pl}.unlink"),organisation_project_meeting_participant_link_path(current_organisation, meeting.project, meeting, participant),@@ -81,9 +81,9 @@meeting: meeting, participant: participant, query: query, choice: choice %><% if can_create %>- <% new_checked = choice == Organisations::MeetingParticipantLinksController::NEW_PERSON %>+ <% new_person = Meetings::ParticipantLinkChoice::NEW_PERSON %><div class="participant-link-option participant-link-option--new flex items-center gap-3 rounded px-2 py-2 hover:bg-cream-100">- <%= radio_button_tag :choice, Organisations::MeetingParticipantLinksController::NEW_PERSON, new_checked,+ <%= radio_button_tag :choice, new_person, choice == new_person,id: "#{modal_id}-new", class: 'shrink-0' %><span class="flex min-w-0 flex-1 flex-col gap-1"><label for="<%= modal_id %>-new" class="text-sm font-medium text-ink">diff --git a/app/views/organisations/meeting_participant_links/_results.html.erb b/app/views/organisations/meeting_participant_links/_results.html.erbindex be790b7..c722575 100644--- a/app/views/organisations/meeting_participant_links/_results.html.erb+++ b/app/views/organisations/meeting_participant_links/_results.html.erb@@ -1,17 +1,18 @@<%# locals: (meeting:, participant:, query:, choice: nil) %><%# The people the dialog offers, in their own frame so the search reloads only them: thesuggestions first (E6, only without a search), then the people matching the search.- Members are offered by account, contacts by row (participant_link_choice). Picking one- only marks it; "Verknüpfen" links. %>+ Members are offered by account, contacts by row (Meetings::ParticipantLinkChoice). 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, choice: choice) %>+<% lines = 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? %>+ <% if lines.empty? %><p class="participant-link-none px-2 py-2 text-sm text-cream-600"><%= t("#{pl}.none") %></p><% else %><ul class="participant-link-options max-h-72 space-y-0.5 overflow-y-auto" role="list">- <% options.each do |entry, suggested| %>- <% value = participant_link_choice(entry) %>+ <% lines.each do |line| %>+ <% entry = line.entry %>+ <% value = Meetings::ParticipantLinkChoice.value_for(entry) %><% input_id = "#{participant_link_results_id(participant)}-#{value.tr(':', '-')}" %><% name = person_display_name(person: entry.person, user: (entry.user if entry.member?)) %><li class="participant-link-option flex items-center gap-3 rounded px-2 py-2 hover:bg-cream-100">@@ -26,12 +27,12 @@<span class="people-badge"><%= t('views.organisations.people.index.member_badge') %></span><% end %></span>- <% detail = participant_link_detail(entry) %>+ <% detail = entry.detail %><% if detail.present? %><span class="truncate text-xs text-cream-600"><%= detail %></span><% end %></label>- <% if suggested %>+ <% if line.suggested? %><span class="participant-link-suggestion shrink-0 rounded-full border border-amber-500 px-2 text-xs text-cream-700"><%= t("#{pl}.suggestion") %></span><% end %></li>diff --git a/app/views/organisations/meeting_participant_links/_row_stream.turbo_stream.erb b/app/views/organisations/meeting_participant_links/_row_stream.turbo_stream.erbindex 55e5682..68573af 100644--- a/app/views/organisations/meeting_participant_links/_row_stream.turbo_stream.erb+++ b/app/views/organisations/meeting_participant_links/_row_stream.turbo_stream.erb@@ -2,7 +2,7 @@<%# The chips of this meeting as they are now, wherever the page shows them (the meeting'spage or the panel beside a ticket). Only the chips: the dialog frame beside them stays, sothis answer cannot close a dialog opened after it was sent. %>-<% participants = meeting.meeting_participants.order(:created_at).to_a %>+<% participants = meeting.meeting_participants.in_row_order.to_a %><%= turbo_stream.replace meeting_participant_chips_id(meeting),partial: 'organisations/meetings/participant_chips',locals: { meeting: meeting, participants: participants,diff --git a/app/views/organisations/meeting_participant_links/changed.turbo_stream.erb b/app/views/organisations/meeting_participant_links/changed.turbo_stream.erbindex 07b9508..3a6a8a0 100644--- a/app/views/organisations/meeting_participant_links/changed.turbo_stream.erb+++ b/app/views/organisations/meeting_participant_links/changed.turbo_stream.erb@@ -2,7 +2,7 @@removed (its controller then empties the frame and returns the focus), the participantrow redrawn, the flash. %><% if @modal_token %>- <%= turbo_stream.remove participant_link_modal_instance_id(@meeting, @modal_token) %>+ <%= turbo_stream.remove participant_link_modal_instance_id(@meeting.id, @modal_token) %><% end %><%= render 'organisations/meeting_participant_links/row_stream', meeting: @meeting %><%= turbo_stream.prepend 'flash', partial: 'layouts/flash', locals: { flash: @flash_message } %>diff --git a/app/views/organisations/meeting_participant_links/gone.turbo_stream.erb b/app/views/organisations/meeting_participant_links/gone.turbo_stream.erbindex fd21283..2248995 100644--- a/app/views/organisations/meeting_participant_links/gone.turbo_stream.erb+++ b/app/views/organisations/meeting_participant_links/gone.turbo_stream.erb@@ -1,8 +1,9 @@-<%# Not found: a person or member out of the writer's reach, or a meeting moved meanwhile (the- lock reloaded it into its new project). The dialog instance goes and the reason comes as a- flash; nothing of the meeting is drawn again, so a moved meeting shows nothing of the- project it is in now. %>+<%# Not found: a person or member out of the writer's reach, a participant removed, or a meeting+ moved meanwhile (before the request: the lookup; during it: the lock). The dialog instance+ goes and the reason comes as a flash. Nothing of the meeting is drawn again, so a moved+ meeting shows nothing of the project it is in now; the instance is named by the meeting id+ of the route, because the meeting itself may not be found here. %><% if @modal_token %>- <%= turbo_stream.remove participant_link_modal_instance_id(@meeting, @modal_token) %>+ <%= turbo_stream.remove participant_link_modal_instance_id(@meeting_id, @modal_token) %><% end %><%= turbo_stream.prepend 'flash', partial: 'layouts/flash', locals: { flash: { alert: @errors.to_sentence } } %>diff --git a/app/views/organisations/meeting_participant_links/new.html.erb b/app/views/organisations/meeting_participant_links/new.html.erbindex b6ccb72..54e20b4 100644--- a/app/views/organisations/meeting_participant_links/new.html.erb+++ b/app/views/organisations/meeting_participant_links/new.html.erb@@ -1,6 +1,6 @@<%# The dialog "Mit Person verknüpfen", loaded into its frame by a trigger of the participantrow (layout: false, only the frame counts). See _modal. %>-<%= turbo_frame_tag participant_link_modal_id(@meeting) do %>+<%= turbo_frame_tag participant_link_modal_id(@meeting.id) do %><%= render 'organisations/meeting_participant_links/modal',meeting: @meeting, participant: @participant, token: @modal_token, query: @query %><% end %>diff --git a/app/views/organisations/meeting_participant_links/not_found.html.erb b/app/views/organisations/meeting_participant_links/not_found.html.erbnew file mode 100644index 0000000..70ebed1--- /dev/null+++ b/app/views/organisations/meeting_participant_links/not_found.html.erb@@ -0,0 +1,6 @@+<%# The meeting or the participant is no longer in this project (moved or deleted while its row+ was open). The answer goes into the dialog's frame, by the meeting id of the route, so the+ row says why instead of Turbo's "Content missing". %>+<%= turbo_frame_tag participant_link_modal_id(@meeting_id) do %>+ <p class="participant-link-gone mt-1 text-sm text-red-800" role="alert"><%= @errors.to_sentence %></p>+<% end %>diff --git a/app/views/organisations/meeting_participant_links/refused.turbo_stream.erb b/app/views/organisations/meeting_participant_links/refused.turbo_stream.erbindex 5732769..184a6e5 100644--- a/app/views/organisations/meeting_participant_links/refused.turbo_stream.erb+++ b/app/views/organisations/meeting_participant_links/refused.turbo_stream.erb@@ -1,10 +1,10 @@-<%# The link was refused (nothing picked, a member already in the meeting, no right to create- a person; not found answers with gone instead): the dialog again with the reason and what was picked, in place- of the instance that sent it. A dialog closed meanwhile has no such element and stays+<%# The link was refused (nothing picked, someone already in the meeting, no right to create+ a person; not found answers with gone instead): the dialog again with the reason and what+ was picked, in place of the instance that sent it. A dialog closed meanwhile has no such element and staysclosed. Without a usable token there is no instance to fill: the reason goes out as aflash, and the row shows the state as it is now. %><% if @modal_token %>- <%= turbo_stream.replace participant_link_modal_instance_id(@meeting, @modal_token) do %>+ <%= turbo_stream.replace participant_link_modal_instance_id(@meeting.id, @modal_token) do %><%= render 'organisations/meeting_participant_links/modal',meeting: @meeting, participant: @participant, token: @modal_token,choice: @choice, new_person_name: @new_person_name, errors: @errors %>diff --git a/app/views/organisations/meetings/_meeting_show.html.erb b/app/views/organisations/meetings/_meeting_show.html.erbindex fa7db88..e25405c 100644--- a/app/views/organisations/meetings/_meeting_show.html.erb+++ b/app/views/organisations/meetings/_meeting_show.html.erb@@ -30,7 +30,7 @@<% end %></div>- <% participants = meeting.meeting_participants.order(:created_at).to_a %>+ <% participants = meeting.meeting_participants.in_row_order.to_a %><%= render 'organisations/meetings/participants_row', meeting: meeting, participants: participants %><% if meeting.organisation&.ai_enabled? %>diff --git a/app/views/organisations/meetings/_participant_chips.html.erb b/app/views/organisations/meetings/_participant_chips.html.erbindex 72305ac..38ae3f2 100644--- a/app/views/organisations/meetings/_participant_chips.html.erb+++ b/app/views/organisations/meetings/_participant_chips.html.erb@@ -34,7 +34,7 @@id: participant_link_trigger_id(participant),class: 'meeting-participant__link inline-flex h-6 w-6 items-center justify-center rounded-full text-cream-600 hover:bg-cream-200 hover:text-ink',title: action_label, aria: { label: action_label },- data: { turbo_frame: participant_link_modal_id(meeting) } do %>+ data: { turbo_frame: participant_link_modal_id(meeting.id) } do %><i class="bi <%= participant.person_id ? 'bi-pencil' : 'bi-link-45deg' %>" aria-hidden="true"></i><% end %><% end %>diff --git a/app/views/organisations/meetings/_participants_row.html.erb b/app/views/organisations/meetings/_participants_row.html.erbindex 7a39ee5..32bb618 100644--- a/app/views/organisations/meetings/_participants_row.html.erb+++ b/app/views/organisations/meetings/_participants_row.html.erb@@ -16,7 +16,7 @@</span><%= render 'organisations/meetings/participant_chips', meeting: meeting, participants: participants, people: people %><% if people.can_link %>- <%= turbo_frame_tag participant_link_modal_id(meeting) %>+ <%= turbo_frame_tag participant_link_modal_id(meeting.id) %><% end %></div><% end %>diff --git a/app/views/organisations/people/_row.html.erb b/app/views/organisations/people/_row.html.erbindex ce45b97..705dbde 100644--- a/app/views/organisations/people/_row.html.erb+++ b/app/views/organisations/people/_row.html.erb@@ -26,7 +26,7 @@<span class="people-badge"><%= t('views.organisations.people.index.member_badge') %></span><% end %></span>- <% sub = [person&.function, person&.company].compact_blank.join(' · ').presence || (entry.user&.email if entry.member?) %>+ <% sub = entry.detail %><% if sub %><span class="people-row__sub"><%= sub %></span><% end %>diff --git a/app/views/organisations/tickets/_meeting_panel.html.erb b/app/views/organisations/tickets/_meeting_panel.html.erbindex aa6dcd8..d8f84a2 100644--- a/app/views/organisations/tickets/_meeting_panel.html.erb+++ b/app/views/organisations/tickets/_meeting_panel.html.erb@@ -1,11 +1,14 @@<%# locals: (ticket:, meeting:, meetings:, linked_tickets:) %><%# The meeting beside the ticket (doc/ticket_meeting_panel_plan.md, S1), the content of- turbo-frame#ticket_meeting_panel in the grid's third lane. Read only: no edit, no delete,- no analyses, no suggestions, no assistant entry point; "Open meeting" leads to the page- where all of that lives. It does NAME its meeting to the assistant+ turbo-frame#ticket_meeting_panel in the grid's third lane. No edit, no delete, no+ analyses, no suggestions, no assistant entry point; "Open meeting" leads to the page+ where all of that lives. One write lives here: the participant row is the meeting+ page's own (_participants_row), so a writer with view_people can link a participant+ to the people directory from here too (S2b); its dialog loads into a frame of the row+ and redraws only the chips. It does NAME its meeting to the assistant(assistant_context_attributes, S3): the assistant then offers the ticket and, afterit, this meeting, so "what was decided about this ticket?" has both at hand. A name- is not an entry point: nothing here writes, the assistant's own strip asks.+ is not an entry point; the assistant's own strip asks.meetings: every meeting of this ticket the reader may see (Tickets::LinkedMeetings),newest first, as tabs in the head; a tab is a plain link, so it loads into this frame.The close button is the lane's own (NeoTwoColumnGridComponent, layout_toggle#togglePanel);@@ -42,7 +45,7 @@<%= display_time(meeting.occurred_at, user: current_user) %></p>- <% participants = meeting.meeting_participants.order(:created_at).to_a %>+ <% participants = meeting.meeting_participants.in_row_order.to_a %><%= render 'organisations/meetings/participants_row', meeting: meeting, participants: participants %><div class="border-b border-cream-300 mt-4 mb-5"></div>diff --git a/config/locales/models.de.yml b/config/locales/models.de.ymlindex c7521c9..7e3e0c0 100644--- a/config/locales/models.de.yml+++ b/config/locales/models.de.yml@@ -127,6 +127,8 @@ de:content_too_large: "ist zu groß (maximal 1 MB)"duplicate_participant_name: "Ein Teilnehmer wurde doppelt angegeben (gleicher Name)."duplicate_participant_user: "Dieselbe Person wurde mehrfach als Teilnehmer angegeben."+ meeting_participant:+ one_key: "Ein Teilnehmer ist entweder ein Mitglied oder ein Kontakt, nie beides."documentation_set:attributes:project_repository:diff --git a/config/locales/models.en.yml b/config/locales/models.en.ymlindex 8cc4a6a..f6f7fed 100644--- a/config/locales/models.en.yml+++ b/config/locales/models.en.yml@@ -119,6 +119,8 @@ en:content_too_large: "is too large (max. 1 MB)"duplicate_participant_name: "A participant was listed twice (same name)."duplicate_participant_user: "The same person was listed more than once as a participant."+ meeting_participant:+ one_key: "A participant is either a member or a contact, never both."documentation_set:attributes:project_repository:diff --git a/config/locales/services.de.yml b/config/locales/services.de.ymlindex 1eaf3d9..0254f2d 100644--- a/config/locales/services.de.yml+++ b/config/locales/services.de.yml@@ -52,6 +52,7 @@ de:nothing_picked: "Wähle eine Person aus oder lege eine neue an."member_participant: "Dieser Teilnehmer ist ein Mitglied und über sein Konto verknüpft."member_already_participant: "Dieses Mitglied nimmt schon an dem Meeting teil."+ person_already_participant: "Diese Person ist schon mit einem anderen Teilnehmer des Meetings verknüpft."member_name_taken: "Ein anderer Teilnehmer trägt schon den Namen dieses Mitglieds. Entferne ihn zuerst aus dem Meeting."not_allowed: "Du darfst keine Personen anlegen."move_meeting:diff --git a/config/locales/services.en.yml b/config/locales/services.en.ymlindex 39908f3..8f9f1ce 100644--- a/config/locales/services.en.yml+++ b/config/locales/services.en.yml@@ -52,6 +52,7 @@ en:nothing_picked: "Pick a person or create a new one."member_participant: "This participant is a member and is linked through their account."member_already_participant: "This member already takes part in the meeting."+ person_already_participant: "This person is already linked to another participant of the meeting."member_name_taken: "Another participant already carries the name of this member. Remove them from the meeting first."not_allowed: "You may not create people."move_meeting:diff --git a/db/migrate/20261027130000_add_one_key_check_to_meeting_participants.rb b/db/migrate/20261027130000_add_one_key_check_to_meeting_participants.rbnew file mode 100644index 0000000..b25df29--- /dev/null+++ b/db/migrate/20261027130000_add_one_key_check_to_meeting_participants.rb@@ -0,0 +1,17 @@+# frozen_string_literal: true++# One key per meeting participant: a member by user_id, a contact of the people+# directory by person_id, never both (MeetingParticipant#one_key holds the same+# rule for writes through the model). Three writers clear the other key by hand;+# this constraint makes a writer that forgets fail loudly, also one that writes+# past the model (update_all, a console fix).+#+# Safe to add in one step: until the link dialog (S2b) nothing wrote person_id,+# so no row carries both keys, and the table is small enough for the short+# lock of the validating ALTER TABLE.+class AddOneKeyCheckToMeetingParticipants < ActiveRecord::Migration[8.1]+ def change+ add_check_constraint :meeting_participants, 'num_nonnulls(user_id, person_id) <= 1',+ name: 'meeting_participants_one_key'+ end+enddiff --git a/db/schema.rb b/db/schema.rbindex 7782bb2..e9d8ac7 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_27_120000) do+ActiveRecord::Schema[8.1].define(version: 2026_10_27_130000) do# These are extensions that must be enabled in order to support this databaseenable_extension "pg_catalog.plpgsql"enable_extension "pgcrypto"@@ -793,6 +793,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_10_27_120000) dot.index ["organisation_id", "normalized_name"], name: "idx_on_organisation_id_normalized_name_5eadc4a5e5"t.index ["person_id"], name: "index_meeting_participants_on_person_id"t.index ["user_id"], name: "index_meeting_participants_on_user_id"+ t.check_constraint "num_nonnulls(user_id, person_id) <= 1", name: "meeting_participants_one_key"endcreate_table "meeting_ticket_suggestion_runs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|diff --git a/spec/models/meeting_participant_spec.rb b/spec/models/meeting_participant_spec.rbindex 1d4b8da..3e12d8c 100644--- a/spec/models/meeting_participant_spec.rb+++ b/spec/models/meeting_participant_spec.rb@@ -144,6 +144,63 @@ RSpec.describe MeetingParticipant, type: :model doendend+ # One key per participant (S2b): a member by user_id, a contact by person_id.+ # Two layers, each tested on its own: the validation names a writer that+ # forgets, the check constraint stops a write past the model.+ describe 'one key per participant' do+ let(:user) { create(:user) }+ let(:person) { ActsAsTenant.with_tenant(organisation) { create(:person, organisation: organisation) } }++ it 'is invalid with both a user and a person' do+ participant = ActsAsTenant.with_tenant(organisation) do+ build(:meeting_participant, meeting: meeting, user: user, person: person).tap(&:valid?)+ end++ expect(participant.errors.details[:base]).to include(error: :one_key)+ end++ it 'is valid with either key alone, or with none' do+ ActsAsTenant.with_tenant(organisation) do+ expect(build(:meeting_participant, meeting: meeting, user: user)).to be_valid+ expect(build(:meeting_participant, meeting: meeting, person: person)).to be_valid+ expect(build(:meeting_participant, meeting: meeting)).to be_valid+ end+ end++ it 'is refused by the database when the model is bypassed' do+ participant = ActsAsTenant.with_tenant(organisation) do+ create(:meeting_participant, meeting: meeting, user: user)+ end++ expect { participant.update_columns(person_id: person.id) }+ .to raise_error(ActiveRecord::StatementInvalid, /meeting_participants_one_key/)+ end+ end++ describe '.external' do+ it 'is a free name only: no member and no contact' do+ ActsAsTenant.with_tenant(organisation) do+ free = create(:meeting_participant, meeting: meeting, display_name: 'Frei')+ create(:meeting_participant, meeting: meeting, display_name: 'Mitglied', user: create(:user))+ create(:meeting_participant, meeting: meeting, display_name: 'Kontakt',+ person: create(:person, organisation: organisation))++ expect(described_class.external).to contain_exactly(free)+ end+ end+ end++ describe '.in_row_order' do+ it 'lists participants as they were added, not by name' do+ ActsAsTenant.with_tenant(organisation) do+ later = create(:meeting_participant, meeting: meeting, display_name: 'Anna', created_at: 1.minute.ago)+ earlier = create(:meeting_participant, meeting: meeting, display_name: 'Zora', created_at: 2.minutes.ago)++ expect(meeting.meeting_participants.in_row_order).to eq([earlier, later])+ end+ end+ end+describe 'user deletion (snapshot survives)' doit 'nulls user_id but keeps display_name when the linked user is deleted' douser = create(:user)diff --git a/spec/models/person_name_spec.rb b/spec/models/person_name_spec.rbindex e92da65..fd0d8c7 100644--- a/spec/models/person_name_spec.rb+++ b/spec/models/person_name_spec.rb@@ -18,6 +18,22 @@ RSpec.describe PersonName doexpect(described_class.normalize(nil)).to eq('')end+ describe '.without_note' do+ it 'drops every note in round brackets and the space around it' do+ expect(described_class.without_note('J. Weber (Hoster) (extern)')).to eq('J. Weber')+ expect(described_class.without_note('Anna (IT) Berg')).to eq('Anna Berg')+ end++ it 'keeps a name without a note as it is' do+ expect(described_class.without_note('Jonas Weber')).to eq('Jonas Weber')+ end++ it 'is empty for a name that is only a note, and for nil' do+ expect(described_class.without_note('(Hoster)')).to eq('')+ expect(described_class.without_note(nil)).to eq('')+ end+ end+it 'is the normalizer MeetingParticipant uses (delegation, not a copy)' doallow(described_class).to receive(:normalize).and_call_originaldiff --git a/spec/requests/organisations/meeting_participant_links_spec.rb b/spec/requests/organisations/meeting_participant_links_spec.rbindex 5518ed2..dea17b1 100644--- a/spec/requests/organisations/meeting_participant_links_spec.rb+++ b/spec/requests/organisations/meeting_participant_links_spec.rb@@ -7,6 +7,8 @@ require 'rails_helper'# writes. Rights in both directions; every negative claim about a page stands# next to proof that the page itself was rendered.RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :request do+ include PeopleVisibilityHelpers+let(:organisation) { create(:organisation) }before { ActsAsTenant.current_tenant = organisation }@@ -62,6 +64,30 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeparams: { choice: choice, modal_token: modal_token }.merge(extra), headers: streamend+ # The answer as a page Capybara's matchers can search: selectors instead of+ # regexes, so attribute order and quoting do not matter.+ def page_markup+ Capybara.string(response.body)+ end++ # The markup one stream of the answer carries. A stream's markup is the content+ # of its <template>, which Capybara's HTML5 parser keeps out of the tree it+ # searches; a missing stream fails here instead of turning a negative check green.+ def stream_markup(action, target)+ node = Nokogiri::HTML(response.body).at_css(%(turbo-stream[action="#{action}"][target="#{target}"]))+ raise "no #{action} stream for #{target} in the answer" unless node++ Capybara.string(node.at_css('template').inner_html)+ end++ def dialog_instance_id+ "meeting-participant-link-modal-#{meeting.id}-#{modal_token}"+ end++ def chips_id+ ActionView::RecordIdentifier.dom_id(meeting, :participants)+ end+describe 'the participant row' doit 'offers the link action to a writer with view_people' dosign_in writer('view_people')@@ -159,10 +185,7 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeendit 'keeps a chip as text when its person is a row the viewer may not see' do- hidden_member = member_with(create(:role, organisation: organisation), first_name: 'Hanna')- create(:project_permission, user: hidden_member, project: create(:project, organisation: organisation),- tickets_access: :read_only)- hidden_row = create(:person, organisation: organisation, name: 'Hanna Beispiel', user: hidden_member)+ hidden_row = row_out_of_sight(organisation: organisation, name: 'Hanna Beispiel')participant.update!(person: hidden_row)viewer = writer('view_people')sign_in viewer@@ -184,6 +207,29 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeexpect(response).to have_http_status(:ok)end+ it 'offers to change a link, from a single trigger the focus can come back to' do+ participant.update!(person: contact)+ sign_in admin+ show_meeting++ label = I18n.t("#{pl}.change", name: 'J. Weber (Hoster)')+ expect(page_markup).to have_css(%(a[title="#{label}"] i.bi-pencil), visible: :all)+ expect(page_markup).to have_css("[id='meeting-participant-link-trigger-#{participant.id}']", count: 1)+ end++ # The row was linked to a member after the participant was linked to it: the+ # participant is that member now, and the meeting form owns its link.+ it 'offers no link action for a contact whose row belongs to a member now' do+ participant.update!(person: contact)+ contact.update!(user: member_with(create(:role, organisation: organisation), first_name: 'Jonas'))+ sign_in admin+ show_meeting++ expect(response.body).to include('J. Weber (Hoster)',+ CGI.escapeHTML(organisation_people_path(organisation, person_id: contact.id)))+ expect(response.body).not_to include(new_link_path)+ end+it 'shows the links in the panel beside a ticket too' doticket = create(:ticket, project: project, organisation: organisation, title: 'Ticket mit Meeting')meeting.outgoing_references.create!(organisation: organisation, target: ticket, target_title_snapshot: ticket.display_title)@@ -213,8 +259,9 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeexpect(body.index('Jonas Weber')).to be < body.index('Anton Anders')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)+ expect(page_markup).to have_css('input[name=choice]', visible: :all)+ expect(page_markup).to have_no_css('input[name=choice][checked]', visible: :all)+ expect(page_markup).to have_css("input[value='person:#{contact.id}']", count: 1, visible: :all)endit 'searches in its list frame' do@@ -241,10 +288,7 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeendit 'does not name a linked person the viewer may not see' do- hidden_member = member_with(create(:role, organisation: organisation), first_name: 'Hanna')- create(:project_permission, user: hidden_member, project: create(:project, organisation: organisation),- tickets_access: :read_only)- hidden_row = create(:person, organisation: organisation, name: 'Hanna Weber', user: hidden_member)+ hidden_row = row_out_of_sight(organisation: organisation, name: 'Hanna Weber')participant.update_column(:person_id, hidden_row.id)sign_in writer('view_people')@@ -254,6 +298,15 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeexpect(response.body).not_to include('Hanna Weber')end+ it 'names the visible person the participant is linked to' do+ participant.update!(person: contact)+ sign_in admin++ get new_link_path++ expect(response.body).to include(CGI.escapeHTML(I18n.t("#{pl}.linked_to", name: 'Jonas Weber')))+ end+it 'offers no new person without manage_people' dosign_in writer('view_people')@@ -265,10 +318,7 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeit 'lists no person of another organisation and no row of an invisible member' doActsAsTenant.with_tenant(create(:organisation)) { create(:person, name: 'Fremde Weber') }- hidden_member = member_with(create(:role, organisation: organisation), first_name: 'Hanna')- create(:project_permission, user: hidden_member, project: create(:project, organisation: organisation),- tickets_access: :read_only)- create(:person, organisation: organisation, name: 'Hanna Weber', user: hidden_member)+ row_out_of_sight(organisation: organisation, name: 'Hanna Weber')sign_in writer('view_people')get new_link_path@@ -287,7 +337,7 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeexpect(response).to have_http_status(:ok)expect(participant.reload.person_id).to eq(contact.id)- expect(response.body).to include("turbo-stream action=\"replace\" target=\"#{ActionView::RecordIdentifier.dom_id(meeting, :participants)}\"")+ expect(response.body).to include("turbo-stream action=\"replace\" target=\"#{chips_id}\"")expect(response.body).to include("action=\"remove\" target=\"meeting-participant-link-modal-#{meeting.id}-#{modal_token}\"")expect(response.body).to include(CGI.escapeHTML(organisation_people_path(organisation, person_id: contact.id)))@@ -300,10 +350,9 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requepost_link("person:#{contact.id}")- chips_id = ActionView::RecordIdentifier.dom_id(meeting, :participants)- replaced = response.body[%r{<turbo-stream action="replace" target="#{chips_id}">[\s\S]*?</turbo-stream>}]- expect(replaced).to include('J. Weber (Hoster)')- expect(replaced).not_to include("<turbo-frame id=\"meeting-participant-link-modal-#{meeting.id}\"")+ replaced = stream_markup('replace', chips_id)+ expect(replaced).to have_text('J. Weber (Hoster)')+ expect(replaced).to have_no_css("turbo-frame[id='meeting-participant-link-modal-#{meeting.id}']", visible: :all)endit 'links a member by account and leaves person_id empty' do@@ -326,9 +375,9 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requepost_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(stream_markup('replace', dialog_instance_id))+ .to have_css("input[value='member:#{colleague.id}'][checked]", visible: :all)expect(response.body).to include(I18n.t('services.actors.link_meeting_participant.member_already_participant'))expect(participant.reload.user_id).to be_nilend@@ -347,7 +396,8 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requepost_link("member:#{pick.id}")expect(response).to have_http_status(:unprocessable_content)- expect(response.body.scan(%(value="member:#{pick.id}")).size).to eq(1)+ expect(stream_markup('replace', dialog_instance_id))+ .to have_css("input[value='member:#{pick.id}']", count: 1, visible: :all)endexpect(response.body).to include(I18n.t("#{pl}.suggestion"))end@@ -383,7 +433,7 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requepost_link('', modal_token: bad)expect(response).to have_http_status(:unprocessable_content)- expect(response.body).to include("action=\"replace\" target=\"#{ActionView::RecordIdentifier.dom_id(meeting, :participants)}\"",+ expect(response.body).to include("action=\"replace\" target=\"#{chips_id}\"",I18n.t('services.actors.link_meeting_participant.nothing_picked'))expect(response.body).not_to include('target="meeting-participant-link-modal-')end@@ -395,7 +445,7 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requepost_link("person:#{contact.id}", modal_token: '')expect(response).to have_http_status(:ok)- expect(response.body).to include("action=\"replace\" target=\"#{ActionView::RecordIdentifier.dom_id(meeting, :participants)}\"")+ expect(response.body).to include("action=\"replace\" target=\"#{chips_id}\"")expect(response.body).not_to include('action="remove"')end@@ -406,6 +456,17 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeexpect(participant.reload.person.name).to eq('J. Weber')end+ it 'keeps the new person picked and the typed name after a refusal' do+ sign_in writer('manage_people')++ post_link('new', new_person_name: ' ')++ expect(response).to have_http_status(:unprocessable_content)+ dialog = stream_markup('replace', dialog_instance_id)+ expect(dialog).to have_css('input[name=choice][value=new][checked]', visible: :all)+ expect(dialog).to have_field('new_person_name', with: ' ')+ end+it 'creates no person without manage_people' dosign_in writer('view_people')@@ -508,17 +569,14 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeendit 'does not find the row of a member the writer may not see' do- hidden_member = member_with(create(:role, organisation: organisation), first_name: 'Hanna')- create(:project_permission, user: hidden_member, project: create(:project, organisation: organisation),- tickets_access: :read_only)- hidden_row = create(:person, organisation: organisation, name: 'Hanna Weber', user: hidden_member)+ hidden_row = row_out_of_sight(organisation: organisation, name: 'Hanna Weber')sign_in writer('view_people')post_link("person:#{hidden_row.id}")expect(response).to have_http_status(:not_found)expect(response.body).to include(I18n.t('services.actors.link_meeting_participant.not_found'))expect(response.body).not_to include('Hanna Weber')- post_link("member:#{hidden_member.id}")+ post_link("member:#{hidden_row.user_id}")expect(response).to have_http_status(:not_found)expect(response.body).not_to include('Hanna Weber')expect_unchanged@@ -565,6 +623,63 @@ RSpec.describe 'Organisations::MeetingParticipantLinks', :ci_guard, type: :requeendend+ # A dialog or a panel left open while the meeting moved to another project: its+ # next request finds nothing here. It says so where the dialog would be, instead+ # of Turbo's "Content missing", and draws nothing of the meeting.+ describe 'a meeting moved while its row was open' do+ before do+ meeting.update_columns(project_id: create(:project, organisation: organisation).id)+ sign_in admin+ end++ let(:reason) { I18n.t('services.actors.link_meeting_participant.not_found') }++ it 'answers the dialog frame with the reason' do+ get new_link_path, headers: { 'Turbo-Frame' => "meeting-participant-link-modal-#{meeting.id}" }++ expect(response).to have_http_status(:not_found)+ expect(page_markup).to have_css("turbo-frame[id='meeting-participant-link-modal-#{meeting.id}']", text: reason)+ end++ it 'closes the dialog with the reason after a link' do+ post_link("person:#{contact.id}")++ expect(response).to have_http_status(:not_found)+ expect(response.body).to include(%(turbo-stream action="remove" target="#{dialog_instance_id}"), reason)+ expect(response.body).not_to include('action="replace"')+ expect(participant.reload.person_id).to be_nil+ end+ end++ # The dialog always posts as a stream; a form without Turbo still gets an answer.+ describe 'without Turbo (a plain form submit)' do+ before { sign_in admin }++ it 'goes back to the meeting with a notice after a link' do+ post link_path, params: { choice: "person:#{contact.id}" }++ expect(response).to redirect_to(organisation_project_meetings_path(organisation, project, meeting_id: meeting.id))+ expect(response).to have_http_status(:see_other)+ expect(flash[:notice]).to eq(I18n.t('flash.meeting_participant_links.linked'))+ end++ it 'goes back to the meeting with the reason after a refusal' do+ post link_path, params: { choice: '' }++ expect(response).to redirect_to(organisation_project_meetings_path(organisation, project, meeting_id: meeting.id))+ expect(flash[:alert]).to eq(I18n.t('services.actors.link_meeting_participant.nothing_picked'))+ end++ it 'goes back to the meetings of the project when someone is out of reach' do+ foreign = ActsAsTenant.with_tenant(create(:organisation)) { create(:person, name: 'Fremde Weber') }++ post link_path, params: { choice: "person:#{foreign.id}" }++ expect(response).to redirect_to(organisation_project_meetings_path(organisation, project))+ expect(flash[:alert]).to eq(I18n.t('services.actors.link_meeting_participant.not_found'))+ end+ end+describe 'a later edit of the meeting' dodef edit_with(display_name:, user_id: nil)patch organisation_project_meeting_path(organisation, project, meeting, format: :turbo_stream),diff --git a/spec/requests/organisations/meeting_participant_person_link_spec.rb b/spec/requests/organisations/meeting_participant_person_link_spec.rbindex 766dcaf..ca5fcc1 100644--- a/spec/requests/organisations/meeting_participant_person_link_spec.rb+++ b/spec/requests/organisations/meeting_participant_person_link_spec.rb@@ -2,13 +2,13 @@require 'rails_helper'-# A participant's person link (meeting_participants.person_id) survives a save of-# the meeting form that leaves the participant alone. The form labels a member-# chip with the member's CURRENT profile name, so after a change of name the-# untouched chip comes back under another name. The actor spec covers the rule;-# this one walks the real edit form, so a change to how the form names a member-# cannot go round it.-RSpec.describe 'Meeting edit keeps the person link of a member participant', type: :request do+# A member participant keeps its row through a save of the meeting form that+# leaves it alone. The form labels a member chip with the member's CURRENT+# profile name, so after a change of name the untouched chip comes back under+# another name. The actor spec covers the rule; this one walks the real edit+# form, so a change to how the form names a member cannot go round it. (A member+# row carries no person_id, one key per participant: the row id is the mark.)+RSpec.describe 'Meeting edit keeps the row of a member participant', type: :request dolet(:organisation) { create(:organisation) }let(:project) { ActsAsTenant.with_tenant(organisation) { create(:project, organisation: organisation) } }let(:writer) do@@ -21,13 +21,10 @@ RSpec.describe 'Meeting edit keeps the person link of a member participant', typuserend- it 'keeps the row and person_id after the member changed their name in the profile' do- meeting, row, person = ActsAsTenant.with_tenant(organisation) do+ it 'keeps the row after the member changed their name in the profile' do+ meeting, row = ActsAsTenant.with_tenant(organisation) dom = create(:meeting, project: project, organisation: organisation, creator: writer, title: 'Retro')- p = create(:person, organisation: organisation, name: 'Karl Krause')- r = create(:meeting_participant, meeting: m, display_name: 'Karl Krause', user_id: writer.id)- r.update_column(:person_id, p.id)- [m, r, p]+ [m, create(:meeting_participant, meeting: m, display_name: 'Karl Krause', user_id: writer.id)]endwriter.update!(last_name: 'Krause-Meier')sign_in writer@@ -47,8 +44,8 @@ RSpec.describe 'Meeting edit keeps the person link of a member participant', typexpect(response).to have_http_status(:found)rows = ActsAsTenant.with_tenant(organisation) do- MeetingParticipant.where(meeting_id: meeting.id).pluck(:id, :user_id, :person_id)+ MeetingParticipant.where(meeting_id: meeting.id).pluck(:id, :user_id)end- expect(rows).to eq([[row.id, writer.id, person.id]])+ expect(rows).to eq([[row.id, writer.id]])endenddiff --git a/spec/services/actors/link_meeting_participant_spec.rb b/spec/services/actors/link_meeting_participant_spec.rbindex 9240ace..441e9d8 100644--- a/spec/services/actors/link_meeting_participant_spec.rb+++ b/spec/services/actors/link_meeting_participant_spec.rb@@ -7,6 +7,8 @@ require 'rails_helper'# the person and the member through what the writer may see in the directory.# One key per participant: a member is linked by user_id, a contact by person_id.RSpec.describe Actors::LinkMeetingParticipant, :ci_guard do+ include PeopleVisibilityHelpers+let(:organisation) { create(:organisation) }before { ActsAsTenant.current_tenant = organisation }@@ -120,17 +122,67 @@ RSpec.describe Actors::LinkMeetingParticipant, :ci_guard do# The claim writes without the meeting lock, so its row can land after both the# actor's check and the model's uniqueness validation. The partial unique index on- # (meeting_id, user_id) then refuses, and the actor answers as the check would.+ # (meeting_id, user_id) then refuses the write, and the actor answers as the check+ # would. Simulated at the database seam, so the checks themselves stay real.it 'turns the unique index into the same refusal when a write lands past both checks' do- create(:meeting_participant, meeting: meeting, display_name: 'Carl der Andere', user: colleague)- allow_any_instance_of(described_class).to receive(:taken_by_another?).and_return(false)- allow_any_instance_of(MeetingParticipant).to receive(:valid?).and_return(true)+ allow_any_instance_of(MeetingParticipant).to receive(:update!).and_raise(ActiveRecord::RecordNotUnique)result = link(member_id: colleague.id)expect(result.code).to eq(:member_already_participant)expect(participant.reload.user_id).to be_nilend++ # The meeting form shows a member under the profile name. A second member of the+ # same profile name would make the form show one name twice, and every later save+ # of the meeting would fail.+ it 'refuses a member whose profile name another member participant shows' do+ twin = member(first_name: colleague.first_name)+ twin.update!(last_name: colleague.last_name)+ create(:meeting_participant, meeting: meeting, display_name: 'C. B. (Vertrieb)', user: twin)++ result = link(member_id: colleague.id)++ expect(result.code).to eq(:member_name_taken)+ expect(participant.reload.user_id).to be_nil+ end+ end++ describe 'linking a contact that another participant has already' do+ it 'refuses it, changing nothing' do+ create(:meeting_participant, meeting: meeting, display_name: 'Jonas W.', person: contact)++ result = link(person_id: contact.id)++ expect(result.code).to eq(:person_already_participant)+ expect(result.errors).to eq([I18n.t('services.actors.link_meeting_participant.person_already_participant')])+ expect(participant.reload.person_id).to be_nil+ end++ it 'links the same contact in another meeting' do+ other_meeting = create(:meeting, organisation: organisation, project: project)+ create(:meeting_participant, meeting: other_meeting, display_name: 'Jonas W.', person: contact)++ expect(link(person_id: contact.id)).to be_success+ end+ end++ # The row was linked to a member after the participant was linked to it. The+ # participant is that member now: the dialog may neither relink nor unlink it, also+ # not for a writer who may not see that member.+ describe 'a contact whose row belongs to a member now' do+ before do+ link(person_id: contact.id)+ contact.update!(user: member(first_name: 'Jonas'))+ end++ it 'is neither relinked nor unlinked' do+ other = create(:person, organisation: organisation, name: 'Jana Weber')++ expect(link(person_id: other.id).code).to eq(:member_participant)+ expect(link(unlink: true).code).to eq(:member_participant)+ expect(participant.reload.person_id).to eq(contact.id)+ endenddescribe 'a participant that is a member' do@@ -202,6 +254,18 @@ RSpec.describe Actors::LinkMeetingParticipant, :ci_guard doexpect(participant.reload.person_id).to be_nilend+ # A stale or internal failure of SavePerson is no validation failure: its code+ # comes through, so the controller can answer our own failure with a 500.+ it 'passes the code of a failed SavePerson through' do+ failure = Actors::BaseActor::Result.new(success: false, errors: ['Veraltet'], code: :stale_object)+ allow(Actors::SavePerson).to receive(:call).and_return(failure)++ result = link(new_person: { name: 'J. Weber' })++ expect(result.code).to eq(:stale_object)+ expect(result.errors).to eq(['Veraltet'])+ end+it 'creates nothing when the link fails afterwards (one transaction)' doallow_any_instance_of(MeetingParticipant).to receive(:update!).and_raise(Actors::ActorError, 'link failed')@@ -245,16 +309,12 @@ RSpec.describe Actors::LinkMeetingParticipant, :ci_guard doendit 'does not find the row of a member the writer may not see' do- # Members see only colleagues of projects they share (MembershipPolicy::Scope).limited = member(role: role_with('view_people'))- hidden_member = member(first_name: 'Hanna')create(:project_permission, user: limited, project: project, meetings_access: :read_write)- create(:project_permission, user: hidden_member, project: create(:project, organisation: organisation),- tickets_access: :read_only)- row = create(:person, organisation: organisation, name: hidden_member.display_name, user: hidden_member)+ row = row_out_of_sight(organisation: organisation, name: 'Hanna Beispiel')expect(link(user: limited, person_id: row.id).code).to eq(:not_found)- expect(link(user: limited, member_id: hidden_member.id).code).to eq(:not_found)+ expect(link(user: limited, member_id: row.user_id).code).to eq(:not_found)expect(participant.reload.user_id).to be_nilenddiff --git a/spec/services/actors/save_meeting_spec.rb b/spec/services/actors/save_meeting_spec.rbindex 0305f7d..d704f07 100644--- a/spec/services/actors/save_meeting_spec.rb+++ b/spec/services/actors/save_meeting_spec.rb@@ -324,24 +324,26 @@ RSpec.describe Actors::SaveMeeting do# The form labels a member chip with the member's CURRENT profile name, not# the stored one. After a change of name in the profile, an untouched save- # sends the same member under a new name: still the same participant.- it 'keeps the row and person_id when a member arrives under a new name' do+ # sends the same member under a new name: still the same participant, the+ # same row. (A member row carries no person_id: one key per participant,+ # so the row id is the mark that it stayed.)+ it 'keeps the row when a member arrives under a new name' domember = org_membermeeting = 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')+ row = meeting.meeting_participants.find_by!(user_id: member.id)save(meeting, valid_params.merge(participants: [{ display_name: 'Karl Krause-Meier', user_id: member.id }]))- rows = meeting.reload.meeting_participants.pluck(:id, :display_name, :user_id, :person_id)- expect(rows).to eq([[row.id, 'Karl Krause-Meier', member.id, person.id]])+ rows = meeting.reload.meeting_participants.pluck(:id, :display_name, :user_id)+ expect(rows).to eq([[row.id, 'Karl Krause-Meier', member.id]])end# Two members, one renamed and one removed in the same save: the renamed- # member takes its own row and link, never the other member's. Each member- # is the renamed one once, so the order the rows load in cannot hide it.+ # member takes its own row, never the other member's. Each member is the+ # renamed one once, so the order the rows load in cannot hide it.[0, 1].each do |renamed|it "gives a member under a new name its own row, not another member's (member #{renamed + 1})" donames = ['Karl Krause', 'Erika Muster']@@ -351,23 +353,13 @@ RSpec.describe Actors::SaveMeeting doparams: valid_params.merge(participants: names.zip(members).map { |n, m| { display_name: n, user_id: m.id } }),current_user: user).resource- # Setup only: one person per row, looked up per name (Prosopite would- # call the loop an N+1).- people = Prosopite.pause do- names.map do |n|- linked = create(:person, organisation: organisation, name: n)- meeting.meeting_participants.find_by!(normalized_name: MeetingParticipant.normalize_name(n))- .update_column(:person_id, linked.id)- linked- end- endkept = meeting.meeting_participants.find_by!(user_id: members[renamed].id)save(meeting, valid_params.merge(participants: [{ display_name: "#{names[renamed]}-Neu",user_id: members[renamed].id }]))- rows = meeting.reload.meeting_participants.pluck(:id, :user_id, :person_id)- expect(rows).to eq([[kept.id, members[renamed].id, people[renamed].id]])+ rows = meeting.reload.meeting_participants.pluck(:id, :user_id)+ expect(rows).to eq([[kept.id, members[renamed].id]])endend@@ -381,13 +373,12 @@ RSpec.describe Actors::SaveMeeting do{ display_name: 'Karl Krause-Meier' }]),current_user: user).resource- linked_row(meeting, 'Karl Krause')named = meeting.meeting_participants.find_by!(normalized_name: 'karl krause-meier')save(meeting, valid_params.merge(participants: [{ display_name: 'Karl Krause-Meier', user_id: member.id }]))- rows = meeting.reload.meeting_participants.pluck(:id, :user_id, :person_id)- expect(rows).to eq([[named.id, member.id, nil]])+ rows = meeting.reload.meeting_participants.pluck(:id, :user_id)+ expect(rows).to eq([[named.id, member.id]])end# The member's old name comes back as an external participant: that name@@ -398,14 +389,14 @@ RSpec.describe Actors::SaveMeeting doproject: project, params: valid_params.merge(participants: [{ display_name: 'Karl Krause', user_id: member.id }]),current_user: user).resource- row = linked_row(meeting, 'Karl Krause')+ row = meeting.meeting_participants.find_by!(user_id: member.id)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]])+ rows = meeting.reload.meeting_participants.order(:normalized_name).pluck(:id, :normalized_name, :user_id)+ expect(rows).to match([[row.id, 'karl krause', nil],+ [satisfy { |id| id != row.id }, 'karl krause-meier', member.id]])endendenddiff --git a/spec/services/meetings/account_participants_spec.rb b/spec/services/meetings/account_participants_spec.rbnew file mode 100644index 0000000..91b0372--- /dev/null+++ b/spec/services/meetings/account_participants_spec.rb@@ -0,0 +1,82 @@+# frozen_string_literal: true++require 'rails_helper'++# Which participants the link dialog leaves alone, because their link runs+# through an account (S2b). The actor and the participant row both ask this.+RSpec.describe Meetings::AccountParticipants, :ci_guard do+ let(:organisation) { create(:organisation) }++ before { ActsAsTenant.current_tenant = organisation }+ after { ActsAsTenant.current_tenant = nil }++ let(:meeting) { create(:meeting, organisation: organisation, project: create(:project, organisation: organisation)) }++ def member(active: true)+ create(:user).tap do |user|+ create(:membership, user: user, organisation: organisation, role: create(:role, organisation: organisation),+ active: active)+ end+ end++ def participant(name, **keys)+ create(:meeting_participant, meeting: meeting, display_name: name, **keys)+ end++ def through_account?(record)+ described_class.new(organisation: organisation, participants: meeting.meeting_participants.reload.to_a).include?(record)+ end++ it 'counts a member, active or deactivated' do+ expect(through_account?(participant('Aktiv', user: member))).to be(true)+ expect(through_account?(participant('Pausiert', user: member(active: false)))).to be(true)+ end++ it 'does not count someone whose membership here was removed, even with one elsewhere' do+ gone = create(:user)+ elsewhere = create(:organisation)+ ActsAsTenant.with_tenant(elsewhere) do+ create(:membership, user: gone, organisation: elsewhere, role: create(:role, organisation: elsewhere))+ end++ expect(through_account?(participant('Weg', user: gone))).to be(false)+ end++ it 'does not count a free name or a contact without an account' do+ expect(through_account?(participant('Frei'))).to be(false)+ expect(through_account?(participant('Kontakt', person: create(:person, organisation: organisation)))).to be(false)+ end++ it 'counts a contact whose row belongs to an active member now' do+ row = create(:person, organisation: organisation, name: 'Jonas Weber')+ linked = participant('J. Weber', person: row)+ row.update!(user: member)++ expect(through_account?(linked)).to be(true)+ end++ it 'does not count a contact whose row belongs to a deactivated member' do+ row = create(:person, organisation: organisation, name: 'Fritz Frueher', user: member)+ Membership.where(user_id: row.user_id).update_all(active: false)++ expect(through_account?(participant('Fritz', person: row))).to be(false)+ end++ # The participant row asks for every chip: one lookup per key, not per chip.+ it 'asks the database twice, however many participants' do+ Prosopite.pause do+ 3.times { |i| participant("Mitglied #{i}", user: member) }+ 3.times { |i| participant("Kontakt #{i}", person: create(:person, organisation: organisation)) }+ end+ records = meeting.meeting_participants.to_a+ accounts = described_class.new(organisation: organisation, participants: records)++ queries = 0+ count = ->(*, payload) { queries += 1 unless payload[:name] == 'SCHEMA' }+ ActiveSupport::Notifications.subscribed(count, 'sql.active_record') do+ records.each { |record| accounts.include?(record) }+ end++ expect(queries).to eq(2)+ end+enddiff --git a/spec/services/meetings/participant_link_choice_spec.rb b/spec/services/meetings/participant_link_choice_spec.rbnew file mode 100644index 0000000..bbea61c--- /dev/null+++ b/spec/services/meetings/participant_link_choice_spec.rb@@ -0,0 +1,35 @@+# frozen_string_literal: true++require 'rails_helper'++# The one format of a pick in the link dialog (S2b): written by the dialog,+# read by the controller and by the dialog that draws a refused pick again.+RSpec.describe Meetings::ParticipantLinkChoice do+ let(:id) { SecureRandom.uuid }++ it 'writes a row as person:<id> and a member as member:<id>, and reads both back' do+ person = instance_double(Person, id: id)+ user = instance_double(User, id: SecureRandom.uuid)++ contact_value = described_class.value_for(People::Directory::Entry.new(kind: :contact, person: person))+ member_value = described_class.value_for(People::Directory::Entry.new(kind: :member, user: user, person: person))++ expect(contact_value).to eq("person:#{id}")+ expect(member_value).to eq("member:#{user.id}")+ expect(described_class.parse(contact_value)).to have_attributes(kind: :person, id: id)+ expect(described_class.parse(member_value)).to have_attributes(kind: :member, id: user.id)+ end++ it 'reads the new person' do+ expect(described_class.parse(described_class::NEW_PERSON)).to have_attributes(kind: :new_person, id: nil)+ end++ [nil, '', 'person:', 'user:%<id>s', 'person:%<id>s ', ' person:%<id>s', 'person:%<id>s:x', 'person:not-a-uuid',+ ['person:%<id>s']].each do |value|+ it "reads nothing from #{value.inspect}" do+ value = format(value, id: id) if value.is_a?(String)++ expect(described_class.parse(value)).to be_nil+ end+ end+enddiff --git a/spec/services/meetings/participant_link_options_spec.rb b/spec/services/meetings/participant_link_options_spec.rbnew file mode 100644index 0000000..a6a04eb--- /dev/null+++ b/spec/services/meetings/participant_link_options_spec.rb@@ -0,0 +1,66 @@+# frozen_string_literal: true++require 'rails_helper'++# The lines of the link dialog (S2b, E6): suggestions first, then the search,+# and a refused pick drawn again once. Read from the viewer's directory.+RSpec.describe Meetings::ParticipantLinkOptions do+ let(:organisation) { create(:organisation) }++ before { ActsAsTenant.current_tenant = organisation }+ after { ActsAsTenant.current_tenant = nil }++ let(:admin) do+ create(:user, first_name: 'Anna', last_name: 'Admin').tap do |user|+ role = create(:role, organisation: organisation, title: Role::ACCOUNT_ADMIN_TITLE)+ create(:membership, user: user, organisation: organisation, role: role)+ end+ end+ let(:meeting) { create(:meeting, organisation: organisation, project: create(:project, organisation: organisation)) }+ let(:participant) { create(:meeting_participant, meeting: meeting, display_name: 'J. Weber (Hoster)') }+ let!(:same_surname) { create(:person, organisation: organisation, name: 'Jonas Weber') }+ let!(:other) { create(:person, organisation: organisation, name: 'Anton Anders') }++ def lines(query: '', limit: 20, choice: nil)+ described_class.new(viewer: admin, organisation: organisation, participant: participant,+ query: query, limit: limit, choice: choice).lines+ end++ def people(found)+ found.map { |line| [line.entry.person&.name || line.entry.user.display_name, line.suggested?] }+ end++ it 'puts the suggestions first, marked, and lists each person once' do+ expect(people(lines)).to eq([['Jonas Weber', true], ['Anna Admin', false], ['Anton Anders', false]])+ end++ it 'suggests nothing while searching, and lists only what the search finds' do+ expect(people(lines(query: 'weber'))).to eq([['Jonas Weber', false]])+ end++ it 'lists at most limit people besides the suggestions' do+ expect(people(lines(limit: 1))).to eq([['Jonas Weber', true], ['Anna Admin', false]])+ end++ describe 'a refused pick' do+ it 'comes back ahead of the others when it lies past the limit' do+ expect(people(lines(limit: 0, choice: "person:#{other.id}"))).to eq([['Jonas Weber', true], ['Anton Anders', false]])+ end++ it 'stays once where it is when it is a suggestion or already listed' do+ expect(lines(choice: "person:#{same_surname.id}").count { |line| line.entry.person == same_surname }).to eq(1)+ expect(lines(choice: "person:#{other.id}").count { |line| line.entry.person == other }).to eq(1)+ end++ it 'comes back as a member too' do+ expect(people(lines(limit: 0, choice: "member:#{admin.id}"))).to eq([['Jonas Weber', true], ['Anna Admin', false]])+ end++ it 'is not drawn when the viewer may not see it, or the value is no pick' do+ foreign = ActsAsTenant.with_tenant(create(:organisation)) { create(:person, name: 'Fremde Weber') }++ expect(people(lines(limit: 0, choice: "person:#{foreign.id}"))).to eq([['Jonas Weber', true]])+ expect(people(lines(limit: 0, choice: 'person:nonsense'))).to eq([['Jonas Weber', true]])+ end+ end+enddiff --git a/spec/services/people/directory_spec.rb b/spec/services/people/directory_spec.rbindex 7e4efa0..1fe82c6 100644--- a/spec/services/people/directory_spec.rb+++ b/spec/services/people/directory_spec.rb@@ -196,6 +196,74 @@ RSpec.describe People::Directory, :ci_guard doexpect(described_class.surname('J.')).to be_nilexpect(directory.suggestions_for(' ')).to eq([])end++ describe '#entry_for_participant' do+ let(:meeting) { create(:meeting, organisation: organisation, project: project) }++ def participant(name, **keys)+ create(:meeting_participant, meeting: meeting, display_name: name, **keys)+ end++ it 'is the member for a member participant' do+ expect(directory(admin).entry_for_participant(participant('Carl', user: colleague)).user).to eq(colleague)+ end++ it 'is the row that keeps their meetings for a deactivated member' do+ row = create(:person, organisation: organisation, name: 'Carl Kollege', user: colleague)+ Membership.where(user: colleague).update_all(active: false)++ entry = directory(admin).entry_for_participant(participant('Carl', user: colleague))++ expect(entry).not_to be_member+ expect(entry.person).to eq(row)+ end++ it 'is the row for a contact, and the member when that row is a member\'s' do+ member_row = create(:person, organisation: organisation, name: 'Carl Kollege', user: colleague)++ expect(directory(admin).entry_for_participant(participant('Doris', person: contact)).person).to eq(contact)+ expect(directory(admin).entry_for_participant(participant('Carl', person: member_row))).to be_member+ end++ it 'is nil for a free name, and for someone the viewer may not see' do+ expect(directory(admin).entry_for_participant(participant('Frei'))).to be_nil+ expect(directory.entry_for_participant(participant('Sven', user: stranger))).to be_nil+ end+ end++ describe '#former_member_entry' do+ it 'is the contact entry of a deactivated member, nil while they are active' do+ row = create(:person, organisation: organisation, name: 'Carl Kollege', user: colleague)++ expect(directory(admin).former_member_entry(colleague.id)).to be_nil+ Membership.where(user: colleague).update_all(active: false)+ expect(directory(admin).former_member_entry(colleague.id).person).to eq(row)+ end+ end++ describe 'Entry#detail' do+ def entry(**fields)+ described_class::Entry.new(**fields)+ end++ it 'is function and company of a row, joined' do+ person = build(:person, function: 'CTO', company: 'Beispiel GmbH')++ expect(entry(kind: :contact, person: person).detail).to eq('CTO · Beispiel GmbH')+ expect(entry(kind: :contact, person: build(:person, function: nil, company: 'Beispiel GmbH')).detail)+ .to eq('Beispiel GmbH')+ end++ it "is a member's email without function and company, and nothing for such a contact" do+ user = build(:user, email: '[email protected]')++ bare = { function: nil, company: nil }++ expect(entry(kind: :member, user: user, person: build(:person, **bare)).detail).to eq('[email protected]')+ expect(entry(kind: :member, user: user).detail).to eq('[email protected]')+ expect(entry(kind: :contact, person: build(:person, email: '[email protected]', **bare)).detail).to be_nil+ end+ endendit 'returns nothing without the right' dodiff --git a/spec/support/people_visibility_helpers.rb b/spec/support/people_visibility_helpers.rbnew file mode 100644index 0000000..b9bc78f--- /dev/null+++ b/spec/support/people_visibility_helpers.rb@@ -0,0 +1,24 @@+# frozen_string_literal: true++# People a writer with view_people (and no wider rights) does not see in the+# people directory. The rule lives in MembershipPolicy::Scope: a member sees the+# colleagues of the projects they share, and these members' only project is a+# fresh one. PersonPolicy::Scope hides such a member's person row too.+#+# One place for the setup, so a change to the visibility rule is made once: a+# forgotten copy would leave a negative assertion green without testing anything.+# Include it where needed (`include PeopleVisibilityHelpers`).+module PeopleVisibilityHelpers+ def member_out_of_sight(organisation:, first_name: 'Hanna', last_name: 'Beispiel')+ user = create(:user, first_name: first_name, last_name: last_name)+ create(:membership, user: user, organisation: organisation, role: create(:role, organisation: organisation))+ create(:project_permission, user: user, project: create(:project, organisation: organisation),+ tickets_access: :read_only)+ User.find(user.id)+ end++ # The person row of such a member, under the given name.+ def row_out_of_sight(organisation:, name:)+ create(:person, organisation: organisation, name: name, user: member_out_of_sight(organisation: organisation))+ end+end