Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Add a person citation type so answers about people stay with the asker

Guido Boyke5ce2ba5218ce
diff --git a/app/components/neo/chat/citation_list_component.rb b/app/components/neo/chat/citation_list_component.rb
index 394c223..27d6ea9 100644
--- a/app/components/neo/chat/citation_list_component.rb
+++ b/app/components/neo/chat/citation_list_component.rb
@@ -8,8 +8,9 @@ module Neo
# Citation shapes — ONE source of truth: Lalabase::Citations. Source data comes from
# PG JSONB → keys are STRINGS, not symbols. Code citations (vision/capability/symbol)
# carry no link; content citations (ticket/note/document/post) carry the frozen fields
- # needed to build a link WITHOUT a DB hit (id/project_id/number/ticket_id…). Lalabase's
- # own texts (help_page) are a third kind: no area, no project, a link to /hilfe/<slug>.
+ # needed to build a link WITHOUT a DB hit (id/project_id/number/ticket_id…), a person
+ # (People S3) the same without a project. Lalabase's own texts (help_page) are a third
+ # kind: no area, no project, a link to /hilfe/<slug>.
# Unknown types render with a generic label + no link, so a future type rollout never
# crashes an old worker rendering newer data.
#
@@ -41,7 +42,9 @@ module Neo
'time_report' => 'bi-stopwatch',
# A page of Lalabase's own help (product knowledge S2): the icon the help wears in the
# navigation and in the contextual help drawer.
- 'help_page' => 'bi-question-circle'
+ 'help_page' => 'bi-question-circle',
+ # A person of the people directory (People S3).
+ 'person' => 'bi-person'
}.freeze
FALLBACK_ICON = 'bi-bookmark'
@@ -144,6 +147,7 @@ module Neo
t('views.organisations.chats.citations.meeting_analysis', title: citation['title'].to_s)
when 'time_report' then t('views.organisations.chats.citations.time_report', title: citation['title'].to_s)
when 'help_page' then t('views.organisations.chats.citations.help_page', title: citation['title'].to_s)
+ when 'person' then t('views.organisations.chats.citations.person', name: citation['name'].to_s)
else t('views.organisations.chats.citations.unknown')
end
end
diff --git a/app/services/lalabase/citation_inline_links.rb b/app/services/lalabase/citation_inline_links.rb
index e23ab85..6777c96 100644
--- a/app/services/lalabase/citation_inline_links.rb
+++ b/app/services/lalabase/citation_inline_links.rb
@@ -34,6 +34,10 @@ module Lalabase
# the sentences of an org-wide answer, and it has a panel rather than a page.
TITLE_TYPES = %w[note document documentation meeting meeting_analysis].freeze
+ # Types matched by their name, the same way (People S3): a person has a name rather
+ # than a title, and the answer names the person it found.
+ NAME_TYPES = %w[person].freeze
+
module_function
# @param html [String] sanitised answer html
@@ -129,6 +133,7 @@ module Lalabase
case citation['type']
when 'ticket' then number_pattern(citation['number'])
when 'post' then number_pattern(citation['ticket_number'])
+ when *NAME_TYPES then title_pattern(citation['name'])
else
return nil unless TITLE_TYPES.include?(citation['type'])
diff --git a/app/services/lalabase/citation_link.rb b/app/services/lalabase/citation_link.rb
index fc8194a..6e8ed4d 100644
--- a/app/services/lalabase/citation_link.rb
+++ b/app/services/lalabase/citation_link.rb
@@ -24,6 +24,8 @@ module Lalabase
# Lalabase's own texts live outside every organisation and project (/hilfe), so the
# project fallback below must not decide whether they get a link.
return product_path(citation) if citation['type'] == 'help_page'
+ # Nor for a person (People S3): the directory belongs to the organisation.
+ return person_path(citation, organisation) if citation['type'] == 'person'
target_project = citation['project_id'].presence || project
return nil if target_project.nil?
@@ -50,6 +52,17 @@ module Lalabase
end
end
+ # The people page with the person in its lane: a member by the account (?member_id=, the
+ # page sends it on to the member's row when there is one), a contact by its row
+ # (?person_id=). See Citations.person for why a member is not addressed by the row.
+ def person_path(citation, organisation)
+ member_id = citation['member_id'].presence
+ return helpers.organisation_people_path(organisation, member_id: member_id) if member_id
+
+ person_id = citation['id'].presence
+ helpers.organisation_people_path(organisation, person_id: person_id) if person_id
+ end
+
# Route helpers without a view context: this runs in the streaming broadcast
# too, where there is no request.
#
@@ -97,6 +110,6 @@ module Lalabase
helpers.organisation_project_documentation_index_path(organisation, project, set_id: set_id, page: page)
end
- private_class_method :product_path, :helpers, :build, :record_path, :documentation_path
+ private_class_method :product_path, :person_path, :helpers, :build, :record_path, :documentation_path
end
end
diff --git a/app/services/lalabase/citation_targets.rb b/app/services/lalabase/citation_targets.rb
index 4cc6e0a..635ed6d 100644
--- a/app/services/lalabase/citation_targets.rb
+++ b/app/services/lalabase/citation_targets.rb
@@ -29,13 +29,19 @@ module Lalabase
# Deliberately without help_page: a help page belongs to no organisation, so it is never
# asked for and never called gone. A page a later release removes keeps its link, and
# /hilfe answers that with its own designed not-found page (HelpController#show).
+ #
+ # Deliberately without 'member' too (People S3): a member is cited by the account, and an
+ # account has no organisation_id to scope the question by. A member who has left keeps the
+ # link, and the people page shows its plain list for a member_id it cannot resolve
+ # (PeopleHelper#people_unresolved_lane_params). A contact is a row, asked like any other.
MODEL_NAMES = {
'ticket' => 'Ticket',
'note' => 'Note',
'document' => 'Document',
'documentation' => 'DocumentationPage',
'meeting' => 'Meeting',
- 'project' => 'Project'
+ 'project' => 'Project',
+ 'person' => 'Person'
}.freeze
EMPTY = Set.new.freeze
diff --git a/app/services/lalabase/citations.rb b/app/services/lalabase/citations.rb
index fa684eb..841e447 100644
--- a/app/services/lalabase/citations.rb
+++ b/app/services/lalabase/citations.rb
@@ -11,18 +11,21 @@ module Lalabase
# the PRODUCER (ProjectRag::Retriever::CITATION_TYPES) and the RENDERER
# (Neo::Chat::CitationListComponent::KNOWN_TYPES), so the two whitelists cannot drift.
# Code citations (vision/capability/symbol) + content citations
- # (ticket/note/document/post/documentation/meeting/meeting_analysis) + Lalabase's own texts
- # (help_page, doc/product_knowledge_plan.md S2: no organisation, no project, no area). Adding a
- # type touches: a shape method below, this list, the component's ICON_MAP + label/link branch,
- # and (for content) the ContentAreaRegistry (see its header for the full cross-cutting checklist).
+ # (ticket/note/document/post/documentation/meeting/meeting_analysis/time_report/person) +
+ # Lalabase's own texts (help_page, doc/product_knowledge_plan.md S2: no organisation, no
+ # project, no area). Adding a type touches: a shape method below, this list, the component's
+ # ICON_MAP + label/link branch, and (for content embedded from fragments) the
+ # ContentAreaRegistry (see its header for the full cross-cutting checklist).
TYPES = %w[vision capability symbol ticket note document post documentation meeting meeting_analysis
- time_report help_page].freeze
+ time_report help_page person].freeze
# The three kinds inside that list, so a guard iterates the right one instead of keeping a
# hand-written table of its own (five specs did; built 12.09.2026):
# CODE — the project's code layer: no area, no record behind it, no link.
# PRODUCT — Lalabase's own texts: no area and no organisation, but a page of their own.
- # CONTENT — the organisation's records: an area that gates them, a project, a link.
+ # CONTENT — the organisation's records: an area that gates them and a link. Most also sit
+ # in a project; a person (People S3) does not, the directory belongs to the
+ # organisation, and CitationLink answers it before it looks for a project.
# CONTENT is derived, so a new type joins it, and its guards, unless it is named above.
CODE_TYPES = %w[vision capability symbol].freeze
PRODUCT_TYPES = %w[help_page].freeze
@@ -73,9 +76,16 @@ module Lalabase
when 'time_report' then target('project', fetch(citation, :project_id))
# A help page points at itself, by slug: it is no record of the organisation.
when 'help_page' then target('help_page', fetch(citation, :id))
+ when 'person' then person_target(citation)
end
end
+ # A member is cited by the account, a contact by the row (see .person).
+ def person_target(citation)
+ member_id = fetch(citation, :member_id)
+ member_id.present? ? target('member', member_id) : target('person', fetch(citation, :id))
+ end
+
# Types whose citation addresses a SLICE of its target rather than the target
# itself. A time report is ONE evaluation over a project: two of them share the
# project and are still two sources, with two filter sets and two links. The
@@ -119,7 +129,7 @@ module Lalabase
# Internal helpers, not part of the module's API: `Citations.fetch` in particular
# is far too generic a name to hand out.
- private_class_method :target, :fetch
+ private_class_method :target, :fetch, :person_target
def vision(vision)
{ type: 'vision', id: vision.id }
@@ -262,5 +272,24 @@ module Lalabase
def help_page(page)
{ type: 'help_page', source: page.source, id: page.slug, locale: page.locale, title: page.title }
end
+
+ # A person of the people directory (People S3), from a People::Directory::Entry. area
+ # 'people' is the right that gates the directory (Permission::CATEGORIES[:people]) and what
+ # makes an answer drawn on it content-bearing: MessageComponent#redacted? then shows it to
+ # the asker only. No project: the directory belongs to the organisation.
+ #
+ # A contact is cited by its row, a member by the account (member_id), the two addresses the
+ # people page opens (?person_id=, ?member_id=). Also a member WITH a row: the page sends
+ # ?member_id= on to the row, and a source keyed by the row would read "no longer there"
+ # once the row is deleted while the member still is. name is the name the tools hand the
+ # model (Entry#plain_name: the account's for a member, the row's for a contact), frozen like
+ # every title here.
+ def person(entry)
+ if entry.member?
+ { type: 'person', area: 'people', id: entry.user.id, member_id: entry.user.id, name: entry.plain_name }
+ else
+ { type: 'person', area: 'people', id: entry.person.id, name: entry.plain_name }
+ end
+ end
end
end
diff --git a/config/locales/views/tickets.de.yml b/config/locales/views/tickets.de.yml
index 17f31e0..2e92483 100644
--- a/config/locales/views/tickets.de.yml
+++ b/config/locales/views/tickets.de.yml
@@ -803,6 +803,7 @@ de:
meeting_analysis: 'Analyse: %{title}'
time_report: 'Zeiten: %{title}'
help_page: 'Hilfe: %{title}'
+ person: 'Person: %{name}'
hits: "%{count} Fundstellen"
gone: nicht mehr vorhanden
composer:
diff --git a/config/locales/views/tickets.en.yml b/config/locales/views/tickets.en.yml
index 2469859..1680341 100644
--- a/config/locales/views/tickets.en.yml
+++ b/config/locales/views/tickets.en.yml
@@ -802,6 +802,7 @@ en:
meeting_analysis: 'Analysis: %{title}'
time_report: 'Time: %{title}'
help_page: 'Help: %{title}'
+ person: 'Person: %{name}'
hits: "%{count} passages"
gone: no longer available
composer:
diff --git a/spec/components/neo/chat/citation_list_component_spec.rb b/spec/components/neo/chat/citation_list_component_spec.rb
index 8d7a5af..5f5e45c 100644
--- a/spec/components/neo/chat/citation_list_component_spec.rb
+++ b/spec/components/neo/chat/citation_list_component_spec.rb
@@ -212,7 +212,7 @@ RSpec.describe Neo::Chat::CitationListComponent, type: :component do
it {
expect(described_class::KNOWN_TYPES)
.to contain_exactly('vision', 'capability', 'symbol', 'ticket', 'note', 'document', 'post', 'documentation', 'meeting', 'meeting_analysis',
- 'time_report', 'help_page')
+ 'time_report', 'help_page', 'person')
}
it { expect(described_class::KNOWN_TYPES).to be_frozen }
it { expect(described_class::ICON_MAP).to be_frozen }
@@ -270,7 +270,8 @@ RSpec.describe Neo::Chat::CitationListComponent, type: :component do
'meeting' => 'bi-chat-quote',
'meeting_analysis' => 'bi-magic',
'time_report' => 'bi-stopwatch',
- 'help_page' => 'bi-question-circle'
+ 'help_page' => 'bi-question-circle',
+ 'person' => 'bi-person'
}.each do |type, icon|
it "renders the literal icon #{icon} for a #{type} citation" do
render_with([{ 'type' => type, 'id' => 'x' }])
@@ -306,6 +307,61 @@ RSpec.describe Neo::Chat::CitationListComponent, type: :component do
end
end
+ # People S3: a person of the directory. No project; the link opens the people page with
+ # the person in the lane, a contact by its row, a member by the account.
+ describe 'a person of the people directory (People S3)' do
+ let(:person_org) { create(:organisation) }
+
+ before { ActsAsTenant.current_tenant = person_org }
+ after { ActsAsTenant.current_tenant = nil }
+
+ def render_person(cite)
+ render_inline(described_class.new(citations: [cite], organisation: person_org))
+ end
+
+ def people_path(**lane)
+ Rails.application.routes.url_helpers.organisation_people_path(person_org, **lane)
+ end
+
+ it 'names a contact and links its row, out of the chat frame' do
+ person = create(:person, organisation: person_org, name: 'Doris Dienstleister')
+ I18n.with_locale(:de) { render_person({ 'type' => 'person', 'area' => 'people', 'id' => person.id, 'name' => person.name }) }
+
+ link = page.find('li a')
+ expect(link[:href]).to eq(people_path(person_id: person.id))
+ expect(link[:'data-turbo-frame']).to eq('_top')
+ expect(link.text).to eq('Person: Doris Dienstleister')
+ expect(page).to have_css('li .bi-person')
+ end
+
+ it 'links a member by the account' do
+ user_id = SecureRandom.uuid
+ render_person({ 'type' => 'person', 'area' => 'people', 'id' => user_id, 'member_id' => user_id, 'name' => 'Carl Kollege' })
+
+ expect(page.find('li a')[:href]).to eq(people_path(member_id: user_id))
+ end
+
+ it 'keeps the name of a deleted contact, without a link' do
+ person = create(:person, organisation: person_org, name: 'Doris Dienstleister')
+ cite = { 'type' => 'person', 'area' => 'people', 'id' => person.id, 'name' => person.name }
+ person.destroy!
+ render_person(cite)
+
+ expect(page).to have_no_css('li a')
+ expect(page).to have_text('Doris Dienstleister')
+ expect(page).to have_css('[data-testid="citation-gone"]')
+ end
+
+ # Both languages read "Person: ...", so a rendered check cannot tell a missing English
+ # key from a present one (i18n.rb falls back to German). Asked without the fallback.
+ it 'has the label in both languages' do
+ %i[de en].each do |locale|
+ label = I18n.t('views.organisations.chats.citations.person', locale: locale, fallback: false, name: 'Doris')
+ expect(label).to eq('Person: Doris'), "#{locale}: #{label}"
+ end
+ end
+ end
+
describe 'one <li> per citation (count contract)' do
# Catches a mutation that duplicates iteration (`flat_map { |c| [c, c] }`)
# or drops items via filter/conditional.
diff --git a/spec/components/neo/chat/message_component_spec.rb b/spec/components/neo/chat/message_component_spec.rb
index 1294744..c0d4ee9 100644
--- a/spec/components/neo/chat/message_component_spec.rb
+++ b/spec/components/neo/chat/message_component_spec.rb
@@ -697,6 +697,54 @@ RSpec.describe Neo::Chat::MessageComponent, type: :component do
expect(page).to have_css('[data-testid="redacted-notice"] .bi-shield-lock')
expect(page).not_to have_css('.prose')
end
+
+ # People S3: an answer drawn on the people directory carries the people area. The
+ # citation comes from the producer itself (Citations.person), so the gate reads what the
+ # tools emit: without the area the answer would count as content-free and reach every
+ # reader, the broadcast included. The asker sees it, nobody else, not even someone who
+ # may open the directory.
+ describe 'an answer about a person of the people directory (People S3)' do
+ let(:person) { create(:person, organisation: organisation, name: 'Doris Dienstleister', phone: '+49 30 1234567') }
+ let(:person_answer) do
+ entry = People::Directory::Entry.new(kind: :contact, user: nil, person: person)
+ chat.chatposts.create!(
+ organisation: organisation, role: 'assistant', model_used: 'gpt-x',
+ content: 'Doris Dienstleister erreichst du unter +49 30 1234567.',
+ source_citations: [Lalabase::Citations.person(entry).deep_stringify_keys]
+ )
+ end
+
+ def directory_reader
+ role = create(:role, organisation: organisation)
+ create(:permission, role: role, category: 'people', action: 'view_people', allowed: true)
+ reader = create(:user)
+ create(:membership, user: reader, organisation: organisation, role: role, active: true)
+ reader
+ end
+
+ it 'shows the answer and its person to the owner of the thread' do
+ render_for(chat.user, post: person_answer)
+
+ expect(rendered_content).to include('+49 30 1234567')
+ expect(rendered_content).to include('Person: Doris Dienstleister')
+ end
+
+ it 'redacts it for a non-owner, even one who may open the directory' do
+ render_for(directory_reader, post: person_answer)
+
+ expect(rendered_content).to include(I18n.t('views.organisations.chats.message.redacted'))
+ expect(rendered_content).not_to include('+49 30 1234567')
+ expect(rendered_content).not_to include('Doris Dienstleister')
+ end
+
+ it 'redacts it in the broadcast, which renders without a viewer' do
+ render_inline(described_class.new(chatpost: person_answer))
+
+ expect(rendered_content).to include(I18n.t('views.organisations.chats.message.redacted'))
+ expect(rendered_content).not_to include('+49 30 1234567')
+ expect(rendered_content).not_to include('Doris Dienstleister')
+ end
+ end
end
# Source attribution (chat_quellen_attribution_plan.md §6.3/§7). Slice 1 wires the
diff --git a/spec/services/assistant/analysis_sources_spec.rb b/spec/services/assistant/analysis_sources_spec.rb
index 5e02570..b736ee8 100644
--- a/spec/services/assistant/analysis_sources_spec.rb
+++ b/spec/services/assistant/analysis_sources_spec.rb
@@ -39,6 +39,24 @@ RSpec.describe Assistant::AnalysisSources do
expect(readable(citation)).to be false
end
+ # People S3: an answer drawn on the people directory is the asker's alone. Saved as a
+ # meeting analysis it would reach every reader of the meeting, who need not see the
+ # directory. So a person is never a certified source here, not even for an asker who may
+ # open the directory: an unknown type fails closed, and this pins that it stays unknown.
+ it 'never certifies a person of the people directory as a source' do
+ role = Membership.find_by(user: user, organisation: organisation).role
+ create(:permission, role: role, category: 'people', action: 'view_people', allowed: true)
+ entry = People::Directory::Entry.new(kind: :contact, user: nil, person: create(:person, organisation: organisation))
+ meeting_cite = Lalabase::Citations.meeting(meeting)
+ person_cite = Lalabase::Citations.person(entry)
+
+ expect(PersonPolicy.view_allowed?(user, organisation)).to be true
+ expect(readable(meeting_cite)).to be true
+ expect(readable(meeting_cite, person_cite)).to be false
+ context = { 'provenance' => [meeting_cite, person_cite].map(&:deep_stringify_keys) }
+ expect(described_class.publishable?(context: context, meeting: meeting)).to be false
+ end
+
it 'rejects incomplete time-report provenance' do
expect(readable(Lalabase::Citations.time_report(project).merge(scope: 'all'))).to be false
end
diff --git a/spec/services/lalabase/citation_inline_links_spec.rb b/spec/services/lalabase/citation_inline_links_spec.rb
index 1213623..3508c06 100644
--- a/spec/services/lalabase/citation_inline_links_spec.rb
+++ b/spec/services/lalabase/citation_inline_links_spec.rb
@@ -78,6 +78,17 @@ RSpec.describe Lalabase::CitationInlineLinks do
.not_to include('</a>')
end
+ # People S3: a person has a name rather than a title, and the answer names the person
+ # it found ("Ansprechpartnerin ist Doris Dienstleister").
+ it 'links the name of a cited person to the people page' do
+ cite = { 'type' => 'person', 'area' => 'people', 'id' => 'pid', 'name' => 'Doris Dienstleister' }
+ result = apply('<p>Ansprechpartnerin ist Doris Dienstleister.</p>', [cite])
+
+ href = Rails.application.routes.url_helpers.organisation_people_path(organisation, person_id: 'pid')
+ expect(result).to include(%(href="#{href}"))
+ expect(result).to include('>Doris Dienstleister</a>')
+ end
+
# Category 3: n-1 / n / n+1 at MIN_TITLE_LENGTH, driven from the constant.
# A test with a three-character title against a seventeen-character title
# survives any shift of the boundary; only these three examples die when
@@ -378,12 +389,14 @@ RSpec.describe Lalabase::CitationInlineLinks do
end
describe 'the type table' do
- it 'looks for titles only among types the citation shapes actually know' do
+ it 'looks for titles and names only among types the citation shapes actually know' do
expect(described_class::TITLE_TYPES - Lalabase::Citations::TYPES).to be_empty
+ expect(described_class::NAME_TYPES - Lalabase::Citations::TYPES).to be_empty
end
it 'holds its tables frozen, so nothing can widen them at runtime' do
expect(described_class::TITLE_TYPES).to be_frozen
+ expect(described_class::NAME_TYPES).to be_frozen
expect(described_class::SKIP_ANCESTORS).to be_frozen
end
@@ -396,8 +409,10 @@ RSpec.describe Lalabase::CitationInlineLinks do
expect(described_class::SKIP_ANCESTORS).to include('a', 'code', 'pre')
end
- it 'has a decision for EVERY content type: by number, by title, or deliberately not at all' do
+ it 'has a decision for EVERY content type: by number, by title, by name, or deliberately not at all' do
by_number = %w[ticket post]
+ # person (People S3): the name, which is what an answer calls a person.
+ by_name = described_class::NAME_TYPES
# time_report: its title is the project name, and it has a panel. help_page: help titles
# are everyday words in an answer ("Zeiterfassung", "Aktivitäten"); the source row links it.
deliberately_unlinked = %w[time_report help_page]
@@ -405,7 +420,7 @@ RSpec.describe Lalabase::CitationInlineLinks do
content_types.each do |type|
decided = by_number.include?(type) || described_class::TITLE_TYPES.include?(type) ||
- deliberately_unlinked.include?(type)
+ by_name.include?(type) || deliberately_unlinked.include?(type)
expect(decided).to be(true), "#{type} is matched by nothing and excluded by nobody"
end
end
diff --git a/spec/services/lalabase/citation_link_spec.rb b/spec/services/lalabase/citation_link_spec.rb
index 63baaed..b2e663d 100644
--- a/spec/services/lalabase/citation_link_spec.rb
+++ b/spec/services/lalabase/citation_link_spec.rb
@@ -133,6 +133,30 @@ RSpec.describe Lalabase::CitationLink do
end
end
+ # People S3: the directory belongs to the organisation, not to a project, so the project
+ # fallback must neither give a person its link nor take it away.
+ describe 'a person' do
+ let(:contact) { { 'type' => 'person', 'area' => 'people', 'id' => 'pid', 'name' => 'Doris Dienstleister' } }
+ let(:member) { { 'type' => 'person', 'area' => 'people', 'id' => 'uid', 'member_id' => 'uid', 'name' => 'Carl' } }
+
+ it 'opens a contact on the people page by its row' do
+ expect(path(contact)).to eq(routes.organisation_people_path(organisation, person_id: 'pid'))
+ end
+
+ it 'opens a member on the people page by the account' do
+ expect(path(member)).to eq(routes.organisation_people_path(organisation, member_id: 'uid'))
+ end
+
+ it 'needs no project and ignores one the caller offers' do
+ expect(path(contact, project_fallback: project))
+ .to eq(routes.organisation_people_path(organisation, person_id: 'pid'))
+ end
+
+ it 'gives none without an id' do
+ expect(path(contact.merge('id' => ''))).to be_nil
+ end
+ end
+
it 'points a note, a document and a meeting at their own pages' do
{ 'note' => :organisation_project_note_path,
'document' => :organisation_project_document_path,
diff --git a/spec/services/lalabase/citation_targets_spec.rb b/spec/services/lalabase/citation_targets_spec.rb
index 7a1f604..38fc150 100644
--- a/spec/services/lalabase/citation_targets_spec.rb
+++ b/spec/services/lalabase/citation_targets_spec.rb
@@ -121,6 +121,30 @@ RSpec.describe Lalabase::CitationTargets do
expect(resolver([deleted_project]).gone?(deleted_project)).to be(true)
end
+ # People S3: a contact points at its row, so a deleted row is gone like a deleted ticket.
+ it 'follows a contact to its person row' do
+ person = create(:person, organisation: organisation)
+ cite = { 'type' => 'person', 'area' => 'people', 'id' => person.id, 'name' => person.name }
+
+ expect(resolver([cite]).gone?(cite)).to be(false)
+
+ person.destroy!
+
+ expect(resolver([cite]).gone?(cite)).to be(true)
+ end
+
+ # A member points at the account, and an account has no organisation to scope it by.
+ # Never asked, so never gone: a member who has left opens the plain people list, which
+ # drops a member_id it cannot resolve (PeopleHelper#people_unresolved_lane_params).
+ it 'never asks for a member, so a member is never called gone' do
+ user_id = SecureRandom.uuid
+ cite = { 'type' => 'person', 'area' => 'people', 'id' => user_id, 'member_id' => user_id, 'name' => 'X' }
+
+ expect(Lalabase::Citations.target_of(cite)).to eq(type: 'member', id: user_id)
+ expect(described_class::MODEL_NAMES).not_to have_key('member')
+ expect(resolver([cite]).gone?(cite)).to be(false)
+ end
+
it 'never calls the code layer gone — it points at no record' do
Lalabase::Citations::CODE_TYPES.each do |type|
cite = { 'type' => type, 'id' => SecureRandom.uuid }
diff --git a/spec/services/lalabase/citations_spec.rb b/spec/services/lalabase/citations_spec.rb
index e832161..4a176bf 100644
--- a/spec/services/lalabase/citations_spec.rb
+++ b/spec/services/lalabase/citations_spec.rb
@@ -344,7 +344,9 @@ RSpec.describe Lalabase::Citations do
.to match_array(described_class::TYPES)
expect(described_class::CODE_TYPES).to contain_exactly('vision', 'capability', 'symbol')
expect(described_class::PRODUCT_TYPES).to contain_exactly('help_page')
- expect(described_class::CONTENT_TYPES).to include('ticket', 'note', 'time_report')
+ # person (People S3) is content WITHOUT a project: the area gates it and it has a page,
+ # so every content guard applies to it. A fourth kind would excuse it from all of them.
+ expect(described_class::CONTENT_TYPES).to include('ticket', 'note', 'time_report', 'person')
end
it 'name only types the shapes actually know' do
@@ -457,4 +459,59 @@ RSpec.describe Lalabase::Citations do
expect(described_class.source_key_of(cite)).to eq(%w[help_page guides/features/time-tracking])
end
end
+
+ # A person of the people directory (People S3): content of the organisation without a
+ # project. A contact is cited by its row, a member by the account, the two addresses the
+ # people page opens (?person_id=, ?member_id=).
+ describe '.person' do
+ let(:row) { instance_double(Person, id: 'pe-1', name: 'Doris Dienstleister') }
+ let(:account) { instance_double(User, id: 'u-1', display_name: 'Carl Kollege') }
+ let(:contact) { People::Directory::Entry.new(kind: :contact, user: nil, person: row) }
+ let(:member) { People::Directory::Entry.new(kind: :member, user: account, person: nil) }
+ let(:member_with_row) do
+ People::Directory::Entry.new(kind: :member, user: account,
+ person: instance_double(Person, id: 'pe-2', name: 'C. Kollege (alt)'))
+ end
+
+ it 'cites a contact by its row, with the people area and the name' do
+ expect(described_class.person(contact)).to eq(type: 'person', area: 'people', id: 'pe-1',
+ name: 'Doris Dienstleister')
+ end
+
+ it 'cites a member by the account, with the name from the account' do
+ expect(described_class.person(member)).to eq(type: 'person', area: 'people', id: 'u-1', member_id: 'u-1',
+ name: 'Carl Kollege')
+ end
+
+ # A member's page follows the account whether or not the member has a row: the people
+ # page sends ?member_id= on to the row. Cited by the row instead, the source would read
+ # "no longer there" once the row is deleted, while the member still is.
+ it 'cites a member with a row of their own by the account too, named from the account' do
+ expect(described_class.person(member_with_row)).to eq(type: 'person', area: 'people', id: 'u-1',
+ member_id: 'u-1', name: 'Carl Kollege')
+ end
+
+ # The area is the right that gates the directory (Permission::CATEGORIES[:people]), and
+ # what makes an answer drawn on it content-bearing: MessageComponent#redacted? then shows
+ # it to the asker only.
+ it 'carries the people area, which makes an answer drawn on it content-bearing' do
+ expect(Permission::CATEGORIES).to have_key(:people)
+ expect(described_class.areas_of([described_class.person(contact).deep_stringify_keys])).to eq([:people])
+ end
+
+ it 'points a contact at its row and a member at the account' do
+ expect(described_class.target_of(described_class.person(contact).deep_stringify_keys))
+ .to eq(type: 'person', id: 'pe-1')
+ expect(described_class.target_of(described_class.person(member).deep_stringify_keys))
+ .to eq(type: 'member', id: 'u-1')
+ end
+
+ it 'groups two citations of one person into one source' do
+ cite = described_class.person(member).deep_stringify_keys
+
+ expect(described_class.source_key_of(cite)).to eq(described_class.source_key_of(cite.dup))
+ expect(described_class.source_key_of(cite))
+ .not_to eq(described_class.source_key_of(described_class.person(contact).deep_stringify_keys))
+ end
+ end
end
diff --git a/spec/services/lalabase/project_rag/retriever_spec.rb b/spec/services/lalabase/project_rag/retriever_spec.rb
index a54601c..dacf101 100644
--- a/spec/services/lalabase/project_rag/retriever_spec.rb
+++ b/spec/services/lalabase/project_rag/retriever_spec.rb
@@ -129,7 +129,7 @@ RSpec.describe Lalabase::ProjectRag::Retriever do
it {
expect(described_class::CITATION_TYPES)
.to contain_exactly('vision', 'capability', 'symbol', 'ticket', 'note', 'document', 'post', 'documentation',
- 'meeting', 'meeting_analysis', 'time_report', 'help_page')
+ 'meeting', 'meeting_analysis', 'time_report', 'help_page', 'person')
}
it { expect(described_class::CITATION_TYPES).to be_frozen }
end