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
feat(people): show the last contact and the meetings of a person
Guido Boyke7064378de740
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.ymlindex ff78fcf..4b2e7d9 100644--- a/.github/workflows/guards.yml+++ b/.github/workflows/guards.yml@@ -319,6 +319,8 @@ jobs:spec/requests/organisations/meetings_overview_create_spec.rbspec/requests/organisations/people_spec.rbspec/services/people/directory_spec.rb+ spec/services/people/contacts_spec.rb+ spec/requests/organisations/people_last_contact_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/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.cssindex f1b0e1d..07f9053 100644--- a/app/assets/stylesheets/application.tailwind.css+++ b/app/assets/stylesheets/application.tailwind.css@@ -413,8 +413,29 @@.people-row__line { @apply flex min-w-0 items-baseline gap-2; }.people-row__name { @apply truncate text-sm font-medium text-heading; }.people-row__sub { @apply truncate text-xs text-muted; }- .people-row__chevron { @apply hidden text-xs text-cream-400; }- .people-mobile-grid .people-row__chevron { @apply inline; }+ /* S2a: the column heads (NAME, ZULETZT) sort the list; the ink line moves+ from the list to the heads. */+ .people-columns { @apply mx-6 flex items-center gap-3 border-b border-ink pb-1.5; }+ .people-columns + .people-list { border-top-width: 0; }+ .people-columns__head--name { @apply min-w-0 flex-1; padding-inline-start: 42px; }+ .people-columns__head--last { @apply w-[120px] flex-none text-end; }+ .people-columns__link { @apply inline-flex items-center gap-1 font-mono text-[10px] uppercase tracking-[0.08em] text-muted no-underline hover:text-heading; }+ .people-columns__link--active { @apply text-heading; }+ .people-row__last { @apply w-[120px] flex-none whitespace-nowrap text-end text-xs text-cream-700; }+ .people-row__last--none { @apply text-cream-500; }+ .people-last { @apply flex items-baseline gap-2.5 rounded-lg bg-cream-50 px-3 py-2.5 text-[13px]; }+ .people-last i, .people-last__label { @apply flex-none text-muted; }+ .people-last__text { @apply min-w-0 flex-1 text-heading; }+ .people-last__text--none { @apply text-muted; }+ .people-meetings { @apply flex flex-col; }+ .people-meetings__title { @apply pb-1.5 text-sm font-semibold text-heading; }+ .people-meetings__empty { @apply py-1.5 text-[13px] text-muted; }+ .people-meetings__row { @apply -mx-2 flex items-baseline gap-3 rounded-md border-t border-cream-200 px-2 py-2 text-heading no-underline hover:bg-cream-100; }+ .people-meetings__date { @apply w-[88px] flex-none font-mono text-xs text-muted; }+ .people-meetings__text { @apply flex min-w-0 flex-1 flex-col gap-px; }+ .people-meetings__name { @apply truncate text-sm; }+ .people-meetings__project { @apply text-xs text-muted; }+ .people-meetings .people-text-action { @apply mt-1 self-start; }.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. */diff --git a/app/controllers/organisations/people_controller.rb b/app/controllers/organisations/people_controller.rbindex a59c799..4e1fbb8 100644--- a/app/controllers/organisations/people_controller.rb+++ b/app/controllers/organisations/people_controller.rb@@ -29,7 +29,9 @@ module OrganisationsLIST_FRAME_ID = 'people_results'NEW_STATE = 'person'# The list state the lane's forms and links carry, so a save keeps it.- LIST_PARAMS = %w[q kind].freeze+ LIST_PARAMS = %w[q kind sort].freeze+ # The meetings the lane shows before "Alle N anzeigen".+ MEETINGS_SHOWN = 3rescue_from Pundit::NotAuthorizedError, with: :render_forbidden@@ -150,7 +152,7 @@ module Organisationsdef directory@directory ||= People::Directory.new(viewer: current_user, organisation: current_organisation,- query: params[:q], kind: params[:kind])+ query: params[:q], kind: params[:kind], sort: params[:sort])enddef load_listdiff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rbindex 5307429..86a76b1 100644--- a/app/helpers/people_helper.rb+++ b/app/helpers/people_helper.rb@@ -187,4 +187,41 @@ module PeopleHelperlabel = t('views.organisations.people.form.former_member_option', name: person.name_in_database)[[label, stored_id]] + optionsend++ # How long ago a last contact was, in calendar days (S2a): heute, gestern,+ # vor n Tagen, Wochen, Monaten, Jahren. Not time_ago_in_words: that counts+ # hours ("etwa 1 Stunde") and calls late yesterday evening "today".+ def last_contact_age(at)+ days = (Time.zone.today - at.in_time_zone.to_date).to_i+ scope = 'views.organisations.people.age'+ return t("#{scope}.today") if days <= 0+ return t("#{scope}.yesterday") if days == 1+ return t("#{scope}.days", count: days) if days < 7+ return t("#{scope}.weeks", count: days / 7) if days < 30+ return t("#{scope}.months", count: days / 30) if days < 365++ t("#{scope}.years", count: days / 365)+ end++ # The words of a last contact (People::Contacts::LastContact): the last+ # meeting with its date, or the ticket work with its age.+ def last_contact_text(last)+ scope = 'views.organisations.people.last_contact'+ if last.kind == :meeting+ t("#{scope}.meeting", title: last.meeting_title, date: l(last.at.to_date, format: :short))+ else+ t("#{scope}.ticket.#{last.action}", number: last.ticket_number, age: last_contact_age(last.at))+ end+ end++ # The last contact and the readable meetings of one person or member in the+ # lane. A member (the account, active) counts their ticket work too; a row+ # of a former member only its meetings.+ def person_contacts(person: nil, member: nil)+ contacts = People::Contacts.new(viewer: current_user, organisation: current_organisation)+ subject = People::Contacts::Subject.new(person_id: person&.id, user_id: member&.id || person&.user_id,+ member: member.present?)+ meetings = contacts.meetings_for(person: person, user: member).includes(:project)+ { last: contacts.last_contacts([subject]).first, meetings: meetings }+ endenddiff --git a/app/models/CLAUDE.md b/app/models/CLAUDE.mdindex 65bcb35..5113639 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@@ -59,6 +59,10 @@ Verzeichnis-Layout nicht ablesbar — diese Karte gruppiert sie:UND `admin/membership`: wer eine Mitgliedschaft entfernt, behält die Zeile und verliert nurdie Verknüpfung. Darum läuft `erase_personal_data!` in beiden Löschwegen VOR`memberships.destroy_all`; andersherum findet `erase_person_links!` nichts mehr.+ Seit S2a (27.10.2026) zeigt `meeting_participant.person_id` (FK, nullt beim Löschen der+ Person) auf eine Zeile; `belongs_to :person` steht VOR `acts_as_tenant`, eine Validierung+ hä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`).* **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 cc5e0e7..00e0547 100644--- a/app/services/CLAUDE.md+++ b/app/services/CLAUDE.md@@ -158,6 +158,12 @@ Verzeichnis-Übersicht (Auswahl):über `MembershipPolicy::Scope` (dieselbe Reichweite wie die Mitgliederseite), dazu dieZeilen ohne aktives Mitglied als Kontakte; Suche in Ruby über `PersonName.normalize`.Rechte nur über `PersonPolicy`, keine eigene Regel daneben.+ `contacts.rb` (S2a, 27.10.2026): Meetings einer Person (`person_id` ODER `user_id` des+ Mitglieds) und „Letzter Kontakt“ einer ganzen Liste in fester Abfragezahl. Lesbar nur über+ `MeetingPolicy::Scope`, `TicketPolicy::Scope`, `Post.readable_by` und `Activity.feed`; bei+ aktiven Mitgliedern zählt eigene Ticket-Arbeit (`TICKET_ACTIONS`: angelegt, geändert,+ kommentiert), bei Kontakten nur Meetings. `Directory#entries` hängt den Kontakt an und+ sortiert nach `name` oder `last`.* `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/people/directory.rb b/app/services/people/directory.rbindex 3fb7a1e..4be504d 100644--- a/app/services/people/directory.rb+++ b/app/services/people/directory.rb@@ -20,8 +20,13 @@ module People# organisation. Pagination is a follow-up once an organisation passes that.class DirectoryKINDS = %w[all members contacts].freeze+ # The orders of the list (E5): by name (the default) or by last contact,+ # newest first, people without any contact last.+ SORTS = %w[name last].freeze- Entry = Struct.new(:kind, :user, :person, :sort_name, keyword_init: true) do+ # last_contact: People::Contacts::LastContact or nil, set for the entries+ # the page shows (#entries).+ Entry = Struct.new(:kind, :user, :person, :sort_name, :last_contact, keyword_init: true) dodef member?kind == :memberend@@ -33,15 +38,28 @@ module Peopleendend- def initialize(viewer:, organisation:, query: nil, kind: 'all')+ def initialize(viewer:, organisation:, query: nil, kind: 'all', sort: 'name')@viewer = viewer@organisation = organisation@query = PersonName.normalize(query)@kind = KINDS.include?(kind.to_s) ? kind.to_s : 'all'+ @sort = SORTS.include?(sort.to_s) ? sort.to_s : 'name'end+ # The entries the page shows, each with its last contact (People::Contacts,+ # only what the viewer may read), in the order asked for.def entries- everyone.select { |entry| kind_matches?(entry) && (@query.blank? || matches?(entry)) }+ list = everyone.select { |entry| kind_matches?(entry) && (@query.blank? || matches?(entry)) }+ attach_last_contacts(list)+ @sort == 'last' ? by_last_contact(list) : list+ end++ # The one subject People::Contacts asks about for an entry: a member counts+ # their own ticket work, a contact (also a former member) only meetings.+ def self.contact_subject(entry)+ People::Contacts::Subject.new(person_id: entry.person&.id,+ user_id: entry.member? ? entry.user.id : entry.person&.user_id,+ member: entry.member?)end# How many people the page holds, before search and filter: the head line@@ -71,6 +89,24 @@ module Peopleprivate+ def attach_last_contacts(list)+ return if list.empty?++ contacts = People::Contacts.new(viewer: @viewer, organisation: @organisation)+ ActsAsTenant.with_tenant(@organisation) do+ contacts.last_contacts(list.map { |entry| self.class.contact_subject(entry) })+ .each_with_index { |last, index| list[index].last_contact = last }+ end+ end++ # Newest first, without a contact last; the name order breaks ties.+ def by_last_contact(list)+ list.each_with_index.sort_by do |entry, index|+ at = entry.last_contact&.at+ [at ? 0 : 1, at ? -at.to_f : 0, index]+ end.map(&:first)+ end+# Everything the viewer may see, sorted, read once per directory.def everyone@everyone ||= if PersonPolicy.view_allowed?(@viewer, @organisation)diff --git a/app/views/organisations/people/_contact_summary.html.erb b/app/views/organisations/people/_contact_summary.html.erbnew file mode 100644index 0000000..8b4d9e0--- /dev/null+++ b/app/views/organisations/people/_contact_summary.html.erb@@ -0,0 +1,43 @@+<%# locals: (person: nil, member: nil, more_url:) %>+<%# Variant A of S2a: "Letzter Kontakt" right under the identity, then the+ newest meetings (three, then "Alle N anzeigen", which reloads the lane+ with ?meetings=all). Only what the viewer may read (People::Contacts); a+ row opens the meeting where "Alle Meetings" opens it. No badge per+ meeting: attendance is the only kind there is (E2). %>+<% summary = person_contacts(person: person, member: member) %>+<% last = summary[:last] %>+<% all_shown = params[:meetings] == 'all' %>+<% total = summary[:meetings].count %>+<% meetings = all_shown ? summary[:meetings].to_a : summary[:meetings].limit(Organisations::PeopleController::MEETINGS_SHOWN).to_a %>+<p class="people-last">+ <i class="bi bi-clock-history" aria-hidden="true"></i>+ <span class="people-last__label"><%= t('views.organisations.people.show.last_contact') %></span>+ <span class="people-last__text <%= 'people-last__text--none' unless last %>">+ <%= last ? last_contact_text(last) : t('views.organisations.people.show.no_meeting') %>+ </span>+</p>++<section class="people-meetings" aria-labelledby="people-meetings-title">+ <h3 id="people-meetings-title" class="people-meetings__title"><%= t('views.organisations.people.show.meetings') %></h3>+ <% if meetings.empty? %>+ <p class="people-meetings__empty"><%= t('views.organisations.people.show.no_meeting') %></p>+ <% else %>+ <ul class="people-meetings__list">+ <% meetings.each do |meeting| %>+ <li>+ <%= link_to organisation_meetings_path(@current_organisation, meeting_id: meeting.id), class: 'people-meetings__row',+ data: { turbo_frame: '_top' } do %>+ <time class="people-meetings__date" datetime="<%= meeting.occurred_at.to_date.iso8601 %>"><%= l(meeting.occurred_at.to_date, format: :default) %></time>+ <span class="people-meetings__text">+ <span class="people-meetings__name"><%= meeting.title %></span>+ <span class="people-meetings__project"><%= meeting.project.name %></span>+ </span>+ <% end %>+ </li>+ <% end %>+ </ul>+ <% if !all_shown && total > meetings.size %>+ <%= link_to t('views.organisations.people.show.all_meetings', count: total), more_url, class: 'people-text-action' %>+ <% end %>+ <% end %>+</section>diff --git a/app/views/organisations/people/_detail.html.erb b/app/views/organisations/people/_detail.html.erbindex b44f25b..df2f0ba 100644--- a/app/views/organisations/people/_detail.html.erb+++ b/app/views/organisations/people/_detail.html.erb@@ -14,6 +14,8 @@<% status_icon, status = person_link_state(person, member) %><%= render 'organisations/people/identity', name: name, user: member, status_icon: status_icon, status: status %>+ <%= render 'organisations/people/contact_summary', person: person, member: member,+ more_url: organisation_person_path(@current_organisation, person, list_state.merge('meetings' => 'all')) %><% duplicates = People::Directory.new(viewer: current_user, organisation: @current_organisation).duplicates_of(person) %><% if duplicates.any? %>@@ -54,6 +56,9 @@<p class="people-footer__created"><% if person.creator %><%= t('views.organisations.people.show.created_by', name: person_actor_name(person.creator), date: l(person.created_at.to_date, format: :default)) %>+ <% elsif member %>+ <%# A member row nobody created by hand ("Angaben ergänzen" by a deleted account, a later import). %>+ <%= t('views.organisations.people.show.from_account', date: l(person.created_at.to_date, format: :default)) %><% else %><%= t('views.organisations.people.show.created_at', date: l(person.created_at.to_date, format: :default)) %><% end %>diff --git a/app/views/organisations/people/_list_head.html.erb b/app/views/organisations/people/_list_head.html.erbindex 501de97..d7906c8 100644--- a/app/views/organisations/people/_list_head.html.erb+++ b/app/views/organisations/people/_list_head.html.erb@@ -45,6 +45,7 @@<div class="people-tools"><%= form_with url: organisation_people_path(@current_organisation), method: :get, class: 'people-search', data: { turbo_frame: '_top' } do %><%= hidden_field_tag :kind, list_state['kind'] if list_state['kind'] %>+ <%= hidden_field_tag :sort, list_state['sort'] if list_state['sort'] %><label for="people-search" class="people-search__field"><i class="bi bi-search" aria-hidden="true"></i><span class="sr-only"><%= t('views.organisations.people.index.search_label') %></span>diff --git a/app/views/organisations/people/_member.html.erb b/app/views/organisations/people/_member.html.erbindex 13839b4..657c1ec 100644--- a/app/views/organisations/people/_member.html.erb+++ b/app/views/organisations/people/_member.html.erb@@ -9,6 +9,8 @@edit_link: add_link %><%= render 'organisations/people/identity', name: viewer_display_name(member), user: member, status_icon: 'bi-person-check',status: t('views.organisations.people.show.linked_member', name: viewer_display_name(member)) %>+ <%= render 'organisations/people/contact_summary', member: member,+ more_url: member_organisation_people_path(@current_organisation, member.id, list_state.merge('meetings' => 'all')) %><%= render 'organisations/people/bare_hint', member: member, link: add_link %><%= render 'organisations/people/fields', fields: person_fields(nil, member) %><% membership = Membership.find_by(organisation: @current_organisation, user: member) %>diff --git a/app/views/organisations/people/_results.html.erb b/app/views/organisations/people/_results.html.erbindex ab5fed6..fff9d16 100644--- a/app/views/organisations/people/_results.html.erb+++ b/app/views/organisations/people/_results.html.erb@@ -1,9 +1,27 @@<%# locals: (entries:, counts:, selected: nil, member: nil) %>-<%# The rows of the directory (People::Directory), one column: name with a- "Mitglied" badge, function and company below. Every row opens the lane:- a person row through person_id, a member without a row through member_id. %>+<%# The rows of the directory (People::Directory): name with a "Mitglied"+ badge, function and company below, the age of the last contact on the+ right. Every row opens the lane: a person row through person_id, a member+ without a row through member_id. The two column heads sort the list+ (?sort=last, E5), a full visit that keeps search, filter and the open+ person. %>+<% open_lane = params.permit(:person_id, :member_id).to_h %><turbo-frame id="<%= Organisations::PeopleController::LIST_FRAME_ID %>"><% if entries.any? %>+ <% sort = list_state['sort'] == 'last' ? 'last' : 'name' %>+ <div class="people-columns" role="row">+ <%# Class names written out: Tailwind keeps only component classes it finds whole in a template. %>+ <% { 'name' => ['ascending', 'people-columns__head--name'], 'last' => ['descending', 'people-columns__head--last'] }.each do |key, (direction, head_class)| %>+ <% active = sort == key %>+ <%= tag.span role: 'columnheader', class: "people-columns__head #{head_class}", 'aria-sort': (active ? direction : 'none') do %>+ <%= link_to organisation_people_path(@current_organisation, list_state.except('sort').merge(key == 'last' ? { 'sort' => 'last' } : {}).merge(open_lane)),+ class: "people-columns__link #{'people-columns__link--active' if active}", data: { turbo_frame: '_top' } do %>+ <%= t("views.organisations.people.index.columns.#{key}") %>+ <% if active %><i class="bi bi-arrow-down" aria-hidden="true"></i><% end %>+ <% end %>+ <% end %>+ <% end %>+ </div><ul class="people-list"><% entries.each do |entry| %><%= render 'organisations/people/row', entry: entry, selected: selected, member: member %>diff --git a/app/views/organisations/people/_row.html.erb b/app/views/organisations/people/_row.html.erbindex 8b9a684..ce45b97 100644--- a/app/views/organisations/people/_row.html.erb+++ b/app/views/organisations/people/_row.html.erb@@ -31,5 +31,8 @@<span class="people-row__sub"><%= sub %></span><% end %></span>- <i class="bi bi-chevron-right people-row__chevron" aria-hidden="true"></i>+ <% last = entry.last_contact %>+ <%= tag.span(last ? last_contact_age(last.at) : t('views.organisations.people.index.never'),+ class: "people-row__last #{'people-row__last--none' unless last}",+ title: last ? last_contact_text(last) : t('views.organisations.people.show.no_meeting')) %><% end %>diff --git a/config/locales/views/personen.de.yml b/config/locales/views/personen.de.ymlindex 83b726a..7d09e73 100644--- a/config/locales/views/personen.de.yml+++ b/config/locales/views/personen.de.yml@@ -47,7 +47,38 @@ de:no_hits_text: "Gesucht wird in Name, Funktion, Abteilung, Firma und E-Mail."clear_search: "Suche zurücksetzen"back_to_list: "Personen"+ never: "noch nie"+ columns:+ name: "Name"+ last: "Zuletzt"+ age:+ today: "heute"+ yesterday: "gestern"+ days:+ one: "vor %{count} Tag"+ other: "vor %{count} Tagen"+ weeks:+ one: "vor %{count} Woche"+ other: "vor %{count} Wochen"+ months:+ one: "vor %{count} Monat"+ other: "vor %{count} Monaten"+ years:+ one: "vor %{count} Jahr"+ other: "vor %{count} Jahren"+ last_contact:+ meeting: "Letztes Meeting: %{title}, %{date}"+ ticket:+ created: "Hat Ticket #%{number} angelegt, %{age}"+ changed: "Hat Ticket #%{number} geändert, %{age}"+ commented: "Hat Ticket #%{number} kommentiert, %{age}"show:+ last_contact: "Letzter Kontakt"+ no_meeting: "Noch kein Meeting."+ meetings: "Meetings"+ all_meetings:+ one: "Alle %{count} anzeigen"+ other: "Alle %{count} anzeigen"kind:member: "Mitglied"contact: "Kontakt"diff --git a/config/locales/views/personen.en.yml b/config/locales/views/personen.en.ymlindex df5e74f..13b70aa 100644--- a/config/locales/views/personen.en.yml+++ b/config/locales/views/personen.en.yml@@ -47,7 +47,38 @@ en:no_hits_text: "The search looks at name, function, department, company and email."clear_search: "Clear search"back_to_list: "People"+ never: "never"+ columns:+ name: "Name"+ last: "Last"+ age:+ today: "today"+ yesterday: "yesterday"+ days:+ one: "%{count} day ago"+ other: "%{count} days ago"+ weeks:+ one: "%{count} week ago"+ other: "%{count} weeks ago"+ months:+ one: "%{count} month ago"+ other: "%{count} months ago"+ years:+ one: "%{count} year ago"+ other: "%{count} years ago"+ last_contact:+ meeting: "Last meeting: %{title}, %{date}"+ ticket:+ created: "Created ticket #%{number}, %{age}"+ changed: "Changed ticket #%{number}, %{age}"+ commented: "Commented on ticket #%{number}, %{age}"show:+ last_contact: "Last contact"+ no_meeting: "No meeting yet."+ meetings: "Meetings"+ all_meetings:+ one: "Show all %{count}"+ other: "Show all %{count}"kind:member: "Member"contact: "Contact"diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rbnew file mode 100644index 0000000..ac9ca8e--- /dev/null+++ b/spec/helpers/people_helper_spec.rb@@ -0,0 +1,39 @@+# frozen_string_literal: true++require 'rails_helper'++# The age of a last contact in the list (S2a): calendar days, not hours, in+# both languages, at the edges of every step.+RSpec.describe PeopleHelper, type: :helper do+ include ActiveSupport::Testing::TimeHelpers++ around { |example| travel_to(Time.zone.local(2026, 10, 26, 9, 0)) { example.run } }++ {+ 0 => %w[heute today],+ 1 => %w[gestern yesterday],+ 2 => ['vor 2 Tagen', '2 days ago'],+ 6 => ['vor 6 Tagen', '6 days ago'],+ 7 => ['vor 1 Woche', '1 week ago'],+ 13 => ['vor 1 Woche', '1 week ago'],+ 14 => ['vor 2 Wochen', '2 weeks ago'],+ 29 => ['vor 4 Wochen', '4 weeks ago'],+ 30 => ['vor 1 Monat', '1 month ago'],+ 59 => ['vor 1 Monat', '1 month ago'],+ 60 => ['vor 2 Monaten', '2 months ago'],+ 364 => ['vor 12 Monaten', '12 months ago'],+ 365 => ['vor 1 Jahr', '1 year ago'],+ 800 => ['vor 2 Jahren', '2 years ago']+ }.each do |days, (german, english)|+ it "says #{german} / #{english} for #{days} days" do+ at = days.days.ago.change(hour: 23)++ expect(I18n.with_locale(:de) { helper.last_contact_age(at) }).to eq(german)+ expect(I18n.with_locale(:en) { helper.last_contact_age(at) }).to eq(english)+ end+ end++ it 'counts late yesterday evening as yesterday, not as hours ago' do+ expect(I18n.with_locale(:de) { helper.last_contact_age(Time.zone.local(2026, 10, 25, 23, 50)) }).to eq('gestern')+ end+enddiff --git a/spec/requests/organisations/people_last_contact_spec.rb b/spec/requests/organisations/people_last_contact_spec.rbnew file mode 100644index 0000000..14591cb--- /dev/null+++ b/spec/requests/organisations/people_last_contact_spec.rb@@ -0,0 +1,228 @@+# frozen_string_literal: true++require 'rails_helper'++# The people page, S2a: the column "Zuletzt" with its sort, and in the lane+# "Letzter Kontakt" and the meetings of a person. Only what the viewer may+# read counts; every negative claim below stands next to proof that the page+# itself was rendered.+RSpec.describe 'Organisations::People last contact', :ci_guard, type: :request do+ include ActiveSupport::Testing::TimeHelpers++ let(:organisation) { create(:organisation) }++ before { ActsAsTenant.current_tenant = organisation }+ after { ActsAsTenant.current_tenant = nil }++ def member_with(role, first_name:)+ user = create(:user, first_name: first_name, last_name: 'Beispiel')+ create(:membership, user: user, organisation: organisation, role: role, active: true)+ User.find(user.id)+ end++ def viewer_role+ role = create(:role, organisation: organisation)+ create(:permission, role: role, category: 'people', action: 'view_people', allowed: true)+ role+ end++ let(:readable) { create(:project, organisation: organisation, name: 'Relaunch') }+ let(:hidden) { create(:project, organisation: organisation, name: 'Geheimprojekt') }+ let(:viewer) { member_with(viewer_role, first_name: 'Vera') }+ let(:admin) { member_with(create(:role, organisation: organisation, title: Role::ACCOUNT_ADMIN_TITLE), first_name: 'Anna') }+ let(:colleague) { member_with(create(:role, organisation: organisation), first_name: 'Carl') }+ let!(:contact) { create(:person, organisation: organisation, name: 'Doris Dienstleister') }++ let(:frame_headers) { { 'Turbo-Frame' => Organisations::PeopleController::DETAIL_FRAME_ID } }++ before do+ create(:project_permission, user: viewer, project: readable, tickets_access: :read_only, meetings_access: :read_only)+ create(:project_permission, user: colleague, project: readable, tickets_access: :read_only, meetings_access: :read_only)+ end++ # Test data only: Prosopite would read a loop of these as an N+1.+ def meeting(project, at:, title:, person: nil, user: nil)+ Prosopite.pause do+ record = create(:meeting, organisation: organisation, project: project, occurred_at: at, title: title)+ create(:meeting_participant, meeting: record, person: person, user: user, display_name: 'Gast')+ record+ end+ end++ def row_of(body, name)+ body[%r{<li[^>]*people-row[\s\S]*?#{name}[\s\S]*?</li>}]+ end++ describe 'the list' do+ it 'shows the column heads, sorted by name by default with the arrow on NAME' do+ sign_in viewer+ get organisation_people_path(organisation)++ head = response.body[%r{<div class="people-columns"[\s\S]*?</div>}]+ expect(head).to include(I18n.t('views.organisations.people.index.columns.name'),+ I18n.t('views.organisations.people.index.columns.last'))+ active = head[%r{<span[^>]*aria-sort="ascending"[^>]*>[\s\S]*?</span>}]+ expect(active).to include(I18n.t('views.organisations.people.index.columns.name'), 'bi-arrow-down')+ expect(response.body.index('Carl Beispiel')).to be < response.body.index('Doris Dienstleister')+ end++ it 'shows the age of the last contact and "noch nie" without one' do+ meeting(readable, at: 1.day.ago, title: 'Status', person: contact)+ sign_in viewer++ get organisation_people_path(organisation)++ expect(row_of(response.body, 'Doris Dienstleister')).to include('gestern', 'Letztes Meeting: Status')+ expect(row_of(response.body, 'Carl Beispiel')).to include('noch nie')+ end++ it 'sorts by ?sort=last, newest first, and keeps the sort in search, filter and selection links' do+ meeting(readable, at: 1.day.ago, title: 'Status', person: contact)+ sign_in viewer++ get organisation_people_path(organisation, sort: 'last')++ expect(response.body.index('Doris Dienstleister')).to be < response.body.index('Carl Beispiel')+ expect(response.body).to match(/<input type="hidden" name="sort"[^>]*value="last"/)+ expect(response.body).to include(CGI.escapeHTML(organisation_people_path(organisation, kind: 'contacts', sort: 'last')))+ expect(response.body).to include(CGI.escapeHTML('"sort"'))+ end++ it 'is not moved by, and does not show, a meeting the viewer may not read' do+ meeting(readable, at: 5.days.ago, title: 'Status', person: contact)+ meeting(hidden, at: 1.hour.ago, title: 'Geheimrunde', user: colleague)+ sign_in viewer++ get organisation_people_path(organisation, sort: 'last')++ expect(response).to have_http_status(:ok)+ expect(response.body).to include('Doris Dienstleister')+ expect(response.body.index('Doris Dienstleister')).to be < response.body.index('Carl Beispiel')+ expect(response.body).not_to include('Geheimrunde')+ end+ end++ describe 'the lane' do+ it 'shows the last contact and the three newest meetings of a contact, then "Alle N anzeigen"' do+ meetings = Array.new(4) { |index| meeting(readable, at: (index + 1).days.ago, title: "Runde #{index}", person: contact) }+ sign_in viewer++ get organisation_person_path(organisation, contact), headers: frame_headers++ expect(response.body).to include(I18n.t('views.organisations.people.show.last_contact'), 'Letztes Meeting: Runde 0')+ expect(response.body).to include('Runde 0', 'Runde 1', 'Runde 2', 'Relaunch')+ expect(response.body).not_to include('Runde 3')+ expect(response.body).to include(I18n.t('views.organisations.people.show.all_meetings', count: 4))+ expect(response.body).to include(organisation_meetings_path(organisation, meeting_id: meetings.first.id))+ end++ it 'shows every meeting after "Alle N anzeigen"' do+ Array.new(4) { |index| meeting(readable, at: (index + 1).days.ago, title: "Runde #{index}", person: contact) }+ sign_in viewer++ get organisation_person_path(organisation, contact, meetings: 'all'), headers: frame_headers++ expect(response.body).to include('Runde 3')+ expect(response.body).not_to include(I18n.t('views.organisations.people.show.all_meetings', count: 4))+ end++ it 'leaves out a meeting the viewer may not read, also from the count, and an admin sees it' do+ Array.new(3) { |index| meeting(readable, at: (index + 2).days.ago, title: "Runde #{index}", person: contact) }+ meeting(hidden, at: 1.day.ago, title: 'Geheimrunde', person: contact)+ sign_in viewer++ get organisation_person_path(organisation, contact), headers: frame_headers++ expect(response.body).to include('Runde 0')+ expect(response.body).not_to include('Geheimrunde')+ expect(response.body).not_to include(I18n.t('views.organisations.people.show.all_meetings', count: 4))+ expect(response.body).to include('Letztes Meeting: Runde 0')+ end++ it 'says so when there is no meeting' do+ sign_in viewer++ get organisation_person_path(organisation, contact), headers: frame_headers++ expect(response.body).to include(I18n.t('views.organisations.people.show.no_meeting'))+ end++ describe 'a member (E3)' do+ let(:ticket) { create(:ticket, organisation: organisation, project: readable) }++ it 'shows their newer ticket work as the last contact, in the lane of a member without a row' do+ meeting(readable, at: 4.days.ago, title: 'Planung', user: colleague)+ post = create(:post, ticket: ticket, user: colleague, organisation: organisation)+ Activity.create!(actor: colleague, trackable: ticket, organisation: organisation, action: 'post_added',+ secondary: post, parameters: { 'skip_notifications' => true }, created_at: 1.day.ago)+ sign_in viewer++ get member_organisation_people_path(organisation, colleague.id), headers: frame_headers++ expect(response.body).to include("Hat Ticket ##{ticket.number} kommentiert, gestern", 'Planung')+ end++ it 'does not count a comment the viewer may not read' do+ meeting(readable, at: 4.days.ago, title: 'Planung', user: colleague)+ post = create(:post, ticket: ticket, user: colleague, organisation: organisation, is_private: true,+ visible_to_user: admin)+ Activity.create!(actor: colleague, trackable: ticket, organisation: organisation, action: 'post_added',+ secondary: post, parameters: { 'skip_notifications' => true }, created_at: 1.day.ago)+ sign_in viewer++ get member_organisation_people_path(organisation, colleague.id), headers: frame_headers++ expect(response.body).to include('Letztes Meeting: Planung')+ expect(response.body).not_to include('kommentiert')+ end++ it 'shows the meetings of a member with a row through the account' do+ row = create(:person, organisation: organisation, user: colleague)+ meeting(readable, at: 2.days.ago, title: 'Planung', user: colleague)+ sign_in viewer++ get organisation_person_path(organisation, row), headers: frame_headers++ expect(response.body).to include('Planung', 'Letztes Meeting: Planung')+ end+ end++ it 'reads "Aus dem Konto übernommen am" for a member row without a creator' do+ row = create(:person, organisation: organisation, user: colleague, creator: nil)+ sign_in viewer++ get organisation_person_path(organisation, row), headers: frame_headers++ expect(response.body).to include(I18n.t('views.organisations.people.show.from_account', date: I18n.l(row.created_at.to_date, format: :default)))+ end+ end++ it 'shows the last contact and the meetings on a phone' do+ meeting(readable, at: 1.day.ago, title: 'Status', person: contact)+ sign_in viewer++ get organisation_people_path(organisation, person_id: contact.id, viewport: 'mobile')++ expect(response.body).to include('people-mobile-grid', I18n.t('views.organisations.people.show.last_contact'), 'Status')+ end++ it 'asks the database as often for a list of two people as for a list of eight' do+ Prosopite.pause+ sign_in admin+ count = lambda do+ queries = 0+ counter = ->(*, payload) { queries += 1 unless payload[:name] == 'SCHEMA' || payload[:cached] }+ ActiveSupport::Notifications.subscribed(counter, 'sql.active_record') { get organisation_people_path(organisation) }+ queries+ end++ count.call+ small = count.call+ 6.times { |index| meeting(readable, at: index.days.ago, title: "M#{index}", person: create(:person, organisation: organisation, name: "Kontakt #{index}")) }+ 3.times { |index| member_with(create(:role, organisation: organisation), first_name: "Neu#{index}") }++ expect(count.call).to eq(small)+ ensure+ Prosopite.resume+ end+enddiff --git a/spec/services/people/directory_spec.rb b/spec/services/people/directory_spec.rbindex e60d667..8b9f1f4 100644--- a/spec/services/people/directory_spec.rb+++ b/spec/services/people/directory_spec.rb@@ -110,6 +110,52 @@ RSpec.describe People::Directory, :ci_guard doexpect(duplicates.map(&:person)).not_to include(old_namesake)end+ # S2a: the last contact of each entry and the sort "Zuletzt" (E5).+ describe 'last contact and sort' do+ let(:hidden_project) { create(:project, organisation: organisation) }++ before do+ ProjectPermission.find_by(user: viewer, project: project).update!(meetings_access: :read_only)+ end++ def meeting(project_for, at:, person: nil, user: nil)+ record = create(:meeting, organisation: organisation, project: project_for, occurred_at: at)+ create(:meeting_participant, meeting: record, person: person, user: user, display_name: 'Gast')+ end++ it 'gives every entry its last readable contact' do+ meeting(project, at: 3.days.ago, person: contact)+ meeting(hidden_project, at: 1.day.ago, user: colleague)++ list = entries.index_by { |entry| entry.person&.name || entry.user.first_name }++ expect(list['Doris Dienstleister'].last_contact.kind).to eq(:meeting)+ expect(list['Carl'].last_contact).to be_nil+ end++ it 'keeps sorting by name unless asked' do+ meeting(project, at: 1.day.ago, user: viewer)++ expect(names(entries)).to eq(['Carl Kollege', 'Doris Dienstleister', 'Vera Viewer'])+ expect(names(entries(sort: 'nonsense'))).to eq(['Carl Kollege', 'Doris Dienstleister', 'Vera Viewer'])+ end++ it 'sorts by last contact, newest first, people without any contact last' do+ meeting(project, at: 5.days.ago, person: contact)+ meeting(project, at: 1.day.ago, user: viewer)++ expect(names(entries(sort: 'last'))).to eq(['Vera Viewer', 'Doris Dienstleister', 'Carl Kollege'])+ end++ it 'is not moved by a meeting the viewer may not read' do+ meeting(project, at: 5.days.ago, person: contact)+ meeting(hidden_project, at: 1.hour.ago, user: colleague)++ expect(names(entries(sort: 'last')).first).to eq('Doris Dienstleister')+ expect(names(entries(admin, sort: 'last')).first).to eq('Carl Kollege')+ end+ end+it 'returns nothing without the right' doexpect(entries(colleague)).to be_emptyend