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.

feat(glossary): export the heard forms a member spoke and unlink them on erasure

Guido Boyke1b0de172646a
diff --git a/app/models/concerns/personal_data_erasure.rb b/app/models/concerns/personal_data_erasure.rb
index e240898..87b0447 100644
--- a/app/models/concerns/personal_data_erasure.rb
+++ b/app/models/concerns/personal_data_erasure.rb
@@ -3,7 +3,7 @@
# Erases the personal records an account owns BEYOND the users row itself, for
# the account-erasure path: GDPR export archives, private meeting analyses,
# private ticket posts, personal tasks, linked people directory rows, the
-# account's own chat threads (via
+# speaker link of glossary heard forms, the account's own chat threads (via
# PersonalChatErasure, which is included here so that both entry points get it
# through this ONE include) and, as access revocation, its personal access
# tokens.
@@ -39,6 +39,7 @@ module PersonalDataErasure
erase_personal_tasks!
erase_personal_chats!
erase_person_links!
+ erase_term_correction_speakers!
revoke_personal_access_tokens!
end
@@ -120,6 +121,18 @@ module PersonalDataErasure
end
end
+ # The glossary heard forms this account spoke (term_corrections.user_id), in
+ # every organisation. A heard form is knowledge of the organisation and stays,
+ # as when a person of the directory is deleted (plan §3.3, K4a); only the link
+ # to the erased account goes. A soft delete never fires the FK's
+ # on_delete: :nullify, so the step is explicit. update_all: no callbacks, and
+ # the one-speaker check holds (person_id stays as it is, empty).
+ def erase_term_correction_speakers!
+ ActsAsTenant.without_tenant do
+ TermCorrection.where(user_id: id).update_all(user_id: nil, updated_at: Time.current)
+ end
+ end
+
# Access revocation rather than erasure: a personal access token authenticates
# by its hash alone (PersonalAccessToken.authenticate joins no users), so a
# token surviving the erasure keeps answering the API for up to 90 days with
diff --git a/app/models/meeting.rb b/app/models/meeting.rb
index 596c490..88f8435 100644
--- a/app/models/meeting.rb
+++ b/app/models/meeting.rb
@@ -266,6 +266,13 @@ class Meeting < ApplicationRecord
# See the before_destroy declaration: subselect the fragment ids (they still
# exist because this runs BEFORE the dependent delete_all) and drop their sidecar
# rows synchronously — a de-indexed/deleted transcript leaves no retrievable trace.
+ #
+ # One deliberate exception (glossary K4a, E4, decided 2026-11-04): the heard
+ # forms of the glossary (term_corrections) STAY, with their place in the
+ # transcript (line_index, char_offset, transcript_digest); only meeting_id is
+ # cleared, by the foreign key (on_delete: :nullify), nothing here. A correction
+ # is knowledge of the organisation that a person confirmed, not content of the
+ # conversation. Do not purge them here, and do not turn that key into a cascade.
def purge_fragment_content_embeddings
ContentEmbedding.purge_for(embeddable_type: 'Fragment', embeddable_ids: fragments.select(:id))
end
diff --git a/app/services/user_data_exports/registry.rb b/app/services/user_data_exports/registry.rb
index d38aafd..f27affa 100644
--- a/app/services/user_data_exports/registry.rb
+++ b/app/services/user_data_exports/registry.rb
@@ -225,6 +225,17 @@ module UserDataExports
attributes: %w[name salutation function department company email phone additional_details notes
created_at updated_at],
scope: ->(user) { Person.where(user_id: user.id) }),
+ # The heard forms of the glossary this account SPOKE (term_corrections.
+ # user_id, the speaker as a member, K4a): what speech recognition heard
+ # from the person, for which term, in which project and when. Data about
+ # the account, so it is exported. The table's two other person
+ # references are not: corrected_by_id is authoring metadata on org
+ # knowledge (as analysis_prompts), and person_id is a row of the people
+ # directory, exported through :people when it is the account's own.
+ source(key: :term_corrections, model: 'TermCorrection', tenant_scoped: true,
+ attributes: %w[heard replaced_count created_at],
+ computed: { term: ->(r) { r.glossary_term&.term }, project_name: ->(r) { r.project&.name } },
+ scope: ->(user) { TermCorrection.where(user_id: user.id).includes(:glossary_term, :project) }),
source(key: :notification_subscriptions, model: 'NotificationSubscription', tenant_scoped: true,
attributes: %w[subscribable_type source created_at],
scope: ->(user) { NotificationSubscription.where(user: user) }),
@@ -269,6 +280,9 @@ module UserDataExports
'recreatable UX state — no exportable content',
'analysis_prompts' => 'Org-wide prompt library asset (Gespräche Slice 7a); creator_id is ' \
'authoring metadata on shared org infrastructure (role model, org export)',
+ 'glossary_terms' => 'Org-wide glossary (K4a, role model); created_by_id is authoring metadata on ' \
+ 'shared org knowledge, like analysis_prompts. The heard forms a person spoke are ' \
+ 'exported as term_corrections.json',
'user_deletions' => 'Deletion audit log, metadata only by design; core state is in account.json',
'user_data_exports' => 'The export mechanism itself; state is visible on the export page',
'attachment_deletion_records' => 'Deletion proof owed to the CONTROLLER, not to the user ' \
diff --git a/spec/models/user_erasure_path_parity_spec.rb b/spec/models/user_erasure_path_parity_spec.rb
index 6b6ba06..ac77fad 100644
--- a/spec/models/user_erasure_path_parity_spec.rb
+++ b/spec/models/user_erasure_path_parity_spec.rb
@@ -249,6 +249,27 @@ RSpec.describe 'Account erasure path parity', type: :model do
end
end
+ # K4a: the heard form stays as knowledge of the organisation, only the
+ # speaker link to the erased account goes (plan §3.3, like a deleted person).
+ describe 'glossary heard forms the account spoke' do
+ it 'clears the speaker in every organisation and keeps the heard forms' do
+ create(:membership, user: user, organisation: other_organisation)
+ term = create(:glossary_term, organisation: organisation)
+ spoken = create(:term_correction, organisation: organisation, glossary_term: term, user: user)
+ spoken_elsewhere = ActsAsTenant.with_tenant(other_organisation) do
+ create(:term_correction, organisation: other_organisation, user: user)
+ end
+ by_colleague = create(:term_correction, organisation: organisation, glossary_term: term, user: colleague)
+
+ record.soft_delete_and_anonymize!
+
+ ActsAsTenant.without_tenant do
+ expect(TermCorrection.where(id: [spoken.id, spoken_elsewhere.id]).pluck(:user_id)).to eq([nil, nil])
+ expect(TermCorrection.find(by_colleague.id).user_id).to eq(colleague.id)
+ end
+ end
+ end
+
describe 'personal access tokens (access revocation)' do
it 'revokes the tokens so they stop authenticating' do
raw = create(:personal_access_token, user: user, organisations: [organisation]).token
diff --git a/spec/services/user_data_exports/registry_guards_spec.rb b/spec/services/user_data_exports/registry_guards_spec.rb
index 8f02b7f..b0753ff 100644
--- a/spec/services/user_data_exports/registry_guards_spec.rb
+++ b/spec/services/user_data_exports/registry_guards_spec.rb
@@ -120,6 +120,33 @@ RSpec.describe UserDataExports::Registry do
end
end
+ # K4a: the heard forms a member spoke are data about the account; who
+ # corrected them and the glossary itself are org knowledge (EXCLUDED).
+ describe 'term_corrections (the heard forms the account spoke)' do
+ it 'exports the spoken forms only, with term and project, never who corrected them' do
+ source = described_class::SOURCES.find { |s| s.key == :term_corrections }
+ speaker = create(:user)
+ corrector = create(:user)
+ organisation = create(:organisation)
+
+ ActsAsTenant.with_tenant(organisation) do
+ create(:membership, user: speaker, organisation: organisation)
+ create(:membership, user: corrector, organisation: organisation)
+ project = create(:project, organisation: organisation, name: 'Beispielprojekt')
+ term = create(:glossary_term, organisation: organisation, term: 'Lalabase')
+ spoken = create(:term_correction, organisation: organisation, glossary_term: term, project: project,
+ heard: 'lala bass', user: speaker, corrected_by: corrector)
+ create(:term_correction, organisation: organisation, glossary_term: term, user: corrector)
+
+ expect(source.scope.call(speaker).to_a).to eq([spoken])
+ expect(source.computed[:term].call(spoken)).to eq('Lalabase')
+ expect(source.computed[:project_name].call(spoken)).to eq('Beispielprojekt')
+ end
+ expect(source.exported_keys).not_to include('corrected_by_id', 'user_id', 'person_id')
+ expect(described_class::EXCLUDED).to have_key('glossary_terms')
+ end
+ end
+
describe 'completeness guard' do
def user_referencing_tables
connection = ActiveRecord::Base.connection