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
Link a meeting participant to a person of the directory
Guido Boyke1278f41e2271
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.ymlindex deeb8c1..b8581c8 100644--- a/.github/workflows/guards.yml+++ b/.github/workflows/guards.yml@@ -321,6 +321,8 @@ jobs:spec/services/people/directory_spec.rbspec/services/people/contacts_spec.rbspec/requests/organisations/people_last_contact_spec.rb+ spec/requests/organisations/meeting_participant_links_spec.rb+ spec/services/actors/link_meeting_participant_spec.rbspec/requests/organisations/note_editor_embed_spec.rbspec/requests/organisations/onboarding_banner_spec.rbspec/requests/organisations/panel_lane_markup_guard_spec.rb@@ -647,6 +649,7 @@ jobs:spec/system/meeting_filters_columns_spec.rbspec/system/ticket_list_unread_dot_spec.rbspec/system/ticket_relations_spec.rb+ spec/system/meeting_participant_link_spec.rbspec/system/ticket_meeting_panel_spec.rbspec/system/ticket_meeting_panel_stages_spec.rbspec/system/ticket_meeting_panel_assistant_spec.rbdiff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.cssindex 07f9053..ecce0ee 100644--- a/app/assets/stylesheets/application.tailwind.css+++ b/app/assets/stylesheets/application.tailwind.css@@ -439,8 +439,10 @@.people-badge { @apply shrink-0 rounded-full border border-cream-300 bg-cream-100 px-1.5 text-[11px] text-cream-600; }/* Members keep the chip's own tone; contacts (no account) a lighter one.Scoped to the page so it wins over the chip's utility classes. */- .people-page .people-avatar { @apply font-mono font-normal; }- .people-page .people-avatar--contact { @apply border-cream-300 bg-surface-raised text-cream-600; }+ .people-page .people-avatar,+ .participant-link-modal .people-avatar { @apply font-mono font-normal; }+ .people-page .people-avatar--contact,+ .participant-link-modal .people-avatar--contact { @apply border-cream-300 bg-surface-raised text-cream-600; }.people-empty { @apply flex flex-col items-start gap-2.5 px-6 pt-8; }.people-empty__icon { @apply text-2xl text-cream-500; }.people-empty__title { @apply text-[15px] font-semibold text-heading; }diff --git a/app/controllers/organisations/meeting_participant_links_controller.rb b/app/controllers/organisations/meeting_participant_links_controller.rbnew file mode 100644index 0000000..b030b2d--- /dev/null+++ b/app/controllers/organisations/meeting_participant_links_controller.rb@@ -0,0 +1,133 @@+# frozen_string_literal: true++# Linking a meeting participant to the people directory (S2b): new renders the+# dialog "Mit Person verknüpfen" into its frame (?q= reloads only its list),+# create links (a person, a member, or a person created in the same step),+# destroy unlinks. Every answer redraws the participant row of THIS meeting.+#+# 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.+# 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.+module Organisations+ class MeetingParticipantLinksController < Organisations::BaseController+ include ProjectController++ # The token of one dialog instance, echoed by its form. Anything else is no token.+ MODAL_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].freeze+ NOT_FOUND_CODES = %i[not_found].freeze++ before_action :set_meeting_and_participant++ def new+ authorize @meeting, :update?+ authorize Person, :index?++ @query = scalar_param(:q).to_s+ if request.headers['Turbo-Frame'] == helpers.participant_link_results_id(@participant)+ render partial: 'organisations/meeting_participant_links/results',+ locals: { meeting: @meeting, participant: @participant, query: @query, choice: nil }+ return+ end++ @modal_token = SecureRandom.hex(8)+ render layout: false+ end++ def 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)+ return changed(t('flash.meeting_participant_links.linked')) if result.success?++ refused(result)+ end++ def 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?++ refused(result)+ end++ private++ # ProjectController derives the area from the controller name+ # ("meeting_participant_links"), which is no area. Linking is a meeting write.+ def determine_access_area+ :meetings+ end++ # Scoped to the route's project: a meeting of another project or another+ # organisation, or a participant of another meeting, is not found.+ def set_meeting_and_participant+ @meeting = @project.meetings.find(params[:meeting_id])+ @participant = @meeting.meeting_participants.find(params[:participant_id])+ end++ def actor_arguments+ { meeting: @meeting, project: @project, participant_id: @participant.id, current_user: current_user }+ end++ 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] }+ end++ # The row of this meeting's participants, the dialog closed, the flash.+ def changed(message)+ respond_to do |format|+ format.turbo_stream do+ @flash_message = { notice: message }+ render 'organisations/meeting_participant_links/changed'+ end+ format.html { redirect_to meeting_path, notice: message, status: :see_other }+ end+ end++ # The dialog again with the reason, in place of the instance that sent it.+ # Gone meanwhile (a move, a deleted participant) is a 404, our own failure a 500.+ def refused(result)+ @errors = result.errors+ status = if INTERNAL_CODES.include?(result.code) then :internal_server_error+ elsif NOT_FOUND_CODES.include?(result.code) then :not_found+ else :unprocessable_content+ end+ respond_to do |format|+ format.turbo_stream { render 'organisations/meeting_participant_links/refused', status: status }+ format.html { redirect_to meeting_path, alert: @errors.to_sentence, status: :see_other }+ end+ end++ def meeting_path+ organisation_project_meetings_path(current_organisation, @project, meeting_id: @meeting.id)+ end++ # A nested or repeated parameter is no value here.+ def scalar_param(key)+ value = params[key]+ value.is_a?(String) ? value : nil+ end+ end+enddiff --git a/app/helpers/meeting_participant_links_helper.rb b/app/helpers/meeting_participant_links_helper.rbnew file mode 100644index 0000000..178e8b8--- /dev/null+++ b/app/helpers/meeting_participant_links_helper.rb@@ -0,0 +1,97 @@+# frozen_string_literal: true++# 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.+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.+ ParticipantPeople = Struct.new(:can_link, :paths, keyword_init: true) do+ def path_for(participant)+ paths[participant.id]+ end+ end++ # The row of one meeting's participants (meeting page and the panel beside a+ # ticket); a link or an unlink redraws it.+ def meeting_participants_row_id(meeting)+ dom_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}"+ 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}"+ end++ # The list of the dialog, reloaded by its search.+ def participant_link_results_id(participant)+ "meeting-participant-link-results-#{participant.id}"+ end++ # The button that opened the dialog: the focus goes back to it.+ def participant_link_trigger_id(participant)+ "meeting-participant-link-trigger-#{participant.id}"+ end++ def meeting_participant_people(meeting, participants)+ return ParticipantPeople.new(can_link: false, paths: {}) unless PersonPolicy.view_allowed?(current_user, current_organisation)++ directory = 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+ end+ ParticipantPeople.new(can_link: policy(meeting).update?, paths: paths)+ end++ # The person page of a directory entry: its row, or a member without one.+ def person_entry_path(entry)+ selection = entry.person ? { person_id: entry.person.id } : { member_id: entry.user.id }+ organisation_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.+ def participant_link_options(participant, query, limit:)+ 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)+ suggested.map { |entry| [entry, true] } + others.map { |entry| [entry, false] }+ end++ # 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?)+ end++ # The name a new person starts with: the participant's, without a note in+ # brackets ("J. Weber (Hoster)" -> "J. Weber").+ def participant_link_new_name(participant)+ participant.display_name.gsub(/\([^)]*\)/, ' ').squish.presence || participant.display_name+ end++ private++ def participant_directory_entry(directory, participant)+ if participant.user_id+ directory.member_entry(participant.user_id)+ elsif participant.person_id+ directory.person_entry(participant.person_id)+ end+ end+enddiff --git a/app/javascript/controllers/CLAUDE.md b/app/javascript/controllers/CLAUDE.mdindex 6926110..3079eb0 100644--- a/app/javascript/controllers/CLAUDE.md+++ b/app/javascript/controllers/CLAUDE.md@@ -1,4 +1,4 @@-# Karte: app/javascript/controllers (Stand: 2026-10-17)+# Karte: app/javascript/controllers (Stand: 2026-10-27)~109 Stimulus-Controller, bewusst FLACH gehalten: Unterordner würden via`eagerLoadControllersFrom` alle Identifier ändern (`meetings/row_controller.js` →@@ -25,6 +25,8 @@ Konventionen:Öffnen, Schließen leert den Frame. Jede Öffnung trägt eine eigene ID (Token): Ablehnung undSpeichern treffen nur sie, eine späte Antwort an ein geschlossenes Modal findet nichts. DasFokus-Rücksprungziel liegt am Frame, nicht an der Instanz.+ Ein weiteres Modal derselben Form erbt den Controller statt ihn zu kopieren+ (`participant_link_modal_controller.js`, seit 27.10.2026: nur das erste Feld ist anders).* **Escape gehört dem Obersten** (`lib/escape_owner.js`, seit 17.10.2026): Jeder Controller, derauf Escape reagiert, beantwortet `ownsEscape()` (wahr, solange sein nächstes Escape etwasEigenes schließt). Ein Overlay, das ein Skript außerhalb eines Controllers baut, trägtdiff --git a/app/javascript/controllers/participant_link_modal_controller.js b/app/javascript/controllers/participant_link_modal_controller.jsnew file mode 100644index 0000000..9de86f4--- /dev/null+++ b/app/javascript/controllers/participant_link_modal_controller.js@@ -0,0 +1,19 @@+import TicketRelationModalController from "controllers/ticket_relation_modal_controller"++/**+ * Participant Link Modal Controller+ *+ * The dialog "Mit Person verknüpfen" beside the participant chips of a meeting (S2b of the+ * people directory, markup in organisations/meeting_participant_links/_modal.html.erb). The+ * same frame-content modal as the ticket relation modal, so it IS that controller: opening+ * on connect, one id per opening, focus trap, closing on the backdrop and on Escape, the+ * focus back to the chip's link button. Only the first field differs: the search.+ */+export default class extends TicketRelationModalController {+ static targets = ["card", "search"]++ connect() {+ super.connect()+ if (!this.discarded && this.hasSearchTarget) this.searchTarget.focus()+ }+}diff --git a/app/javascript/controllers/ticket_relation_modal_controller.js b/app/javascript/controllers/ticket_relation_modal_controller.jsindex c83174d..fd27cef 100644--- a/app/javascript/controllers/ticket_relation_modal_controller.js+++ b/app/javascript/controllers/ticket_relation_modal_controller.js@@ -71,7 +71,8 @@ export default class extends Controller {}returnFocus(frame) {- if (frame.querySelector('[data-controller~="ticket-relation-modal"]')) return+ // By identifier: a dialog built on this one (participant_link_modal) has its own.+ if (frame.querySelector(`[data-controller~="${this.identifier}"]`)) returnconst id = frame.dataset.relationModalReturndelete frame.dataset.relationModalReturndiff --git a/app/models/CLAUDE.md b/app/models/CLAUDE.mdindex 9b6e069..b9eb280 100644--- a/app/models/CLAUDE.md+++ b/app/models/CLAUDE.md@@ -1,4 +1,4 @@-# Karte: app/models (Stand: 2026-10-26)+# Karte: app/models (Stand: 2026-10-27)~80 Modelle liegen flach in diesem Verzeichnis; Namespaces existieren nur für `admin/`,`knowledge/`, `overview/`, `smart_folders/`, `time_sessions/`, `user/`. Die Domänen-Zugehörigkeit ist am@@ -63,6 +63,12 @@ Verzeichnis-Layout nicht ablesbar — diese Karte gruppiert sie:Person) auf eine Zeile; `belongs_to :person` steht VOR `acts_as_tenant`, eine Validierunghält die Person in derselben Org. Ein Mitglied läuft weiter über `user_id`. Meetings und„Letzter Kontakt“ einer Person liest nur `People::Contacts` (`app/services/CLAUDE.md`).+ Seit S2b (27.10.2026) schreibt `person_id` nur `Actors::LinkMeetingParticipant` (Dialog an+ den Teilnehmer-Chips, `MeetingParticipantLinksController`): EIN Schlüssel je Teilnehmer,+ ein Mitglied über `user_id`, ein Kontakt (auch die Zeile eines früheren Mitglieds) über+ `person_id`. Der Actor sperrt das Meeting (`lock_in_project!`) und löst Person und Mitglied+ nur über `People::Directory` des Schreibenden auf. Das Meeting-Formular kennt `person_id`+ nicht; `SaveMeeting` behält die Zeile und damit den Link.* **Activity/Notifications**: `activity`, `user_activity`, `outbox_event`, `notification`,`notification_preference`, `notification_subscription`, `email_log` — Services dazu unter`app/services/notifications/` (eigene Karte dort)diff --git a/app/services/CLAUDE.md b/app/services/CLAUDE.mdindex abe2a37..2e2306d 100644--- a/app/services/CLAUDE.md+++ b/app/services/CLAUDE.md@@ -1,4 +1,4 @@-# Karte: app/services (Stand: 2026-10-26)+# Karte: app/services (Stand: 2026-10-27)**Entry-Point-Konvention für NEUE Services: `Klass.call(**kwargs)`** (Klassenmethode; eineInstanz-`#call`-Implementierung dahinter ist erlaubt). Pflicht: mindestens 1 Kommentarzeile@@ -164,6 +164,10 @@ 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.* `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/link_meeting_participant.rb b/app/services/actors/link_meeting_participant.rbnew file mode 100644index 0000000..45b199a--- /dev/null+++ b/app/services/actors/link_meeting_participant.rb@@ -0,0 +1,106 @@+# frozen_string_literal: true++# app/services/actors/link_meeting_participant.rb+#+# Links one participant of a meeting to the people directory, or unlinks it+# (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 that is a member already+# is linked through its account and is left alone.+#+# The caller authorizes the meeting write (MeetingPolicy#update?). 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:+# PersonPolicy::Scope and MembershipPolicy::Scope, nothing without+# view_people);+# * a new person through Actors::SavePerson in the same transaction, only with+# manage_people.+# No activity: a link carries no personal data worth a history line.+module Actors+ class LinkMeetingParticipant < BaseActor+ def initialize(meeting:, project:, participant_id:, current_user:, person_id: nil, member_id: nil,+ new_person: nil, unlink: false)+ super()+ @meeting = meeting+ @project = project+ @participant_id = participant_id+ @current_user = current_user+ @person_id = person_id.presence+ @member_id = member_id.presence+ @new_person = new_person+ @unlink = unlink+ end++ def record+ @participant+ end++ def perform+ refuse!(:not_found) unless @meeting.lock_in_project!(@project.id)++ @participant = @meeting.meeting_participants.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 @participant.user_id++ return @participant.update!(person_id: nil) if @unlink++ link_to_entry(chosen_entry)+ end++ private++ attr_reader :current_user++ def organisation+ @meeting.organisation+ end++ def chosen_entry+ return 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)+ end++ def link_to_entry(entry)+ if entry.member?+ refuse!(:member_already_participant) if taken_by_another?(entry.user.id)+ @participant.update!(user_id: entry.user.id, person_id: nil)+ else+ @participant.update!(person_id: entry.person.id)+ end+ rescue ActiveRecord::RecordNotUnique+ # The same member linked twice at once: the unique index refuses the second.+ refuse!(:member_already_participant)+ end++ def taken_by_another?(user_id)+ @meeting.meeting_participants.where(user_id: user_id).where.not(id: @participant.id).exists?+ end++ def created_entry+ refuse!(:not_allowed) unless PersonPolicy.manage_allowed?(current_user, organisation)++ 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?++ People::Directory::Entry.new(kind: :contact, person: result.resource)+ end++ def directory+ @directory ||= People::Directory.new(viewer: current_user, organisation: organisation)+ end++ def refuse!(code)+ raise ActorError.new(I18n.t("services.actors.link_meeting_participant.#{code}"), code: code)+ end+ end+enddiff --git a/app/services/people/directory.rb b/app/services/people/directory.rbindex 120457d..1d9081b 100644--- a/app/services/people/directory.rb+++ b/app/services/people/directory.rb@@ -74,6 +74,38 @@ module Peopleeveryone.find { |entry| entry.member? && entry.user.id == user_id.to_s }end+ # The entry of one person row, or nil when the viewer may not see it. A row+ # of an active member the viewer sees is that member's entry.+ def person_entry(person_id)+ everyone.find { |entry| entry.person&.id == person_id.to_s }+ end++ # The entries matching the search, without last contacts: the list of the+ # dialog that links a meeting participant (S2b).+ def candidates+ everyone.select { |entry| @query.blank? || matches?(entry) }+ end++ # The entries that may be the participant of this name (E6): the same full+ # normalized name first, then the same surname. A suggestion only; nothing+ # is linked without a click.+ def suggestions_for(name)+ full = PersonName.normalize(name)+ surname = self.class.surname(name)+ return [] if full.blank?++ same_name = everyone.select { |entry| entry.sort_name == full }+ same_surname = surname ? everyone.select { |entry| self.class.surname(entry.plain_name) == surname } : []+ (same_name + same_surname).uniq+ end++ # 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.reverse.find { |word| word.length > 1 }+ end+# The other entries with the same normalized name as this person: rows and# members that may be the same person (the duplicate hint, read only).def duplicates_of(person)diff --git a/app/views/organisations/meeting_participant_links/_modal.html.erb b/app/views/organisations/meeting_participant_links/_modal.html.erbnew file mode 100644index 0000000..8350295--- /dev/null+++ b/app/views/organisations/meeting_participant_links/_modal.html.erb@@ -0,0 +1,118 @@+<%# locals: (meeting:, participant:, token:, query: '', choice: nil, new_person_name: nil, errors: []) %>+<%# The dialog "Mit Person verknüpfen" (S2b, E4/E6). Lives in the frame of the participant row;+ the trigger beside a chip loads participant_links#new into it. The root carries the id of+ THIS opening (token): a refused save replaces exactly it, a save removes it. Shape and+ lifecycle after README_MODAL_PATTERN.md (reference: the ticket relation modal).++ Two forms side by side, never nested: the search (GET, reloads only the list frame) and+ the link (POST, the list's radios and the new person). Unlinking is a third, its own+ 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) %>+<% form_id = "#{modal_id}-form" %>+<% can_create = PersonPolicy.manage_allowed?(current_user, current_organisation) %>+<div id="<%= participant_link_modal_instance_id(meeting, 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">+ <div class="fixed inset-0 z-50 overflow-y-auto"+ data-action="click->participant-link-modal#closeOnBackdrop">+ <div class="fixed inset-0 bg-gray-500 bg-opacity-60 backdrop-blur-sm" aria-hidden="true"></div>+ <div class="relative flex min-h-screen items-center justify-center p-4"+ data-action="click->participant-link-modal#closeOnBackdrop">+ <div class="participant-link-modal relative w-full max-w-md rounded-lg border border-slate-200 bg-surface-raised shadow-xl"+ role="dialog" aria-modal="true" aria-labelledby="<%= modal_id %>-title"+ data-participant-link-modal-target="card">+ <div class="flex items-start justify-between gap-3 border-b border-slate-200 p-4">+ <div class="min-w-0">+ <h3 id="<%= modal_id %>-title" class="text-lg font-bold text-cream-900">+ <i class="bi bi-link-45deg mr-1" aria-hidden="true"></i>+ <%= t("#{pl}.title") %>+ </h3>+ <p class="mt-0.5 text-sm text-cream-600 break-words"><%= t("#{pl}.participant", name: participant.display_name) %></p>+ </div>+ <button type="button" class="text-gray-400 hover:text-gray-600"+ title="<%= t("#{pl}.close") %>" aria-label="<%= t("#{pl}.close") %>"+ data-action="click->participant-link-modal#close">+ <i class="bi bi-x-lg" aria-hidden="true"></i>+ </button>+ </div>++ <div class="space-y-3 p-5">+ <% if errors.any? %>+ <div class="participant-link-error rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-800" role="alert">+ <% errors.each do |message| %>+ <p><%= message %></p>+ <% end %>+ </div>+ <% end %>++ <% if participant.person_id %>+ <% current = People::Directory.new(viewer: current_user, organisation: current_organisation).person_entry(participant.person_id) %>+ <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") %>+ </span>+ <%= button_to t("#{pl}.unlink"),+ organisation_project_meeting_participant_link_path(current_organisation, meeting.project, meeting, participant),+ method: :delete, params: { modal_token: token },+ class: 'participant-link-unlink shrink-0 text-sm font-medium text-cream-700 underline hover:text-ink' %>+ </div>+ <% end %>++ <%= form_with url: new_organisation_project_meeting_participant_link_path(current_organisation, meeting.project, meeting, participant),+ method: :get, class: 'participant-link-search',+ data: { controller: 'auto-submit', turbo_frame: participant_link_results_id(participant) } do %>+ <label for="<%= modal_id %>-search" class="sr-only"><%= t("#{pl}.search_label") %></label>+ <div class="relative">+ <i class="bi bi-search pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-cream-500" aria-hidden="true"></i>+ <%= search_field_tag :q, query, id: "#{modal_id}-search", autocomplete: 'off',+ placeholder: t("#{pl}.search_placeholder"),+ class: 'w-full rounded border border-cream-300 bg-surface-raised py-2 pl-9 pr-3 text-sm focus:border-ink focus:outline-none focus:ring-1 focus:ring-ink',+ data: { participant_link_modal_target: 'search' } %>+ </div>+ <% end %>++ <%= form_with url: organisation_project_meeting_participant_link_path(current_organisation, meeting.project, meeting, participant),+ method: :post, id: form_id, class: 'space-y-3' do %>+ <%= hidden_field_tag :modal_token, token, id: nil %>+ <%= render 'organisations/meeting_participant_links/results',+ meeting: meeting, participant: participant, query: query, choice: choice %>++ <% if can_create %>+ <% new_checked = choice == Organisations::MeetingParticipantLinksController::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,+ 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">+ <i class="bi bi-plus-lg mr-1" aria-hidden="true"></i><%= t("#{pl}.new_person") %>+ </label>+ <%= text_field_tag :new_person_name, new_person_name || participant_link_new_name(participant),+ id: "#{modal_id}-new-name", autocomplete: 'off',+ aria: { label: t("#{pl}.new_person_name") },+ class: 'w-full rounded border border-cream-300 bg-surface-raised px-2 py-1 text-sm focus:border-ink focus:outline-none focus:ring-1 focus:ring-ink' %>+ </span>+ </div>+ <% end %>++ <p class="text-xs text-cream-500"><%= t("#{pl}.hint") %></p>++ <div class="flex justify-end gap-2 border-t border-cream-200 pt-3">+ <button type="button"+ class="h-9 rounded border border-cream-300 bg-cream-100 px-4 text-sm font-medium text-cream-800 hover:bg-cream-200"+ data-action="click->participant-link-modal#close">+ <%= t("#{pl}.cancel") %>+ </button>+ <button type="submit"+ class="h-9 rounded border border-ink bg-lime-300 px-4 text-sm font-bold text-ink hover:bg-lime-400">+ <%= t("#{pl}.submit") %>+ </button>+ </div>+ <% end %>+ </div>+ </div>+ </div>+ </div>+</div>diff --git a/app/views/organisations/meeting_participant_links/_results.html.erb b/app/views/organisations/meeting_participant_links/_results.html.erbnew file mode 100644index 0000000..4fcce6c--- /dev/null+++ b/app/views/organisations/meeting_participant_links/_results.html.erb@@ -0,0 +1,41 @@+<%# locals: (meeting:, participant:, query:, choice: nil) %>+<%# The people the dialog offers, in their own frame so the search reloads only them: the+ suggestions 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. %>+<% pl = 'views.organisations.meetings.participant_links' %>+<% options = participant_link_options(participant, query, limit: Organisations::MeetingParticipantLinksController::LIST_LIMIT) %>+<%= turbo_frame_tag participant_link_results_id(participant), class: 'block' do %>+ <% if options.empty? %>+ <p class="participant-link-none px-2 py-2 text-sm text-cream-600"><%= t("#{pl}.none") %></p>+ <% 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) %>+ <% 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">+ <%= radio_button_tag :choice, value, choice == value, id: input_id, class: 'shrink-0' %>+ <%= render Neo::Users::AvatarComponent.new(user: (entry.user if entry.member?), size: :small,+ fallback_initials: person_initials(name),+ class: "people-avatar #{'people-avatar--contact' unless entry.member?}") %>+ <label for="<%= input_id %>" class="flex min-w-0 flex-1 cursor-pointer flex-col">+ <span class="flex min-w-0 items-center gap-2">+ <span class="truncate text-sm font-medium text-ink"><%= name %></span>+ <% if entry.member? %>+ <span class="people-badge"><%= t('views.organisations.people.index.member_badge') %></span>+ <% end %>+ </span>+ <% detail = participant_link_detail(entry) %>+ <% if detail.present? %>+ <span class="truncate text-xs text-cream-600"><%= detail %></span>+ <% end %>+ </label>+ <% if 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>+ <% end %>+ </ul>+ <% end %>+<% end %>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.erbnew file mode 100644index 0000000..3ceb8c4--- /dev/null+++ b/app/views/organisations/meeting_participant_links/_row_stream.turbo_stream.erb@@ -0,0 +1,6 @@+<%# locals: (meeting:) %>+<%# The participant row of this meeting as it is now, wherever the page shows it (the+ meeting's page or the panel beside a ticket). %>+<%= turbo_stream.replace meeting_participants_row_id(meeting),+ partial: 'organisations/meetings/participants_row',+ locals: { meeting: meeting, participants: meeting.meeting_participants.order(:created_at).to_a } %>diff --git a/app/views/organisations/meeting_participant_links/changed.turbo_stream.erb b/app/views/organisations/meeting_participant_links/changed.turbo_stream.erbnew file mode 100644index 0000000..07b9508--- /dev/null+++ b/app/views/organisations/meeting_participant_links/changed.turbo_stream.erb@@ -0,0 +1,8 @@+<%# A participant of THIS meeting was linked or unlinked: the dialog instance that sent it+ removed (its controller then empties the frame and returns the focus), the participant+ row redrawn, the flash. %>+<% if @modal_token %>+ <%= turbo_stream.remove participant_link_modal_instance_id(@meeting, @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/new.html.erb b/app/views/organisations/meeting_participant_links/new.html.erbnew file mode 100644index 0000000..b6ccb72--- /dev/null+++ b/app/views/organisations/meeting_participant_links/new.html.erb@@ -0,0 +1,6 @@+<%# The dialog "Mit Person verknüpfen", loaded into its frame by a trigger of the participant+ row (layout: false, only the frame counts). See _modal. %>+<%= turbo_frame_tag participant_link_modal_id(@meeting) 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/refused.turbo_stream.erb b/app/views/organisations/meeting_participant_links/refused.turbo_stream.erbnew file mode 100644index 0000000..db5359e--- /dev/null+++ b/app/views/organisations/meeting_participant_links/refused.turbo_stream.erb@@ -0,0 +1,15 @@+<%# The link was refused (nothing picked, a member already in the meeting, no right to create+ a person, gone meanwhile): 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+ closed. Without a usable token there is no instance to fill: the reason goes out as a+ flash, 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 %>+ <%= render 'organisations/meeting_participant_links/modal',+ meeting: @meeting, participant: @participant, token: @modal_token,+ choice: @choice, new_person_name: @new_person_name, errors: @errors %>+ <% end %>+<% else %>+ <%= render 'organisations/meeting_participant_links/row_stream', meeting: @meeting %>+ <%= turbo_stream.prepend 'flash', partial: 'layouts/flash', locals: { flash: { alert: @errors.to_sentence } } %>+<% end %>diff --git a/app/views/organisations/meetings/_participants_row.html.erb b/app/views/organisations/meetings/_participants_row.html.erbindex 7327650..f7ee0b2 100644--- a/app/views/organisations/meetings/_participants_row.html.erb+++ b/app/views/organisations/meetings/_participants_row.html.erb@@ -1,25 +1,56 @@<%# locals: (meeting:, participants:) %>-<%# The participants of a meeting as chips, read only: the meeting's page and the panel- beside a ticket render this one row. The caller loads the participants, because the- transcript below needs the same list for its speaker names. %>+<%# The participants of a meeting as chips: the meeting's page and the panel beside a ticket+ render this one row. The caller loads the participants, because the transcript below+ needs the same list for its speaker names.++ S2b (people directory): a participant whose person the viewer may see is a link to that+ person; a free name stays text. With the meeting write and view_people, a name that is+ no member gets the action "Mit Person verknüpfen" (a linked one: "Verknüpfung ändern"),+ which loads the dialog into the frame at the end of the row. A link or an unlink+ redraws the row (meeting_participants_row_id). %><% if participants.any? %><% permitted_user_ids = meeting.project.permitted_user_ids.to_set %>- <div class="mt-3 flex min-w-0 flex-wrap items-start gap-2">+ <% people = meeting_participant_people(meeting, participants) %>+ <% pl = 'views.organisations.meetings.participant_links' %>+ <div id="<%= meeting_participants_row_id(meeting) %>" class="mt-3 flex min-w-0 flex-wrap items-start gap-2"><span class="pt-0.5 text-xs font-mono uppercase tracking-wider text-cream-600"><%= t('views.organisations.meetings.show.participants_heading') %></span><div class="flex min-w-0 flex-1 flex-wrap gap-2"><% participants.each do |participant| %><% chip_style = meeting_participant_chip_style(meeting_participant_type(participant, permitted_user_ids)) %>- <%= render NeoTagComponent.new(- text: participant.display_name,- variant: chip_style[:variant],- icon: chip_style[:icon],- title: chip_style[:title],- size: :small,- class: 'max-w-full [&_.tag-text]:break-words [&_.tag-text]:[overflow-wrap:anywhere]'- ) %>+ <% path = people.path_for(participant) %>+ <span class="meeting-participant inline-flex min-w-0 max-w-full items-center gap-0.5">+ <% chip = render NeoTagComponent.new(+ text: participant.display_name,+ variant: chip_style[:variant],+ icon: chip_style[:icon],+ title: chip_style[:title],+ size: :small,+ class: 'max-w-full [&_.tag-text]:break-words [&_.tag-text]:[overflow-wrap:anywhere]'+ ) %>+ <% if path %>+ <%= link_to chip, path, class: 'meeting-participant__person min-w-0 max-w-full rounded-full',+ data: { turbo_frame: '_top' },+ aria: { label: t("#{pl}.open_person", name: participant.display_name) } %>+ <% else %>+ <%= chip %>+ <% end %>+ <% if people.can_link && participant.user_id.nil? %>+ <% action_label = participant.person_id ? t("#{pl}.change", name: participant.display_name) : t("#{pl}.link", name: participant.display_name) %>+ <%= link_to new_organisation_project_meeting_participant_link_path(current_organisation, meeting.project, meeting, participant),+ 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 %>+ <i class="bi <%= participant.person_id ? 'bi-pencil' : 'bi-link-45deg' %>" aria-hidden="true"></i>+ <% end %>+ <% end %>+ </span><% end %></div>+ <% if people.can_link %>+ <%= turbo_frame_tag participant_link_modal_id(meeting) %>+ <% end %></div><% end %>diff --git a/config/importmap.rb b/config/importmap.rbindex 3639916..1e41978 100644--- a/config/importmap.rb+++ b/config/importmap.rb@@ -221,6 +221,7 @@ elsepin 'controllers/notification_count_data_controller', to: 'controllers/notification_count_data_controller.js'pin 'controllers/notification_count_listener_controller', to: 'controllers/notification_count_listener_controller.js'pin 'controllers/pane_mark_read_delay_controller', to: 'controllers/pane_mark_read_delay_controller.js'+ pin 'controllers/participant_link_modal_controller', to: 'controllers/participant_link_modal_controller.js'pin 'controllers/personal_tasks_drawer_controller', to: 'controllers/personal_tasks_drawer_controller.js'pin 'controllers/popover_controller', to: 'controllers/popover_controller.js'pin 'controllers/post_composer_controller', to: 'controllers/post_composer_controller.js'diff --git a/config/locales/controllers.de.yml b/config/locales/controllers.de.ymlindex d0729d0..4aec3de 100644--- a/config/locales/controllers.de.yml+++ b/config/locales/controllers.de.yml@@ -243,6 +243,9 @@ de:removed: "Verknüpfung wurde entfernt."already_linked: "Diese Aufgabe ist bereits mit dem Meeting verknüpft."blank_selection: "Bitte zuerst eine Aufgabe auswählen."+ meeting_participant_links:+ linked: "Der Teilnehmer ist verknüpft."+ unlinked: "Die Verknüpfung ist gelöst."ticket_relations:created: "Die Tickets sind verknüpft."removed: "Die Beziehung wurde entfernt."diff --git a/config/locales/controllers.en.yml b/config/locales/controllers.en.ymlindex 852a16c..cd9b25e 100644--- a/config/locales/controllers.en.yml+++ b/config/locales/controllers.en.yml@@ -239,6 +239,9 @@ en:removed: "Link was removed."already_linked: "This task is already linked to the meeting."blank_selection: "Please pick a task first."+ meeting_participant_links:+ linked: "The participant is linked."+ unlinked: "The link was removed."ticket_relations:created: "The tickets are linked."removed: "The relation was removed."diff --git a/config/locales/services.de.yml b/config/locales/services.de.ymlindex 8de0470..a8fb96a 100644--- a/config/locales/services.de.yml+++ b/config/locales/services.de.yml@@ -47,6 +47,12 @@ de:ticket_missing: "Eines der beiden Tickets gibt es nicht mehr."destroy_ticket_relation:not_found: "Die Beziehung wurde nicht gefunden."+ link_meeting_participant:+ not_found: "Teilnehmer oder Person wurden nicht gefunden. Lade die Seite neu."+ 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."+ not_allowed: "Du darfst keine Personen anlegen."move_meeting:same_project: "Das Meeting liegt schon in diesem Projekt."forbidden_target: "In diesem Projekt darfst du keine Meetings anlegen."diff --git a/config/locales/services.en.yml b/config/locales/services.en.ymlindex 4c73191..900cec9 100644--- a/config/locales/services.en.yml+++ b/config/locales/services.en.yml@@ -47,6 +47,12 @@ en:ticket_missing: "One of the two tickets no longer exists."destroy_ticket_relation:not_found: "The relation was not found."+ link_meeting_participant:+ not_found: "Participant or person not found. Reload the page."+ 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."+ not_allowed: "You may not create people."move_meeting:same_project: "The meeting is already in this project."forbidden_target: "You may not add meetings to this project."diff --git a/config/locales/views/meetings.de.yml b/config/locales/views/meetings.de.ymlindex 7f6a871..3a74e1b 100644--- a/config/locales/views/meetings.de.yml+++ b/config/locales/views/meetings.de.yml@@ -132,6 +132,25 @@ de:remove: Verknüpfung entfernenpicker_placeholder: Aufgabe suchen …deleted_badge: gelöscht+ participant_links:+ title: Mit Person verknüpfen+ participant: "Teilnehmer „%{name}“"+ close: Schließen+ search_label: Person suchen+ search_placeholder: Name, Firma oder E-Mail+ suggestion: Vorschlag+ none: Keine Person gefunden.+ new_person: Neue Person anlegen+ new_person_name: Name der neuen Person+ submit: Verknüpfen+ cancel: Abbrechen+ linked_to: "Verknüpft mit %{name}"+ linked: Mit einer Person verknüpft+ unlink: Verknüpfung lösen+ hint: Vorgeschlagen wird bei gleichem Namen oder Nachnamen; nichts wird ohne Klick verknüpft.+ link: "%{name} mit Person verknüpfen"+ change: "Verknüpfung von %{name} ändern"+ open_person: "%{name}: Person öffnen"shared:duration_minutes: "%{count} Min"participant_type:diff --git a/config/locales/views/meetings.en.yml b/config/locales/views/meetings.en.ymlindex cbf2e43..bb9ede0 100644--- a/config/locales/views/meetings.en.yml+++ b/config/locales/views/meetings.en.yml@@ -131,6 +131,25 @@ en:remove: Remove linkpicker_placeholder: Search tasks …deleted_badge: deleted+ participant_links:+ title: Link to a person+ participant: "Participant “%{name}”"+ close: Close+ search_label: Search people+ search_placeholder: Name, company or email+ suggestion: Suggestion+ none: No person found.+ new_person: Create a new person+ new_person_name: Name of the new person+ submit: Link+ cancel: Cancel+ linked_to: "Linked to %{name}"+ linked: Linked to a person+ unlink: Unlink+ hint: Suggestions come from the same name or surname; nothing is linked without a click.+ link: "Link %{name} to a person"+ change: "Change the link of %{name}"+ open_person: "%{name}: open person"shared:duration_minutes: "%{count} min"participant_type:diff --git a/config/routes.rb b/config/routes.rbindex 89437cd..7558c50 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -793,6 +793,11 @@ Rails.application.routes.draw doget :move_preflightpost :moveend+ # Linking a participant to the people directory (S2b): new renders the dialog into+ # its frame (?q= searches), create links, destroy unlinks.+ resources :participants, only: [] do+ resource :link, only: %i[new create destroy], controller: 'meeting_participant_links'+ endcollection do# LLM participant detection (Slice 5): runs BEFORE save on the raw# transcript payload (scoping via @project, no persisted meeting);diff --git a/spec/architecture/meeting_lock_guard_spec.rb b/spec/architecture/meeting_lock_guard_spec.rbindex 0d7ea87..5859a80 100644--- a/spec/architecture/meeting_lock_guard_spec.rb+++ b/spec/architecture/meeting_lock_guard_spec.rb@@ -38,6 +38,7 @@ module MeetingLockGuard}.freezeWRITERS = %w[+ app/services/actors/link_meeting_participant.rbapp/services/actors/move_meeting.rbapp/services/actors/save_meeting.rbapp/services/actors/save_meeting_analysis.rb@@ -50,13 +51,14 @@ module MeetingLockGuard# or write no meeting that exists.CONTROLLERS = {'organisations/meetings' => 'app/controllers/organisations/meetings_controller.rb',- 'organisations/meeting_ticket_links' => 'app/controllers/organisations/meeting_ticket_links_controller.rb'+ 'organisations/meeting_ticket_links' => 'app/controllers/organisations/meeting_ticket_links_controller.rb',+ 'organisations/meeting_participant_links' => 'app/controllers/organisations/meeting_participant_links_controller.rb'}.freezeCONTROLLER_LOCK = 'with_meeting_in_project'# Each one is in WRITERS (checked below).- LOCKING_ACTORS = %w[Actors::SaveMeeting Actors::MoveMeeting].freeze+ LOCKING_ACTORS = %w[Actors::SaveMeeting Actors::MoveMeeting Actors::LinkMeetingParticipant].freeze# Only shrinks; every entry gives its reason.NO_MEETING_YET = {diff --git a/spec/requests/organisations/meeting_participant_links_spec.rb b/spec/requests/organisations/meeting_participant_links_spec.rbnew file mode 100644index 0000000..9e20b18--- /dev/null+++ b/spec/requests/organisations/meeting_participant_links_spec.rb@@ -0,0 +1,402 @@+# frozen_string_literal: true++require 'rails_helper'++# Linking a meeting participant to the people directory (S2b): the chips of the+# meeting page and of the panel beside a ticket, the dialog, and its three+# 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+ let(:organisation) { create(:organisation) }++ before { ActsAsTenant.current_tenant = organisation }+ after { ActsAsTenant.current_tenant = nil }++ let(:project) { create(:project, organisation: organisation, name: 'Relaunch') }+ let(:meeting) { create(:meeting, organisation: organisation, project: project, title: 'Hosting-Abstimmung') }+ let!(:participant) { create(:meeting_participant, meeting: meeting, display_name: 'J. Weber (Hoster)') }+ let!(:contact) { create(:person, organisation: organisation, name: 'Jonas Weber', function: 'Hosting') }+ let(:pl) { 'views.organisations.meetings.participant_links' }+ # One opening of the dialog, as the form echoes it.+ let(:modal_token) { SecureRandom.hex(8) }+ let(:stream) { { 'Accept' => 'text/vnd.turbo-stream.html' } }+ let(:detail_frame) { { 'Turbo-Frame' => Organisations::MeetingsController::DETAIL_FRAME_ID } }++ def member_with(role, first_name:, active: true)+ user = create(:user, first_name: first_name, last_name: 'Beispiel')+ create(:membership, user: user, organisation: organisation, role: role, active: active)+ User.find(user.id)+ end++ def role_with(*people_actions)+ role = create(:role, organisation: organisation)+ people_actions.each { |action| create(:permission, role: role, category: 'people', action: action, allowed: true) }+ role+ end++ def admin+ @admin ||= member_with(create(:role, organisation: organisation, title: Role::ACCOUNT_ADMIN_TITLE), first_name: 'Anna')+ end++ # Meetings write in the project, plus the given people rights.+ def writer(*people_actions, first_name: 'Willi')+ member_with(role_with(*people_actions), first_name: first_name).tap do |user|+ create(:project_permission, user: user, project: project, meetings_access: :read_write, tickets_access: :read_only)+ end+ end++ def show_meeting+ get organisation_project_meeting_path(organisation, project, meeting, frame: 'content'), headers: detail_frame+ end++ def link_path(target = participant, on: meeting, in_project: project)+ organisation_project_meeting_participant_link_path(organisation, in_project, on, target)+ end++ def new_link_path(target = participant)+ new_organisation_project_meeting_participant_link_path(organisation, project, meeting, target)+ end++ def post_link(choice, target: participant, on: meeting, in_project: project, **extra)+ post link_path(target, on: on, in_project: in_project),+ params: { choice: choice, modal_token: modal_token }.merge(extra), headers: stream+ end++ describe 'the participant row' do+ it 'offers the link action to a writer with view_people' do+ sign_in writer('view_people')+ show_meeting++ expect(response).to have_http_status(:ok)+ expect(response.body).to include('J. Weber (Hoster)')+ expect(response.body).to include(CGI.escapeHTML(new_link_path))+ expect(response.body).to include(I18n.t("#{pl}.link", name: 'J. Weber (Hoster)'))+ end++ it 'offers nothing without view_people, and links no chip' do+ participant.update!(person: contact)+ sign_in writer+ show_meeting++ expect(response.body).to include('J. Weber (Hoster)')+ expect(response.body).not_to include(new_link_path)+ expect(response.body).not_to include(organisation_people_path(organisation, person_id: contact.id))+ end++ it 'offers nothing to a reader of the meeting, but links the chip' do+ participant.update!(person: contact)+ reader = member_with(role_with('view_people'), first_name: 'Rita')+ create(:project_permission, user: reader, project: project, meetings_access: :read_only)+ sign_in reader+ show_meeting++ expect(response.body).to include('J. Weber (Hoster)')+ expect(response.body).not_to include(new_link_path)+ expect(response.body).to include(CGI.escapeHTML(organisation_people_path(organisation, person_id: contact.id)))+ end++ it 'links a member chip to the member, with or without a row, and offers no link for it' do+ colleague = member_with(create(:role, organisation: organisation), first_name: 'Carl')+ member_participant = create(:meeting_participant, meeting: meeting, display_name: 'Carl Beispiel', user: colleague)+ sign_in admin+ show_meeting++ expect(response.body).to include(CGI.escapeHTML(organisation_people_path(organisation, member_id: colleague.id)))+ expect(response.body).not_to include(new_link_path(member_participant))++ row = create(:person, organisation: organisation, name: 'Carl Beispiel', user: colleague)+ show_meeting+ expect(response.body).to include(CGI.escapeHTML(organisation_people_path(organisation, person_id: row.id)))+ end++ it '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)+ participant.update!(person: hidden_row)+ viewer = writer('view_people')+ sign_in viewer+ show_meeting++ expect(response.body).to include('J. Weber (Hoster)')+ expect(response.body).not_to include(organisation_people_path(organisation, person_id: hidden_row.id))+ expect(response.body).not_to include('Hanna Beispiel')+ end++ it 'renders the row of several participants in a fixed number of queries' do+ Prosopite.pause do+ 3.times { |i| create(:meeting_participant, meeting: meeting, display_name: "Gast #{i}", person: create(:person, organisation: organisation)) }+ end+ sign_in admin++ show_meeting++ expect(response).to have_http_status(:ok)+ end++ it 'shows the links in the panel beside a ticket too' do+ ticket = create(:ticket, project: project, organisation: organisation, title: 'Ticket mit Meeting')+ meeting.outgoing_references.create!(organisation: organisation, target: ticket, target_title_snapshot: ticket.display_title)+ participant.update!(person: contact)+ sign_in admin++ get organisation_project_ticket_meeting_panel_path(organisation, project, ticket, meeting_id: meeting.id),+ headers: { 'Turbo-Frame' => 'ticket_meeting_panel' }++ expect(response).to have_http_status(:ok)+ expect(response.body).to include('J. Weber (Hoster)')+ expect(response.body).to include(CGI.escapeHTML(organisation_people_path(organisation, person_id: contact.id)))+ expect(response.body).to include(CGI.escapeHTML(new_link_path))+ end+ end++ describe 'the dialog' do+ it 'names the participant, suggests the same surname first and offers a new person' do+ create(:person, organisation: organisation, name: 'Anton Anders')+ sign_in admin++ get new_link_path, headers: { 'Turbo-Frame' => "meeting-participant-link-modal-#{meeting.id}" }++ expect(response).to have_http_status(:ok)+ body = response.body+ expect(body).to include(CGI.escapeHTML(I18n.t("#{pl}.participant", name: 'J. Weber (Hoster)')))+ expect(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/)+ end++ it 'searches in its list frame' do+ create(:person, organisation: organisation, name: 'Anton Anders')+ sign_in admin++ get new_link_path, params: { q: 'anders' }, headers: { 'Turbo-Frame' => "meeting-participant-link-results-#{participant.id}" }++ expect(response.body).to include('Anton Anders')+ expect(response.body).not_to include('Jonas Weber')+ expect(response.body).not_to include(I18n.t("#{pl}.suggestion"))+ end++ it 'offers no new person without manage_people' do+ sign_in writer('view_people')++ get new_link_path++ expect(response.body).to include('Jonas Weber')+ expect(response.body).not_to include(I18n.t("#{pl}.new_person"))+ end++ it 'lists no person of another organisation and no row of an invisible member' do+ ActsAsTenant.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)+ sign_in writer('view_people')++ get new_link_path++ expect(response.body).to include('Jonas Weber')+ expect(response.body).not_to include('Fremde Weber')+ expect(response.body).not_to include('Hanna Weber')+ end+ end++ describe 'linking' do+ it 'links a contact: the row becomes a link, and the person lists the meeting' do+ sign_in admin++ post_link("person:#{contact.id}")++ expect(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('action="remove" target="meeting-participant-link-modal-')+ expect(response.body).to include(CGI.escapeHTML(organisation_people_path(organisation, person_id: contact.id)))++ get organisation_people_path(organisation, person_id: contact.id), headers: { 'Turbo-Frame' => Organisations::PeopleController::DETAIL_FRAME_ID }+ expect(response.body).to include('Hosting-Abstimmung')+ end++ it 'links a member by account and leaves person_id empty' do+ colleague = member_with(create(:role, organisation: organisation), first_name: 'Carl')+ sign_in admin++ post_link("member:#{colleague.id}")++ expect(participant.reload.user_id).to eq(colleague.id)+ expect(participant.person_id).to be_nil+ end++ it 'refuses a member already in the meeting with the dialog and a reason' do+ colleague = member_with(create(:role, organisation: organisation), first_name: 'Carl')+ create(:meeting_participant, meeting: meeting, display_name: 'Carl Beispiel', user: colleague)+ sign_in admin++ post_link("member:#{colleague.id}")++ expect(response).to have_http_status(:unprocessable_content)+ expect(response.body).to include('action="replace" target="meeting-participant-link-modal-')+ expect(response.body).to include(I18n.t('services.actors.link_meeting_participant.member_already_participant'))+ expect(participant.reload.user_id).to be_nil+ end++ it 'refuses without a choice' do+ sign_in admin++ post_link('')++ expect(response).to have_http_status(:unprocessable_content)+ expect(response.body).to include(I18n.t('services.actors.link_meeting_participant.nothing_picked'))+ end++ it 'creates a person and links it' do+ sign_in writer('manage_people')++ expect { post_link('new', new_person_name: 'J. Weber') }.to change(Person, :count).by(1)+ expect(participant.reload.person.name).to eq('J. Weber')+ end++ it 'creates no person without manage_people' do+ sign_in writer('view_people')++ expect { post_link('new', new_person_name: 'J. Weber') }.not_to change(Person, :count)+ expect(response).to have_http_status(:unprocessable_content)+ expect(participant.reload.person_id).to be_nil+ end++ it 'unlinks' do+ participant.update!(person: contact)+ sign_in writer('view_people')++ delete link_path, params: { modal_token: modal_token }, headers: stream++ expect(response).to have_http_status(:ok)+ expect(participant.reload.person_id).to be_nil+ expect(response.body).to include(I18n.t('flash.meeting_participant_links.unlinked'))+ end+ end++ describe 'who may not link' do+ def expect_unchanged+ expect(participant.reload.person_id).to be_nil+ expect(participant.user_id).to be_nil+ end++ it 'refuses a writer without view_people, also the dialog' do+ sign_in writer++ post_link("person:#{contact.id}")+ expect(response).to have_http_status(:found)+ get new_link_path+ expect(response).to have_http_status(:found)+ expect(response.body).not_to include(I18n.t("#{pl}.title"))+ expect_unchanged+ end++ it 'refuses a reader of the meeting with view_people' do+ reader = member_with(role_with('manage_people'), first_name: 'Rita')+ create(:project_permission, user: reader, project: project, meetings_access: :read_only)+ sign_in reader++ post_link("person:#{contact.id}")+ expect(response).to have_http_status(:found)+ get new_link_path+ expect(response).to have_http_status(:found)+ expect_unchanged+ end++ it 'refuses a member of another organisation' do+ stranger_org = create(:organisation)+ stranger = ActsAsTenant.with_tenant(stranger_org) do+ user = create(:user)+ create(:membership, user: user, organisation: stranger_org,+ role: create(:role, organisation: stranger_org, title: Role::ACCOUNT_ADMIN_TITLE), active: true)+ user+ end+ sign_in stranger++ post_link("person:#{contact.id}")++ expect(response.status).to be_in([302, 404])+ expect_unchanged+ end++ it 'does not find a person of another organisation' do+ foreign = ActsAsTenant.with_tenant(create(:organisation)) { create(:person, name: 'Fremde Weber') }+ sign_in admin++ post_link("person:#{foreign.id}")++ expect(response).to have_http_status(:not_found)+ expect_unchanged+ end++ it '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)+ sign_in writer('view_people')++ post_link("person:#{hidden_row.id}")+ expect(response).to have_http_status(:not_found)+ post_link("member:#{hidden_member.id}")+ expect(response).to have_http_status(:not_found)+ expect_unchanged+ end++ it 'does not find a participant of another meeting' do+ other_meeting = create(:meeting, organisation: organisation, project: project)+ other = create(:meeting_participant, meeting: other_meeting, display_name: 'Jonas Weber')+ sign_in admin++ post link_path(other), params: { choice: "person:#{contact.id}" }, headers: stream++ expect(response).to have_http_status(:not_found)+ expect(other.reload.person_id).to be_nil+ end++ it 'does not find a meeting moved into another project' do+ target = create(:project, organisation: organisation)+ Actors::MoveMeeting.call(meeting: meeting, target_project: target, current_user: admin)+ expect(meeting.reload.project_id).to eq(target.id)+ sign_in admin++ post_link("person:#{contact.id}")++ expect(response).to have_http_status(:not_found)+ expect_unchanged+ end+ end++ describe 'a later edit of the meeting' do+ def edit_with(display_name:, user_id: nil)+ patch organisation_project_meeting_path(organisation, project, meeting, format: :turbo_stream),+ params: { meeting: { title: meeting.title, participants: [{ display_name: display_name, user_id: user_id.to_s }] },+ frame_id: Organisations::MeetingsController::DETAIL_FRAME_ID }+ end++ it 'keeps a contact link when the name stays' do+ sign_in admin+ post_link("person:#{contact.id}")++ edit_with(display_name: 'J. Weber (Hoster)')++ expect(response).to have_http_status(:ok)+ expect(participant.reload.person_id).to eq(contact.id)+ end++ it 'keeps a member link, which the form sends as user_id' do+ colleague = member_with(create(:role, organisation: organisation), first_name: 'Carl')+ sign_in admin+ post_link("member:#{colleague.id}")++ edit_with(display_name: 'J. Weber (Hoster)', user_id: colleague.id)++ expect(response).to have_http_status(:ok)+ expect(participant.reload.user_id).to eq(colleague.id)+ end+ end+enddiff --git a/spec/services/actors/link_meeting_participant_spec.rb b/spec/services/actors/link_meeting_participant_spec.rbnew file mode 100644index 0000000..43ec314--- /dev/null+++ b/spec/services/actors/link_meeting_participant_spec.rb@@ -0,0 +1,240 @@+# frozen_string_literal: true++require 'rails_helper'++# Linking a meeting participant to a row of the people directory (S2b). The+# actor resolves every id itself: the participant through the locked meeting,+# 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+ let(:organisation) { create(:organisation) }++ before { ActsAsTenant.current_tenant = organisation }+ after { ActsAsTenant.current_tenant = nil }++ let(:project) { create(:project, organisation: organisation) }+ let(:admin_role) { create(:role, organisation: organisation, title: Role::ACCOUNT_ADMIN_TITLE) }+ let(:writer) { member(role: admin_role, first_name: 'Anna') }+ let(:meeting) { create(:meeting, organisation: organisation, project: project) }+ let!(:participant) { create(:meeting_participant, meeting: meeting, display_name: 'J. Weber (Hoster)') }+ let!(:contact) { create(:person, organisation: organisation, name: 'Jonas Weber') }++ def member(role: create(:role, organisation: organisation), first_name: 'Mia', org: organisation, active: true)+ user = create(:user, first_name: first_name, last_name: "Beispiel#{SecureRandom.hex(2)}")+ create(:membership, user: user, organisation: org, role: role, active: active)+ User.find(user.id)+ end++ def role_with(*actions)+ role = create(:role, organisation: organisation)+ actions.each { |action| create(:permission, role: role, category: 'people', action: action, allowed: true) }+ role+ end++ def link(user: writer, participant_id: participant.id, authorized_project: project, **choice)+ described_class.call(meeting: meeting, project: authorized_project, participant_id: participant_id,+ current_user: user, **choice)+ end++ describe 'linking a contact' do+ it 'sets person_id and leaves user_id empty' do+ result = link(person_id: contact.id)++ expect(result).to be_success+ expect(result.resource).to eq(participant)+ expect(participant.reload.person_id).to eq(contact.id)+ expect(participant.user_id).to be_nil+ expect(participant.display_name).to eq('J. Weber (Hoster)')+ end++ it 'moves a linked contact participant to another contact' do+ other = create(:person, organisation: organisation, name: 'Jana Weber')+ link(person_id: contact.id)++ expect(link(person_id: other.id)).to be_success+ expect(participant.reload.person_id).to eq(other.id)+ end++ it 'writes no activity for the person' do+ expect { link(person_id: contact.id) }.not_to(change { Activity.where(trackable: contact).count })+ end++ it 'treats the row of a former member as a contact (person_id)' do+ former = member+ row = create(:person, organisation: organisation, name: 'Fritz Frueher', user: former)+ Membership.where(user: former, organisation: organisation).update_all(active: false)++ expect(link(person_id: row.id)).to be_success+ expect(participant.reload.person_id).to eq(row.id)+ expect(participant.user_id).to be_nil+ end+ end++ describe 'linking a member' do+ let(:colleague) { member(first_name: 'Carl') }++ it 'sets user_id and leaves person_id empty, by member id' do+ expect(link(member_id: colleague.id)).to be_success+ expect(participant.reload.user_id).to eq(colleague.id)+ expect(participant.person_id).to be_nil+ end++ it 'sets user_id when the chosen person row belongs to an active member' do+ row = create(:person, organisation: organisation, name: colleague.display_name, user: colleague)+ link(person_id: contact.id)++ expect(link(person_id: row.id)).to be_success+ expect(participant.reload.user_id).to eq(colleague.id)+ expect(participant.person_id).to be_nil+ end++ it 'refuses a member who already takes part in the meeting, changing nothing' do+ create(:meeting_participant, meeting: meeting, display_name: colleague.display_name, user: colleague)++ result = link(member_id: colleague.id)++ expect(result).not_to be_success+ expect(result.code).to eq(:member_already_participant)+ expect(result.errors).to eq([I18n.t('services.actors.link_meeting_participant.member_already_participant')])+ expect(participant.reload.user_id).to be_nil+ end+ end++ describe 'a participant that is a member' do+ it 'is not linked again (its account is the link)' do+ colleague = member(first_name: 'Carl')+ participant.update!(user: colleague)++ result = link(person_id: contact.id)++ expect(result.code).to eq(:member_participant)+ expect(participant.reload.person_id).to be_nil+ end+ end++ describe 'unlinking' do+ it 'sets person_id to nil and keeps the row and its name' do+ link(person_id: contact.id)++ expect(link(unlink: true)).to be_success+ expect(participant.reload.person_id).to be_nil+ expect(participant.display_name).to eq('J. Weber (Hoster)')+ end++ it 'leaves the account of a member participant alone' do+ colleague = member(first_name: 'Carl')+ participant.update!(user: colleague)++ expect(link(unlink: true).code).to eq(:member_participant)+ expect(participant.reload.user_id).to eq(colleague.id)+ end+ end++ describe 'creating a person and linking it' do+ it 'creates the row with the given name and links it in one step' do+ result = nil+ expect { result = link(new_person: { name: 'J. Weber' }) }.to change(Person, :count).by(1)++ expect(result).to be_success+ created = Person.order(:created_at).last+ expect(created.name).to eq('J. Weber')+ expect(created.creator).to eq(writer)+ expect(participant.reload.person_id).to eq(created.id)+ end++ it 'creates nothing when the name is blank' do+ result = nil+ expect { result = link(new_person: { name: ' ' }) }.not_to change(Person, :count)++ expect(result).not_to be_success+ expect(result.code).to eq(:validation_failed)+ expect(participant.reload.person_id).to be_nil+ end++ it 'creates nothing when the link fails afterwards (one transaction)' do+ allow_any_instance_of(MeetingParticipant).to receive(:update!).and_raise(Actors::ActorError, 'link failed')++ result = nil+ expect { result = link(new_person: { name: 'J. Weber' }) }.not_to change(Person, :count)+ expect(result.errors).to eq(['link failed'])+ end++ it 'needs manage_people' do+ viewer = member(role: role_with('view_people'))++ result = nil+ expect { result = link(user: viewer, new_person: { name: 'J. Weber' }) }.not_to change(Person, :count)+ expect(result.code).to eq(:not_allowed)+ end++ it 'is allowed with manage_people' do+ manager = member(role: role_with('manage_people'))++ expect(link(user: manager, new_person: { name: 'J. Weber' })).to be_success+ end+ end++ describe 'what the writer cannot reach' do+ it 'refuses without a choice' do+ expect(link.code).to eq(:nothing_picked)+ end++ it 'does not find a person of another organisation' do+ foreign = ActsAsTenant.with_tenant(create(:organisation)) { create(:person, name: 'Jonas Weber') }++ expect(link(person_id: foreign.id).code).to eq(:not_found)+ expect(participant.reload.person_id).to be_nil+ end++ it 'does not find a person without view_people' do+ outsider = member++ expect(link(user: outsider, person_id: contact.id).code).to eq(:not_found)+ expect(participant.reload.person_id).to be_nil+ end++ it '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)++ 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(participant.reload.user_id).to be_nil+ end++ it 'does not find a member of another organisation' do+ stranger = member(org: create(:organisation))++ expect(link(member_id: stranger.id).code).to eq(:not_found)+ end++ it 'does not find a participant of another meeting' do+ other_meeting = create(:meeting, organisation: organisation, project: project)+ other = create(:meeting_participant, meeting: other_meeting, display_name: 'Jonas Weber')++ expect(link(participant_id: other.id, person_id: contact.id).code).to eq(:not_found)+ expect(other.reload.person_id).to be_nil+ end++ it 'treats a meeting moved out of the authorized project as gone' do+ target = create(:project, organisation: organisation)+ meeting.update_columns(project_id: target.id)++ result = link(person_id: contact.id)++ expect(result.code).to eq(:not_found)+ expect(participant.reload.person_id).to be_nil+ end++ it 'takes the meeting lock' do+ expect(meeting).to receive(:lock_in_project!).with(project.id).and_call_original++ link(person_id: contact.id)+ end+ end+enddiff --git a/spec/services/people/directory_spec.rb b/spec/services/people/directory_spec.rbindex 8b9f1f4..7e4efa0 100644--- a/spec/services/people/directory_spec.rb+++ b/spec/services/people/directory_spec.rb@@ -156,6 +156,48 @@ RSpec.describe People::Directory, :ci_guard doendend+ describe 'the link dialog (S2b)' do+ def directory(user = viewer, query: nil)+ described_class.new(viewer: user, organisation: organisation, query: query)+ end++ it 'finds a person row by id only when the viewer sees it, a member row as the member' do+ stranger_row = create(:person, organisation: organisation, user: stranger, name: 'Sven Fremd')+ colleague_row = create(:person, organisation: organisation, user: colleague, name: 'Carl Kollege')++ expect(directory.person_entry(contact.id).person).to eq(contact)+ expect(directory.person_entry(stranger_row.id)).to be_nil+ expect(directory(admin).person_entry(stranger_row.id)).to be_present+ expect(directory.person_entry(colleague_row.id)).to be_member+ expect(directory(colleague).person_entry(contact.id)).to be_nil+ end++ it 'lists candidates by search, without last contacts' do+ expect(names(directory(query: 'hosting').candidates)).to eq(['Doris Dienstleister'])+ expect(directory.candidates.map(&:last_contact)).to all(be_nil)+ expect(names(directory.candidates)).to eq(['Carl Kollege', 'Doris Dienstleister', 'Vera Viewer'])+ end++ it 'suggests the same full name first, then the same surname, only what the viewer sees' do+ same_surname = create(:person, organisation: organisation, name: 'Anton Dienstleister')+ same_name = create(:person, organisation: organisation, name: 'doris dienstleister')+ create(:person, organisation: organisation, user: stranger, name: 'Sven Dienstleister')++ suggested = directory.suggestions_for('Doris Dienstleister').map(&:person)++ expect(suggested.first(2)).to contain_exactly(contact, same_name)+ expect(suggested.last).to eq(same_surname)+ expect(suggested.size).to eq(3)+ end++ it 'reads the surname past initials and a note in brackets' do+ expect(described_class.surname('J. Weber (Hoster)')).to eq('weber')+ expect(described_class.surname('Jürgen Müller')).to eq('mueller')+ expect(described_class.surname('J.')).to be_nil+ expect(directory.suggestions_for(' ')).to eq([])+ end+ end+it 'returns nothing without the right' doexpect(entries(colleague)).to be_emptyenddiff --git a/spec/system/meeting_participant_link_spec.rb b/spec/system/meeting_participant_link_spec.rbnew file mode 100644index 0000000..964e6e6--- /dev/null+++ b/spec/system/meeting_participant_link_spec.rb@@ -0,0 +1,72 @@+# frozen_string_literal: true++require 'rails_helper'++# The dialog "Mit Person verknüpfen" beside the participant chips (S2b): only a+# browser shows that it opens in its frame, searches, links, closes on Escape+# and gives the focus back to the button that opened it.+RSpec.describe 'Linking a meeting participant to a person', type: :system do+ let(:organisation) { create(:organisation) }+ let(:user) { create(:user, first_name: 'Anna', last_name: 'Beispiel') }+ let(:project) { create(:project, organisation: organisation, name: 'Relaunch') }+ let(:meeting) { create(:meeting, organisation: organisation, project: project, title: 'Hosting-Abstimmung') }+ let(:participant) { create(:meeting_participant, meeting: meeting, display_name: 'J. Weber (Hoster)') }+ let(:pl) { 'views.organisations.meetings.participant_links' }++ before do+ Prosopite.pause+ ActsAsTenant.current_tenant = organisation+ role = create(:role, organisation: organisation, title: Role::ACCOUNT_ADMIN_TITLE)+ create(:membership, user: user, organisation: organisation, role: role, active: true)+ participant+ create(:person, organisation: organisation, name: 'Jonas Weber', function: 'Hosting')+ create(:person, organisation: organisation, name: 'Anton Anders')+ sign_in user+ end++ after do+ ActsAsTenant.current_tenant = nil+ Prosopite.resume+ end++ def trigger_id+ "meeting-participant-link-trigger-#{participant.id}"+ end++ def open_dialog+ find("##{trigger_id}").click+ expect(page).to have_css('[role="dialog"]', text: I18n.t("#{pl}.title"))+ end++ it 'searches, links, closes and gives the focus back' do+ visit organisation_project_meetings_path(organisation, project, meeting_id: meeting.id)+ open_dialog++ within('[role="dialog"]') do+ expect(page).to have_css('li', text: 'Jonas Weber')+ expect(page).to have_text(I18n.t("#{pl}.suggestion"))+ fill_in I18n.t("#{pl}.search_label"), with: 'anders'+ expect(page).to have_css('li', text: 'Anton Anders')+ expect(page).to have_no_css('li', text: 'Jonas Weber')+ fill_in I18n.t("#{pl}.search_label"), with: 'weber'+ find('label', text: 'Jonas Weber').click+ click_button I18n.t("#{pl}.submit")+ end++ expect(page).to have_no_css('[role="dialog"]')+ expect(page).to have_link(I18n.t("#{pl}.open_person", name: 'J. Weber (Hoster)'))+ expect(participant.reload.person.name).to eq('Jonas Weber')+ expect(page.evaluate_script('document.activeElement.id')).to eq(trigger_id)+ end++ it 'closes on Escape without linking' do+ visit organisation_project_meetings_path(organisation, project, meeting_id: meeting.id)+ open_dialog++ find('[role="dialog"] input[type="search"]').send_keys(:escape)++ expect(page).to have_no_css('[role="dialog"]')+ expect(page).to have_text('Hosting-Abstimmung')+ expect(participant.reload.person_id).to be_nil+ end+end