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(glossary): give every heard form a status of its own
Guido Boykecaa1db06e09d
diff --git a/app/models/term_correction.rb b/app/models/term_correction.rbindex 0881878..970b0a4 100644--- a/app/models/term_correction.rb+++ b/app/models/term_correction.rb@@ -17,6 +17,14 @@# Meeting#purge_fragment_content_embeddings). Deleting the project or the# person clears the origin or the speaker the same way. Deleting the term or# the organisation takes the row with it.+#+# Every row has a status of its own (K4b, E3): a correction in a meeting+# without manage_glossary is proposed, also at a confirmed term, so it works+# nowhere before someone with the right confirmed it. Rows written before K4b+# are confirmed (the column's default; the check constraint+# term_corrections_status_known holds the two values). What works is a+# confirmed row at a confirmed term: .effective, the one reader K4c and the+# device (M4) go through.class TermCorrection < ApplicationRecord# The references to rows of an organisation, declared BEFORE acts_as_tenant:# acts_as_tenant 1.0.1 checks the tenant only of references declared before@@ -37,6 +45,9 @@ class TermCorrection < ApplicationRecordbelongs_to :corrected_by, class_name: 'User', optional: trueDIGEST_FORMAT = /\A\h{64}\z/+ STATUSES = %w[proposed confirmed].freeze++ enum :status, STATUSES.index_by(&:itself), validate: true# Terms and heard forms share one right (GlossaryPolicy), for authorize,# policy and policy_scope alike.@@ -44,6 +55,11 @@ class TermCorrection < ApplicationRecordGlossaryPolicyend+ # The heard forms that work: confirmed, at a confirmed term. A proposal (at+ # any term) and any form of a proposed or rejected term do not. Inside the+ # tenant like every other query of this model.+ scope :effective, -> { confirmed.joins(:glossary_term).merge(GlossaryTerm.confirmed) }+before_validation :normalize_heardvalidates :heard, presence: true, length: { maximum: GlossaryTerm::MAX_LENGTH }diff --git a/db/migrate/20261105100000_add_status_to_term_corrections.rb b/db/migrate/20261105100000_add_status_to_term_corrections.rbnew file mode 100644index 0000000..1e0fe3e--- /dev/null+++ b/db/migrate/20261105100000_add_status_to_term_corrections.rb@@ -0,0 +1,21 @@+# frozen_string_literal: true++# Every heard form of the glossary has a status of its own (K4b, E3): a+# correction in a meeting without manage_glossary is a proposal, also at a+# term that is already confirmed, so it cannot work in other meetings before+# someone with the right confirmed it. Only a confirmed form at a confirmed+# term works (TermCorrection.effective).+#+# Every row written before K4b was written by hand or confirmed with the right,+# so the default says confirmed and no backfill is needed. A constant default+# on a new column is a metadata-only change in PostgreSQL. The check+# constraint is the second line behind the model's enum (pattern:+# users_email_visibility_known).+class AddStatusToTermCorrections < ActiveRecord::Migration[8.1]+ def change+ change_table :term_corrections, bulk: true do |t|+ t.string :status, null: false, default: 'confirmed'+ t.check_constraint "status IN ('proposed', 'confirmed')", name: 'term_corrections_status_known'+ end+ end+enddiff --git a/db/schema.rb b/db/schema.rbindex 8b11d34..929703b 100644--- a/db/schema.rb+++ b/db/schema.rb@@ -10,7 +10,7 @@## It's strongly recommended that you check this file into your version control system.-ActiveRecord::Schema[8.1].define(version: 2026_11_04_100200) do+ActiveRecord::Schema[8.1].define(version: 2026_11_05_100000) do# These are extensions that must be enabled in order to support this databaseenable_extension "pg_catalog.plpgsql"enable_extension "pgcrypto"@@ -1707,6 +1707,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_04_100200) dot.uuid "corrected_by_id"t.datetime "created_at", null: falset.datetime "updated_at", null: false+ t.string "status", default: "confirmed", null: falset.index ["corrected_by_id"], name: "index_term_corrections_on_corrected_by_id"t.index ["glossary_term_id", "normalized_heard"], name: "index_term_corrections_on_term_and_heard"t.index ["meeting_id"], name: "index_term_corrections_on_meeting_id"@@ -1715,6 +1716,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_04_100200) dot.index ["project_id"], name: "index_term_corrections_on_project_id"t.index ["user_id"], name: "index_term_corrections_on_user_id"t.check_constraint "num_nonnulls(person_id, user_id) <= 1", name: "term_corrections_one_speaker"+ t.check_constraint "status::text = ANY (ARRAY['proposed'::character varying, 'confirmed'::character varying]::text[])", name: "term_corrections_status_known"endcreate_table "ticket_assignments", force: :cascade do |t|diff --git a/spec/models/term_correction_spec.rb b/spec/models/term_correction_spec.rbindex e543ab3..6bd1c6c 100644--- a/spec/models/term_correction_spec.rb+++ b/spec/models/term_correction_spec.rb@@ -62,6 +62,52 @@ RSpec.describe TermCorrection, :ci_guard, type: :model dotranscript_digest: 'a' * 64)).to be_validend+ # Every heard form has a status of its own (K4b, E3): a correction without+ # manage_glossary is a proposal, also at a confirmed term. Rows written+ # before K4b are confirmed (the column's default).+ describe 'the status' do+ it 'is confirmed unless set, the state of every row before K4b' do+ expect(create(:term_correction, organisation: organisation, glossary_term: term)).to be_confirmed+ end++ it 'knows proposed and confirmed, nothing else' do+ expect(build(:term_correction, organisation: organisation, glossary_term: term, status: 'proposed')).to be_valid+ expect(build(:term_correction, organisation: organisation, glossary_term: term, status: 'rejected')).not_to be_valid+ expect(build(:term_correction, organisation: organisation, glossary_term: term, status: nil)).not_to be_valid+ end++ it 'is held by the database too' do+ correction = create(:term_correction, organisation: organisation, glossary_term: term)++ expect { described_class.where(id: correction.id).update_all(status: 'rejected') }+ .to raise_error(ActiveRecord::StatementInvalid, /term_corrections_status_known/)+ end+ end++ # What K4c and the device (M4) read: a confirmed form at a confirmed term.+ # A proposal at a confirmed term and a confirmed form at a proposed or a+ # rejected term do not work anywhere yet.+ describe '.effective' do+ let(:proposed_term) { create(:glossary_term, :proposed, organisation: organisation, term: 'Zirbelholz') }+ let(:rejected_term) { create(:glossary_term, :rejected, organisation: organisation, term: 'Ahornsirup') }++ it 'is the confirmed forms of confirmed terms, and nothing else' do+ effective = create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lala bass')+ create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lala base', status: 'proposed')+ create(:term_correction, organisation: organisation, glossary_term: proposed_term, heard: 'zirbel holz')+ create(:term_correction, organisation: organisation, glossary_term: rejected_term, heard: 'ahorn sirup')++ expect(described_class.effective).to contain_exactly(effective)+ end++ it 'stays inside the tenant' do+ theirs = ActsAsTenant.with_tenant(other_organisation) { create(:term_correction, organisation: other_organisation) }++ expect(described_class.effective).not_to include(theirs)+ expect(ActsAsTenant.with_tenant(other_organisation) { described_class.effective.to_a }).to contain_exactly(theirs)+ end+ end+describe 'the speaker' dolet(:person) { create(:person, organisation: organisation) }let(:member) { member_of(organisation) }