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.

fix: review round 4 of #113, refuse stale saves and invisible twins, hide speakers a reader cannot see

Guido Boyke8bb4e1e22fd3
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.yml
index 0534884..baed24d 100644
--- a/.github/workflows/guards.yml
+++ b/.github/workflows/guards.yml
@@ -348,6 +348,7 @@ jobs:
spec/models/term_correction_spec.rb
spec/requests/organisations/roles_glossary_right_spec.rb
spec/services/actors/merge_glossary_terms_spec.rb
+ spec/services/actors/save_glossary_term_spec.rb
spec/requests/organisations/glossary_spec.rb
spec/requests/organisations/people_spec.rb
spec/requests/organisations/shown_email_spec.rb
diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css
index 0e7e8b9..a004a6b 100644
--- a/app/assets/stylesheets/application.tailwind.css
+++ b/app/assets/stylesheets/application.tailwind.css
@@ -528,7 +528,7 @@
.glossary-row { @apply items-start; }
.glossary-row--rejected .people-row__name { @apply text-muted line-through; }
.glossary-row__head { @apply flex min-w-0 flex-wrap items-center gap-1.5; }
- .glossary-row__origin { @apply text-cream-500; }
+ .glossary-row__origin { @apply text-muted; }
.glossary-row__count { @apply w-10 flex-none self-center text-end text-xs tabular-nums text-muted; }
.glossary-status { @apply shrink-0 rounded-full px-1.5 text-[11px]; }
.glossary-status--proposed { border: 1px solid #C08A3E; color: #8A5A1C; }
diff --git a/app/controllers/concerns/CLAUDE.md b/app/controllers/concerns/CLAUDE.md
index 44f0bdb..4c63b89 100644
--- a/app/controllers/concerns/CLAUDE.md
+++ b/app/controllers/concerns/CLAUDE.md
@@ -97,7 +97,10 @@ eigene Zeile, `PeopleController#member`); `user_id` gehört zur Formular-Gruppe.
Das Glossar (`Organisations::GlossaryController`, K4a, 04.11.2026) ist die siebte Bahn, gebaut
wie die Personenliste (dieselben Stimulus-Controller und `people-*`-Klassen), mit `term_id` als
einziger Auswahl und den Filtern `project_id`, `category`, `status` (`LIST_PARAMS`, unbekannte
-Werte fallen weg). Meeting-Titel nur über `policy_scope(Meeting)`, nie vorgeladen.
+Werte fallen weg). Meeting-Titel nur über `policy_scope(Meeting)`, nie vorgeladen. Ein Sprecher
+hat einen Namen nur, wenn der Leser ihn auf der Mitglieder- oder Personenseite sehen darf
+(`MembershipPolicy::Scope`, `PersonPolicy::Scope`), sonst steht ein neutrales Wort; verlinkt nur
+mit `view_people` und nur auf aktive Mitglieder (die Personenseite listet nur sie).
Der Entscheid für EINE kanonische Listen-Architektur steht aus; bis dahin gilt für neue
Listen-Features: am ähnlichsten Bestands-Feature orientieren und die Wahl im PR begründen.
Seit 10.09.2026 teilen Tickets und Knowledge immerhin die OBERFLÄCHE der Liste-mit-Bahn
diff --git a/app/controllers/organisations/glossary_controller.rb b/app/controllers/organisations/glossary_controller.rb
index 1e749db..c2ef017 100644
--- a/app/controllers/organisations/glossary_controller.rb
+++ b/app/controllers/organisations/glossary_controller.rb
@@ -19,8 +19,9 @@
# its frame have nothing to show, and a redirect inside the lane frame loops.
# A term of another organisation is no term at all (404). The glossary shows
# heard forms from every project (E3), but the title and the link of a meeting
-# only to a reader of that meeting, and the link to a person only with
-# view_people (GlossaryHelper).
+# only to a reader of that meeting, a speaker's name only to a reader who may
+# see that speaker on the members or the people page, and the link to a
+# speaker only with view_people as well (GlossaryHelper).
module Organisations
class GlossaryController < Organisations::BaseController
include ViewportSwitchable
@@ -135,15 +136,19 @@ module Organisations
if result.success?
redirect_to index_path(term_id: result.resource.id), status: :see_other, notice: t(flash_key)
else
- render_refused_save(result)
+ render_refused_save(result, id)
end
end
# The index again, with the form open in the lane and the reason above it.
- def render_refused_save(result)
+ # A stale save shows the CURRENT values (and their lock_version): the
+ # other side's change stays, and the writer sees what they would
+ # overwrite, as on the people page.
+ def render_refused_save(result, id)
@terms = policy_scope(GlossaryTerm)
- @form_term = result.resource || new_term
- @form_message = result.errors.to_sentence
+ stale = result.code == :stale_object
+ @form_term = stale ? @terms.find(id) : (result.resource || new_term)
+ @form_message = stale ? t('controllers.glossary.update.stale') : result.errors.to_sentence
load_list
render :index, status: :unprocessable_content
end
@@ -164,8 +169,10 @@ module Organisations
end
end
+ # expect, not require.permit: a glossary_term that is no hash (a hand-made
+ # request) answers 400 instead of crashing.
def term_params
- params.require(:glossary_term).permit(*Actors::SaveGlossaryTerm::ATTRIBUTES)
+ params.expect(glossary_term: Actors::SaveGlossaryTerm::ATTRIBUTES)
end
def refuse_merge_without_target
@@ -283,17 +290,25 @@ module Organisations
end
helper_method :glossary_people_linkable?
- # The rows and members the reader may see on the people page
- # (PersonPolicy::Scope, MembershipPolicy::Scope), once per request: a
- # speaker links only to one of them, so the link never opens an empty lane.
+ # The rows of the people directory the reader may see there
+ # (PersonPolicy::Scope), once per request: a speaker who is one of them
+ # shows its name and links to it. None without view_people, which the
+ # people page needs (no query then).
def glossary_visible_person_ids
@glossary_visible_person_ids ||= policy_scope(Person).pluck(:id).to_set
end
helper_method :glossary_visible_person_ids
- def glossary_visible_member_ids
- @glossary_visible_member_ids ||= policy_scope(Membership).where(organisation: current_organisation).pluck(:user_id).to_set
- end
- helper_method :glossary_visible_member_ids
+ # The members the reader may see on the members page
+ # (MembershipPolicy::Scope, deactivated ones too), as user_id => active,
+ # once per request and also without view_people: a speaker who is one of
+ # them shows their name. Only an active one links to the people page,
+ # which lists active members only (People::Directory#member_entries), so
+ # the link never opens an empty lane.
+ def glossary_visible_members
+ @glossary_visible_members ||= policy_scope(Membership).where(organisation: current_organisation)
+ .pluck(:user_id, :active).to_h
+ end
+ helper_method :glossary_visible_members
end
end
diff --git a/app/helpers/glossary_helper.rb b/app/helpers/glossary_helper.rb
index 242dd93..621011e 100644
--- a/app/helpers/glossary_helper.rb
+++ b/app/helpers/glossary_helper.rb
@@ -3,11 +3,12 @@
# The glossary page (Organisations::GlossaryController): the wiring of its list
# and lane, the words of a term, and what the page shows of a heard form.
#
-# What a reader with view_glossary sees (E3): every term with its heard forms,
-# speakers and projects, also from projects they cannot read. Two things need
+# What a reader with view_glossary sees (E3): every term with its heard forms
+# and their projects, also from projects they cannot read. Three things need
# more: the title and the link of a meeting (read access to that meeting,
-# glossary_readable_meetings) and the link to a person (view_people and a row
-# the reader may see, glossary_speaker_url).
+# glossary_readable_meetings), the name of a speaker (someone the reader may
+# see on the members or the people page, glossary_speaker_visible?) and the
+# link to a speaker (view_people as well, glossary_speaker_url).
module GlossaryHelper
# The one thing a row opens in the lane.
SELECTION_PARAMS = %w[term_id].freeze
@@ -94,34 +95,51 @@ module GlossaryHelper
end
# The second line of a row: who spoke and in which projects, distinct, as
- # names only (links live in the lane).
+ # names only (links live in the lane). The speakers the reader may not see
+ # stand last, as one neutral word however many they are.
def glossary_row_origin(term)
corrections = term.term_corrections
- speakers = corrections.filter_map { |correction| glossary_speaker_name(correction) }.uniq
+ shown, hidden = corrections.select(&:speaker?).partition { |correction| glossary_speaker_visible?(correction) }
+ speakers = shown.map { |correction| glossary_speaker_name(correction) }.uniq
+ speakers << t('views.organisations.glossary.speaker_hidden') if hidden.any?
projects = corrections.filter_map { |correction| correction.project&.name }.uniq
- [speakers.to_sentence.presence, projects.join(', ').presence].compact.join(' · ')
+ [speakers.join(', ').presence, projects.join(', ').presence].compact.join(' · ')
end
- # The speaker of a heard form as a name: a member through the reader's name
- # display setting, a person of the directory as written there; nil without
+ # Whether the reader may see who spoke a heard form, the rule of the
+ # members and the people page: a member they may see on the members page
+ # (MembershipPolicy::Scope, deactivated ones too; a guest of one project
+ # sees no members of other projects), a row of the directory they may see
+ # on the people page (PersonPolicy::Scope, so only with view_people).
+ def glossary_speaker_visible?(correction)
+ if correction.user_id then glossary_visible_members.key?(correction.user_id)
+ elsif correction.person_id then glossary_visible_person_ids.include?(correction.person_id)
+ else false
+ end
+ end
+
+ # The speaker of a heard form as the reader may see them: a member through
+ # the reader's name display setting, a row of the directory as written
+ # there, any other speaker as a neutral word (speaker_hidden); nil without
# a speaker (none linked, or deleted).
def glossary_speaker_name(correction)
- if correction.user then viewer_display_name(correction.user)
- elsif correction.person then correction.person.name
- end
+ return unless correction.speaker?
+ return t('views.organisations.glossary.speaker_hidden') unless glossary_speaker_visible?(correction)
+
+ correction.user ? viewer_display_name(correction.user) : correction.person.name
end
# Where the name of a speaker links to on the people page, or nil: only
- # with view_people, and only for a row or a member the reader may see
- # there (PersonPolicy::Scope, MembershipPolicy::Scope), so the link never
- # opens an empty lane.
+ # with view_people, and only for someone that page lists to the reader (a
+ # visible row, a visible ACTIVE member), so the link never opens an empty
+ # lane.
def glossary_speaker_url(correction)
- return unless glossary_people_linkable?
+ return unless glossary_people_linkable? && glossary_speaker_visible?(correction)
- if correction.person_id && glossary_visible_person_ids.include?(correction.person_id)
+ if correction.user_id
+ organisation_people_path(current_organisation, member_id: correction.user_id) if glossary_visible_members[correction.user_id]
+ else
organisation_people_path(current_organisation, person_id: correction.person_id)
- elsif correction.user_id && glossary_visible_member_ids.include?(correction.user_id)
- organisation_people_path(current_organisation, member_id: correction.user_id)
end
end
diff --git a/app/models/CLAUDE.md b/app/models/CLAUDE.md
index f0548c6..22071ce 100644
--- a/app/models/CLAUDE.md
+++ b/app/models/CLAUDE.md
@@ -106,9 +106,11 @@ Verzeichnis-Layout nicht ablesbar — diese Karte gruppiert sie:
eindeutig nach `normalized_term`, Status `proposed`/`confirmed`/`rejected`), `term_correction`
(eine gehörte Form je Korrektur: Sprecher als Person ODER Mitglied, Check
`term_corrections_one_speaker`; Projekt als Herkunft; Stelle im Transkript), `glossary_text`
- (der EINE Normalisierer: NFC, Leerraum, klein, bewusst OHNE die Umlaut-Umschrift von
- `PersonName`). Verweise auf Zeilen einer Organisation stehen VOR `acts_as_tenant` und werden
- zusätzlich ohne Mandanten-Scope geprüft (`same_organisation_references`). Eigenes Recht
+ (der EINE Normalisierer: unsichtbare Zeichen raus, NFC, Leerraum, klein, bewusst OHNE die
+ Umlaut-Umschrift von `PersonName`). `glossary_term` hat `lock_version` wie `person`: ein
+ Formular über eine fremde Änderung hinweg wird abgelehnt (`:stale_object`). Verweise auf Zeilen
+ einer Organisation stehen VOR `acts_as_tenant` und werden zusätzlich ohne Mandanten-Scope
+ geprüft (`same_organisation_references`). Eigenes Recht
(`Permission::CATEGORIES[:glossary]`, `view_glossary`/`manage_glossary`, gastrollen-tauglich),
Kontoadmins ohne Zeile; `GlossaryPolicy` für beide Modelle (`policy_class`). Schreiben nur über
die Glossar-Actors. ⚠️ Ein gelöschtes Meeting lässt seine gehörten Formen samt Stelle stehen, nur
diff --git a/app/models/concerns/personal_data_erasure.rb b/app/models/concerns/personal_data_erasure.rb
index 87b0447..f1ff312 100644
--- a/app/models/concerns/personal_data_erasure.rb
+++ b/app/models/concerns/personal_data_erasure.rb
@@ -126,7 +126,10 @@ module PersonalDataErasure
# 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).
+ # the one-speaker check holds (person_id stays as it is, empty). A form
+ # spoken as the account's own directory row (exported with these) loses
+ # that link with the row: erase_person_links! deletes it, and the foreign
+ # key (on_delete: :nullify) clears person_id.
def erase_term_correction_speakers!
ActsAsTenant.without_tenant do
TermCorrection.where(user_id: id).update_all(user_id: nil, updated_at: Time.current)
diff --git a/app/models/glossary_text.rb b/app/models/glossary_text.rb
index 760006b..943f7de 100644
--- a/app/models/glossary_text.rb
+++ b/app/models/glossary_text.rb
@@ -1,18 +1,28 @@
# frozen_string_literal: true
# The ONE normalizer of the glossary (K4a): the form in which a term and a
-# heard form are compared. Unicode NFC, any whitespace (also a no-break
-# space) collapsed to one space and trimmed, lower case. Two terms that
-# differ only in this are one term per organisation (unique index on
-# glossary_terms.normalized_term).
+# heard form are compared. Characters that show nothing dropped, Unicode NFC,
+# any whitespace (also a no-break space) collapsed to one space and trimmed,
+# lower case. Two terms that differ only in this are one term per
+# organisation (unique index on glossary_terms.normalized_term).
#
# Deliberately NOT PersonName.normalize: that one also writes umlauts and ß
# out (ä -> ae, ß -> ss), which would make "Maße" and "Masse" one term.
module GlossaryText
- # The text as it is stored and shown: NFC, whitespace collapsed and trimmed,
- # case kept.
+ # What shows nothing: format characters (zero-width space and joiners, soft
+ # hyphen, bidi controls, byte order mark), what Unicode marks as ignorable
+ # in display (a Hangul filler, a variation selector), and control
+ # characters. Whitespace among them (tab, line break) is left to the
+ # whitespace rule and becomes a space. Dropped, not replaced: "Lala<zero-
+ # width space>base" looks like "Lalabase" and is that term. A term of
+ # nothing else is blank.
+ INVISIBLE = /[\p{Cf}\p{Default_Ignorable_Code_Point}\p{Cc}&&[^[:space:]]]/
+
+ # The text as it is stored and shown: invisible characters dropped (before
+ # NFC, so an umlaut split by one composes), whitespace collapsed and
+ # trimmed, case kept.
def self.clean(value)
- value.to_s.unicode_normalize(:nfc).gsub(/[[:space:]]+/, ' ').strip
+ value.to_s.gsub(INVISIBLE, '').unicode_normalize(:nfc).gsub(/[[:space:]]+/, ' ').strip
end
# The text as it is compared.
diff --git a/app/models/term_correction.rb b/app/models/term_correction.rb
index 843f6b9..0881878 100644
--- a/app/models/term_correction.rb
+++ b/app/models/term_correction.rb
@@ -58,6 +58,11 @@ class TermCorrection < ApplicationRecord
# Newest first within a heard form: the order of the lane.
scope :in_lane_order, -> { order(:normalized_heard, created_at: :desc, id: :asc) }
+ # Whether a speaker is linked at all (a member or a row of the directory).
+ def speaker?
+ user_id.present? || person_id.present?
+ end
+
private
def normalize_heard
diff --git a/app/policies/glossary_policy.rb b/app/policies/glossary_policy.rb
index 5355a04..0ff0c55 100644
--- a/app/policies/glossary_policy.rb
+++ b/app/policies/glossary_policy.rb
@@ -7,11 +7,15 @@
# confirm, reject, merge, delete) implies view_glossary
# (Permission::IMPLIED_BY). Grantable to billable: false roles.
#
-# view_glossary shows the WHOLE glossary with its heard forms, speakers and
-# projects, also from projects the reader may not read (E3). The title and the
-# link of a meeting are not part of that: they need read access to the
-# meeting (MeetingPolicy), and the link to a person needs view_people
-# (PersonPolicy). Both are asked where they are shown.
+# view_glossary shows the WHOLE glossary with its heard forms and their
+# projects, also from projects the reader may not read (E3). Three things are
+# not part of that and are asked where they are shown (GlossaryHelper): the
+# title and the link of a meeting (read access to the meeting,
+# MeetingPolicy); the name of a speaker (only someone the reader may see on
+# the members page, MembershipPolicy::Scope, or on the people page,
+# PersonPolicy::Scope, so a guest of one project sees no names from other
+# projects; anyone else shows as a neutral word); and the link to a speaker
+# (view_people as well, PersonPolicy).
#
# Every predicate asks for an ACTIVE membership itself:
# User#has_permission_in_organisation? reads the role and does not look at
diff --git a/app/services/CLAUDE.md b/app/services/CLAUDE.md
index a881962..43c019c 100644
--- a/app/services/CLAUDE.md
+++ b/app/services/CLAUDE.md
@@ -163,7 +163,8 @@ Verzeichnis-Übersicht (Auswahl):
Verbindung neu prüft und den Socket an die geprüfte Adresse bindet. Vertraut wird nur dem
Endpunkt, den eine `AiCredential` nennt (`Factory#operator_endpoint?`).
Glossar (K4a, 04.11.2026): `save_glossary_term` (anlegen/ändern, von Hand immer
- `confirmed`; eine verlorene Wette auf den Unique-Index ist dieselbe Ablehnung),
+ `confirmed`; eine verlorene Wette auf den Unique-Index ist dieselbe Ablehnung; `lock_version`
+ wie `save_person`, die Sperre allein lädt die Zeile neu und schützte nicht),
`set_glossary_term_status` (nur bestätigen/verwerfen, nie vorschlagen),
`destroy_glossary_term`, `destroy_heard_form` (eine gehörte Form mit ALLEN ihren
Korrekturen am Begriff), `merge_glossary_terms` (sperrt beide Zeilen in EINER Abfrage nach
diff --git a/app/services/actors/base_actor.rb b/app/services/actors/base_actor.rb
index 60d3115..de2903e 100644
--- a/app/services/actors/base_actor.rb
+++ b/app/services/actors/base_actor.rb
@@ -125,7 +125,7 @@ module Actors
# Optimistic locking (lock_version): another write landed between read and
# save. Return a specific, usable message instead of a generic crash/500
# (mirrors the RecordInvalid path). Only models with a lock_version column
- # raise this; today that is Note (wiki versioning), other actors are unaffected.
+ # raise this; actors of other models are unaffected.
failure([I18n.t('services.actors.stale_object')], code: :stale_object)
rescue StandardError => e
handle_unexpected_error(e, reraise: raise_unexpected?)
diff --git a/app/services/actors/save_glossary_term.rb b/app/services/actors/save_glossary_term.rb
index c5dca19..1ecb1a0 100644
--- a/app/services/actors/save_glossary_term.rb
+++ b/app/services/actors/save_glossary_term.rb
@@ -13,9 +13,17 @@
# * The id is looked up inside the organisation: an id of another one is no
# term at all. A saved term is locked before it changes (Glossary::TermLock),
# so one deleted or merged away in the meantime is refused as gone.
+# * A stale save (lock_version, as Actors::SavePerson): the form sends the
+# lock_version it was opened with. The lock reloads the row, so without it
+# the form's old values would write over a change made in the meantime.
+# Assigned to the row, it makes the save raise StaleObjectError, which
+# BaseActor maps to code :stale_object; the controller shows the form again
+# with the current values. A request without the key is not checked.
module Actors
class SaveGlossaryTerm < BaseActor
- ATTRIBUTES = %i[term category].freeze
+ ATTRIBUTES = %i[term category lock_version].freeze
+ # lock_version is an integer column (4 bytes).
+ LOCK_VERSION_RANGE = (0..((2**31) - 1))
def initialize(organisation:, params:, current_user:, id: nil)
super()
@@ -32,8 +40,11 @@ module Actors
def perform
raise ActorError.new(I18n.t('controllers.glossary.not_found'), code: :not_found) if @term.nil?
+ check_lock_version
Glossary::TermLock.call(term: @term) if @term.persisted?
- @term.assign_attributes(@params.slice(*ATTRIBUTES))
+ attributes = @params.slice(*ATTRIBUTES)
+ attributes.delete(:lock_version) if @term.new_record?
+ @term.assign_attributes(attributes)
if @term.new_record?
@term.status = 'confirmed'
@term.created_by = @current_user
@@ -45,6 +56,16 @@ module Actors
attr_reader :current_user
+ # On an update, a lock_version that is not a number the column can hold (a
+ # hand-made request) cannot say what the writer saw; Rails would raise on
+ # it. Treated as stale. A new term has none to compare.
+ def check_lock_version
+ return if @term.new_record? || [email protected]?(:lock_version)
+ return if LOCK_VERSION_RANGE.cover?(Integer(@params[:lock_version].to_s, exception: false))
+
+ raise ActorError.new(I18n.t('controllers.glossary.update.stale'), code: :stale_object)
+ end
+
def save_term
@term.save!
rescue ActiveRecord::RecordNotUnique
diff --git a/app/services/user_data_exports/registry.rb b/app/services/user_data_exports/registry.rb
index f27affa..971c39a 100644
--- a/app/services/user_data_exports/registry.rb
+++ b/app/services/user_data_exports/registry.rb
@@ -225,17 +225,23 @@ 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.
+ # The heard forms of the glossary this account SPOKE (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 speaker is
+ # the account in two ways: as a member (user_id), or as the account's
+ # own row of the people directory (person_id of a Person with this
+ # user_id; :people exports that row, not the forms spoken as it). The
+ # third reference is not exported: corrected_by_id is authoring metadata
+ # on org knowledge (as analysis_prompts). A person_id of any other row is
+ # a third party's, whose requests go through the organisation.
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) }),
+ scope: lambda { |user|
+ TermCorrection.where(user_id: user.id)
+ .or(TermCorrection.where(person_id: Person.where(user_id: user.id).select(: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) }),
diff --git a/app/views/organisations/glossary/_correction.html.erb b/app/views/organisations/glossary/_correction.html.erb
index 8f38aec..776f9bd 100644
--- a/app/views/organisations/glossary/_correction.html.erb
+++ b/app/views/organisations/glossary/_correction.html.erb
@@ -1,20 +1,21 @@
<%# locals: (correction:, meetings:) %>
-<%# One correction of a heard form: who spoke (a name, a link only with
- view_people), the project it came from (a name for every reader of the
- glossary), the meeting (title and link only when the reader may read it,
- meetings holds those), the date and how often it was replaced. Deleting
- is the whole heard form's (_detail). %>
+<%# One correction of a heard form: who spoke (a name only when the reader
+ may see the speaker, else a neutral word; a link only with view_people),
+ the project it came from (a name for every reader of the glossary), the
+ meeting (title and link only when the reader may read it, meetings holds
+ those), the date and how often it was replaced. Deleting is the whole
+ heard form's (_detail). %>
<% speaker = glossary_speaker_name(correction) %>
-<% speaker_url = glossary_speaker_url(correction) if speaker %>
+<% speaker_url = glossary_speaker_url(correction) %>
<% meeting_title = meetings[correction.meeting_id] %>
<li class="glossary-heard__row">
<span class="glossary-heard__speaker">
<% if speaker_url %>
<%= link_to speaker, speaker_url, class: 'people-fields__link', data: { turbo_frame: '_top' } %>
- <% elsif speaker %>
+ <% elsif glossary_speaker_visible?(correction) %>
<%= speaker %>
<% else %>
- <span class="text-muted"><%= t('views.organisations.glossary.show.no_speaker') %></span>
+ <span class="text-muted"><%= speaker || t('views.organisations.glossary.show.no_speaker') %></span>
<% end %>
</span>
<span class="glossary-heard__origin">
diff --git a/app/views/organisations/glossary/_detail.html.erb b/app/views/organisations/glossary/_detail.html.erb
index 8bd111e..2ffbdbf 100644
--- a/app/views/organisations/glossary/_detail.html.erb
+++ b/app/views/organisations/glossary/_detail.html.erb
@@ -1,10 +1,12 @@
<%# locals: (term:) %>
<%# One term: its spelling with category and status, confirm and reject, the
heard forms with speaker, project, meeting and date, merging into another
- term, and delete. Speakers and projects stand for every reader of the
- glossary (E3); a meeting's title and link only for a reader of that
- meeting (glossary_readable_meetings), a speaker's link only with
- view_people (glossary_speaker_url). The body ends at reading width. %>
+ term, and delete. Projects stand for every reader of the glossary (E3);
+ a meeting's title and link only for a reader of that meeting
+ (glossary_readable_meetings), a speaker's name only for a reader who may
+ see the speaker (glossary_speaker_visible?), its link only with
+ view_people as well (glossary_speaker_url). The body ends at reading
+ width. %>
<% can_write = policy(term).update? %>
<% corrections = term.term_corrections.includes(:project, :person, :user).in_lane_order.to_a %>
<% meetings = glossary_readable_meetings(corrections) %>
diff --git a/app/views/organisations/glossary/_form.html.erb b/app/views/organisations/glossary/_form.html.erb
index 63475b9..12c342f 100644
--- a/app/views/organisations/glossary/_form.html.erb
+++ b/app/views/organisations/glossary/_form.html.erb
@@ -2,7 +2,9 @@
<%# The form in the lane, new and edit: the spelling and the category. It
leaves the frame (_top): a save lands on the list with the term open, a
refused save (a spelling already in the glossary) renders the page again
- with this form and its reason. The filters ride in hidden fields. %>
+ with this form and its reason. lock_version travels along, so a save over
+ someone else's change is refused instead of writing the old values back.
+ The filters ride in hidden fields. %>
<% url = term.persisted? ? organisation_glossary_term_path(@current_organisation, term) : organisation_glossary_terms_path(@current_organisation) %>
<% title = term.persisted? ? t('views.organisations.glossary.form.edit_title', term: term.term_in_database) : t('views.organisations.glossary.form.new_title') %>
<% cancel_url = term.persisted? ? organisation_glossary_term_path(@current_organisation, term, list_state) : organisation_glossary_terms_path(@current_organisation, list_state) %>
@@ -23,6 +25,9 @@
<% list_state.each do |name, value| %>
<%= hidden_field_tag name, value, id: nil %>
<% end %>
+ <% if term.persisted? %>
+ <%= f.hidden_field :lock_version %>
+ <% end %>
<div class="people-form__field">
<%= f.label :term do %>
diff --git a/app/views/organisations/glossary/_row.html.erb b/app/views/organisations/glossary/_row.html.erb
index a6afc12..8e9dabc 100644
--- a/app/views/organisations/glossary/_row.html.erb
+++ b/app/views/organisations/glossary/_row.html.erb
@@ -13,7 +13,8 @@
<% count = term.term_corrections.size %>
<%# Class names written out: Tailwind keeps only component classes it finds whole in a template. %>
<%= tag.li data: row_data, tabindex: 0, class: ['people-row glossary-row', ('glossary-row--rejected' if term.rejected?), ('selected-row' if open)].compact.join(' ') do %>
- <span class="people-row__text">
+ <%# A div, not a span: it holds the status actions, a div with forms. %>
+ <div class="people-row__text">
<span class="glossary-row__head">
<span class="people-row__name"><%= term.term %></span>
<% if term.category %>
@@ -33,7 +34,7 @@
<% if term.proposed? && policy(term).confirm? %>
<%= render 'organisations/glossary/status_actions', term: term, lane: false %>
<% end %>
- </span>
+ </div>
<span class="glossary-row__count" title="<%= t('views.organisations.glossary.index.corrections_count', count: count) %>">
<%= count %><span class="sr-only"> <%= t('views.organisations.glossary.index.corrections_count', count: count) %></span>
</span>
diff --git a/app/views/organisations/glossary/_status_actions.html.erb b/app/views/organisations/glossary/_status_actions.html.erb
index 0ce2b78..8307416 100644
--- a/app/views/organisations/glossary/_status_actions.html.erb
+++ b/app/views/organisations/glossary/_status_actions.html.erb
@@ -1,7 +1,9 @@
<%# locals: (term:, lane:) %>
<%# Confirm and reject (E5): "Bestätigen" unless confirmed, "Verwerfen"
unless rejected. From the lane the term stays open (term_id sent along),
- from the list the list stays as it was. %>
+ from the list the list stays as it was. Each button names its term for a
+ screen reader: in the list, several stand one below the other. %>
+<% term_name = t('views.organisations.glossary.quoted', text: term.term) %>
<% params_kept = list_state.merge(lane ? { 'term_id' => term.id } : {}) %>
<%# Class names written out: Tailwind keeps only component classes it finds whole in a template. %>
<div class="<%= lane ? 'glossary-status-actions glossary-status-actions--lane' : 'glossary-status-actions' %>">
@@ -11,7 +13,7 @@
form: { action: confirm_organisation_glossary_term_path(@current_organisation, term), method: :patch,
params: params_kept, data: { turbo_frame: '_top' } }
) do %>
- <%= t('views.organisations.glossary.show.confirm') %>
+ <%= t('views.organisations.glossary.show.confirm') %><span class="sr-only"> <%= term_name %></span>
<% end %>
<% end %>
<% unless term.rejected? %>
@@ -20,7 +22,7 @@
form: { action: reject_organisation_glossary_term_path(@current_organisation, term), method: :patch,
params: params_kept, data: { turbo_frame: '_top' } }
) do %>
- <%= t('views.organisations.glossary.show.reject') %>
+ <%= t('views.organisations.glossary.show.reject') %><span class="sr-only"> <%= term_name %></span>
<% end %>
<% end %>
</div>
diff --git a/config/locales/views/glossar.de.yml b/config/locales/views/glossar.de.yml
index ee1a7bf..318b042 100644
--- a/config/locales/views/glossar.de.yml
+++ b/config/locales/views/glossar.de.yml
@@ -7,6 +7,7 @@ de:
success: "Begriff angelegt."
update:
success: "Begriff gespeichert."
+ stale: "Jemand anderes hat diesen Begriff inzwischen geändert. Unten stehen die aktuellen Angaben, bitte noch einmal ändern."
destroy:
success: "Begriff gelöscht."
confirm:
@@ -28,6 +29,8 @@ de:
organisations:
glossary:
quoted: "„%{text}“"
+ # A speaker the reader may not see (GlossaryHelper#glossary_speaker_name).
+ speaker_hidden: "Name nicht sichtbar"
categories:
person: "Person"
company: "Firma"
diff --git a/config/locales/views/glossar.en.yml b/config/locales/views/glossar.en.yml
index d0972d4..04323c5 100644
--- a/config/locales/views/glossar.en.yml
+++ b/config/locales/views/glossar.en.yml
@@ -7,6 +7,7 @@ en:
success: "Term created."
update:
success: "Term saved."
+ stale: "Someone else changed this term in the meantime. The current details are shown below, please make your change again."
destroy:
success: "Term deleted."
confirm:
@@ -28,6 +29,8 @@ en:
organisations:
glossary:
quoted: "“%{text}”"
+ # A speaker the reader may not see (GlossaryHelper#glossary_speaker_name).
+ speaker_hidden: "Name not visible"
categories:
person: "Person"
company: "Company"
diff --git a/db/migrate/20261104100000_create_glossary_terms.rb b/db/migrate/20261104100000_create_glossary_terms.rb
index d33b689..b9ab9e6 100644
--- a/db/migrate/20261104100000_create_glossary_terms.rb
+++ b/db/migrate/20261104100000_create_glossary_terms.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
# The glossary of an organisation (K4a): one row per term in its right
-# spelling. normalized_term (lower case, NFC, whitespace collapsed,
-# GlossaryText) is unique per organisation, so one spelling cannot stand
-# twice. status: proposed, confirmed, rejected; a rejected term stays, so it
-# is not proposed again.
+# spelling. normalized_term (characters that show nothing dropped, NFC,
+# whitespace collapsed, lower case: GlossaryText) is unique per organisation,
+# so one spelling cannot stand twice. status: proposed, confirmed, rejected; a
+# rejected term stays, so it is not proposed again.
class CreateGlossaryTerms < ActiveRecord::Migration[8.1]
def change
create_table :glossary_terms, id: :uuid do |t|
diff --git a/db/migrate/20261104100200_add_lock_version_to_glossary_terms.rb b/db/migrate/20261104100200_add_lock_version_to_glossary_terms.rb
new file mode 100644
index 0000000..9cef6f2
--- /dev/null
+++ b/db/migrate/20261104100200_add_lock_version_to_glossary_terms.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+# Optimistic locking for a glossary term (review round 4 of #113): the form
+# sends the lock_version it was opened with, so a save over someone else's
+# change in the meantime is refused instead of writing the old spelling or
+# category back (Actors::SaveGlossaryTerm, as Actors::SavePerson).
+class AddLockVersionToGlossaryTerms < ActiveRecord::Migration[8.1]
+ def change
+ add_column :glossary_terms, :lock_version, :integer, default: 0, null: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 658786e..8b11d34 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_100100) do
+ActiveRecord::Schema[8.1].define(version: 2026_11_04_100200) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pgcrypto"
@@ -725,6 +725,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_04_100100) do
t.uuid "created_by_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.integer "lock_version", default: 0, null: false
t.index ["created_by_id"], name: "index_glossary_terms_on_created_by_id"
t.index ["organisation_id", "normalized_term"], name: "index_glossary_terms_on_organisation_id_and_normalized_term", unique: true
end
diff --git a/spec/models/glossary_term_spec.rb b/spec/models/glossary_term_spec.rb
index a18dce7..0922082 100644
--- a/spec/models/glossary_term_spec.rb
+++ b/spec/models/glossary_term_spec.rb
@@ -55,6 +55,61 @@ RSpec.describe GlossaryTerm, :ci_guard, type: :model do
expect(build(:glossary_term, organisation: organisation, term: 'Mueller')).to be_valid
expect(described_class.last.normalized_term).to eq('maße')
end
+
+ it 'compares an umlaut by its case only: "MÜLLER" is "Müller", "Mueller" is another term' do
+ create(:glossary_term, organisation: organisation, term: 'Müller')
+ upper = build(:glossary_term, organisation: organisation, term: 'MÜLLER')
+
+ expect(upper).not_to be_valid
+ expect(upper.errors.details[:term]).to include(error: :taken)
+ expect(build(:glossary_term, organisation: organisation, term: 'Mueller')).to be_valid
+ end
+
+ # Review round 4 of #113: a character that shows nothing made a term of
+ # nothing, or a second term that looks like the first.
+ describe 'characters that show nothing' do
+ it 'refuses a term of nothing else' do
+ term = build(:glossary_term, organisation: organisation, term: "\u{200B}\u{00AD} \u{2060}\u{FEFF}\u{3164}")
+
+ expect(term).not_to be_valid
+ expect(term.errors.details[:term]).to include(error: :blank)
+ end
+
+ {
+ 'a zero-width space' => "Lala\u{200B}base",
+ 'a soft hyphen' => "Lala\u{00AD}base",
+ 'bidi controls' => "\u{202E}Lala\u{200F}base\u{202C}",
+ 'a Hangul filler (shows as a blank)' => "Lala\u{3164}base",
+ 'a control character' => "Lala\u{0007}base"
+ }.each do |what, spelling|
+ it "drops #{what}, so the term collides with the plain spelling" do
+ create(:glossary_term, organisation: organisation, term: 'Lalabase')
+ twin = build(:glossary_term, organisation: organisation, term: spelling)
+
+ expect(twin).not_to be_valid
+ expect(twin.errors.details[:term]).to include(error: :taken)
+ expect([twin.term, twin.normalized_term]).to eq(%w[Lalabase lalabase])
+ end
+ end
+
+ it 'stores a term with a null character without it (the database refuses one)' do
+ term = create(:glossary_term, organisation: organisation, term: "Lala\u{0000}base")
+
+ expect(term.reload.term).to eq('Lalabase')
+ end
+
+ it 'keeps a tab or a line break as a space' do
+ expect(create(:glossary_term, organisation: organisation, term: "Lala\tBase\r\nWerk").term).to eq('Lala Base Werk')
+ end
+
+ it 'composes an umlaut across a dropped character' do
+ create(:glossary_term, organisation: organisation, term: "M\u{00FC}hlstein")
+ twin = build(:glossary_term, organisation: organisation, term: "Mu\u{200B}\u{0308}hlstein")
+
+ expect(twin).not_to be_valid
+ expect(twin.normalized_term).to eq("m\u{00FC}hlstein")
+ end
+ end
end
describe 'one spelling per organisation' do
diff --git a/spec/models/term_correction_spec.rb b/spec/models/term_correction_spec.rb
index d894fc4..e543ab3 100644
--- a/spec/models/term_correction_spec.rb
+++ b/spec/models/term_correction_spec.rb
@@ -43,6 +43,17 @@ RSpec.describe TermCorrection, :ci_guard, type: :model do
expect(correction.errors[:heard]).to be_present
end
+ # Review round 4 of #113: the heard form goes through the same normalizer as
+ # the term (GlossaryText), characters that show nothing included.
+ it 'drops characters that show nothing from a heard form, and refuses one of nothing else' do
+ correction = create(:term_correction, organisation: organisation, glossary_term: term, heard: "Lala\u{200B}\u{00AD}Bass")
+ blank = build(:term_correction, organisation: organisation, glossary_term: term, heard: "\u{200B}\u{202E}")
+
+ expect([correction.heard, correction.normalized_heard]).to eq(%w[LalaBass lalabass])
+ expect(blank).not_to be_valid
+ expect(blank.errors.details[:heard]).to include(error: :blank)
+ end
+
it 'checks the place and the count' do
expect(build(:term_correction, organisation: organisation, glossary_term: term, replaced_count: 0)).not_to be_valid
expect(build(:term_correction, organisation: organisation, glossary_term: term, line_index: -1)).not_to be_valid
diff --git a/spec/models/user_erasure_path_parity_spec.rb b/spec/models/user_erasure_path_parity_spec.rb
index ac77fad..82a0af2 100644
--- a/spec/models/user_erasure_path_parity_spec.rb
+++ b/spec/models/user_erasure_path_parity_spec.rb
@@ -268,6 +268,21 @@ RSpec.describe 'Account erasure path parity', type: :model do
expect(TermCorrection.find(by_colleague.id).user_id).to eq(colleague.id)
end
end
+
+ # Review round 4 of #113: the export counts a form spoken as the
+ # account's own directory row as the account's. Erasure deletes that row
+ # (erase_person_links!), and the foreign key clears the link.
+ it "clears the speaker of a heard form spoken as the account's own directory row" do
+ term = create(:glossary_term, organisation: organisation)
+ own_row = create(:person, organisation: organisation, user: user)
+ spoken = create(:term_correction, organisation: organisation, glossary_term: term, person: own_row)
+
+ record.soft_delete_and_anonymize!
+
+ ActsAsTenant.without_tenant do
+ expect(TermCorrection.where(id: spoken.id).pluck(:person_id, :user_id)).to eq([[nil, nil]])
+ end
+ end
end
describe 'personal access tokens (access revocation)' do
diff --git a/spec/requests/organisations/glossary_spec.rb b/spec/requests/organisations/glossary_spec.rb
index 8ff201a..4fc174e 100644
--- a/spec/requests/organisations/glossary_spec.rb
+++ b/spec/requests/organisations/glossary_spec.rb
@@ -6,9 +6,10 @@ require 'rails_helper'
# (GlossaryPolicy, E2): 403 without it, view_glossary reads but never writes,
# manage_glossary writes (a guest role too), an account admin needs no row,
# and a term of another organisation answers 404. What a reader sees (E3):
-# heard forms with speaker and project from every project, but a meeting's
-# title only with read access to that meeting, and a link to a person only
-# with view_people. Invented words and names only.
+# heard forms with their project from every project, but a meeting's title
+# only with read access to that meeting, a speaker's name only when the
+# reader may see that speaker on the members or the people page, and a link
+# to a speaker only with view_people as well. Invented words and names only.
RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
let(:organisation) { create(:organisation) }
let(:other_organisation) { create(:organisation) }
@@ -147,7 +148,11 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
expect(response).to have_http_status(:ok)
body = response.body
expect(body).to include('Lalabase', I18n.t('views.organisations.glossary.categories.product'))
- expect(body).to include('lala bass', 'la la base', 'Erika Beispiel')
+ expect(body).to include('lala bass', 'la la base')
+ # A row of the people directory is a name only with view_people (review
+ # round 4 of #113).
+ expect(body).to include(I18n.t('views.organisations.glossary.speaker_hidden'))
+ expect(body).not_to include('Erika Beispiel')
# E3: the project's name also where the reader cannot read the project.
expect(body).to include('Projekt Ahorn', 'Projekt Birke')
expect(body.index('Zirbelholz')).to be < body.index('Lalabase')
@@ -291,10 +296,20 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
Nokogiri::HTML(response.body)
end
- it 'names the speaker without a link for a reader without view_people' do
+ def speakers(page)
+ page.css('.glossary-heard__speaker').map { |node| node.text.strip }
+ end
+
+ let(:hidden) { I18n.t('views.organisations.glossary.speaker_hidden') }
+
+ # Review round 4 of #113 (decided): a speaker's name follows what the
+ # reader may see on the people page; without view_people that page shows
+ # no row of the directory.
+ it 'shows a row of the directory as a neutral word to a reader without view_people' do
page = lane_for(viewer)
- expect(page.text).to include('Erika Beispiel')
+ expect(speakers(page)).to include(hidden)
+ expect(page.text).not_to include('Erika Beispiel')
expect(page.css(%(a[href*="person_id=#{speaker.id}"]))).to be_empty
end
@@ -317,30 +332,68 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
page = lane_for(viewer)
- expect(page.css('.glossary-heard__speaker').map { |node| node.text.strip }).to include(speaker_member.display_name)
+ expect(speakers(page)).to include(speaker_member.display_name)
expect(page.css(%(a[href*="member_id=#{speaker_member.id}"]))).to be_empty
end
+ # Review round 4 of #113 (decided): MembershipPolicy::Scope keeps the
+ # names of other projects' members from a guest of one project, so the
+ # glossary does too, in the lane and in the list.
+ describe 'a guest of one project (billable: false) with view_glossary' do
+ let(:guest) { member_with(role_with('view_glossary', billable: false)) }
+ let(:colleague) { member_with(role_with) }
+ let(:stranger) { member_with(role_with) }
+
+ before do
+ create(:project_permission, user: guest, project: open_project, tickets_access: :read_only)
+ create(:project_permission, user: colleague, project: open_project, tickets_access: :read_only)
+ create(:project_permission, user: stranger, project: closed_project, tickets_access: :read_only)
+ create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lalabeis', user: colleague,
+ project: open_project)
+ create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lalabais', user: stranger,
+ project: closed_project)
+ end
+
+ it 'sees the name of a member of its project, not of a member of another project' do
+ page = lane_for(guest)
+
+ expect(speakers(page)).to include(colleague.display_name, hidden)
+ expect(page.text).not_to include(stranger.display_name)
+ expect(page.css('.glossary-heard__speaker a')).to be_empty
+ end
+
+ it 'sees the same names in the list' do
+ sign_in guest
+ get organisation_glossary_terms_path(organisation)
+
+ origin = Nokogiri::HTML(response.body).css('.glossary-row__origin').map(&:text).join
+ expect(origin).to include(colleague.display_name, hidden, 'Projekt Birke')
+ expect(origin).not_to include(stranger.display_name)
+ end
+ end
+
describe 'with view_people but without any project' do
let(:reader) { member_with(role_with('view_glossary', 'people:view_people')) }
let(:hidden_member) { member_with(role_with) }
- it 'names a member it may not see on the people page, without a link' do
+ it 'shows a member it may not see on the members page as a neutral word, without a link' do
create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lalabeis', user: hidden_member)
page = lane_for(reader)
- expect(page.css('.glossary-heard__speaker').map { |node| node.text.strip }).to include(hidden_member.display_name)
+ expect(speakers(page)).to include(hidden)
+ expect(page.text).not_to include(hidden_member.display_name)
expect(page.css(%(a[href*="member_id=#{hidden_member.id}"]))).to be_empty
end
- it 'names the row of a member it may not see, without a link' do
+ it 'shows the row of a member it may not see as a neutral word, without a link' do
row = create(:person, organisation: organisation, user: hidden_member, name: 'Paula Platzhalter')
create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lalabeis', person: row)
page = lane_for(reader)
- expect(page.text).to include('Paula Platzhalter')
+ expect(speakers(page)).to include(hidden)
+ expect(page.text).not_to include('Paula Platzhalter')
expect(page.css(%(a[href*="person_id=#{row.id}"]))).to be_empty
end
@@ -363,6 +416,19 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
expect(page.css(%(a[href="#{organisation_people_path(organisation, member_id: member.id)}"]))).to be_present
end
+
+ # Review round 4 of #113: the people page lists active members only, so a
+ # link to a deactivated one opened an empty lane. The members page still
+ # lists them, so the name stays.
+ it 'names a deactivated member without a link' do
+ member = member_with(role_with, active: false)
+ create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lalabeis', user: member)
+
+ page = lane_for(admin)
+
+ expect(speakers(page)).to include(member.display_name)
+ expect(page.css(%(a[href*="member_id=#{member.id}"]))).to be_empty
+ end
end
describe 'filters' do
@@ -545,6 +611,19 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
merge_organisation_glossary_term_path(organisation, term),
heard_form_organisation_glossary_term_path(organisation, term, correction_id: open_correction.id))
end
+
+ # Review round 4 of #113 (optional): a screen reader heard "Bestätigen"
+ # once per proposal without its term, and the row held a div in a span.
+ it 'names the term in the buttons of a proposal row, inside valid markup' do
+ get organisation_glossary_terms_path(organisation)
+
+ page = Nokogiri::HTML(response.body)
+ row = page.css('[data-glossary-row]').find { |node| node.text.include?('Zirbelholz') }
+ expect(row.css('button').map { |button| button.text.squish })
+ .to eq([I18n.t('views.organisations.glossary.show.confirm'), I18n.t('views.organisations.glossary.show.reject')]
+ .map { |word| "#{word} #{I18n.t('views.organisations.glossary.quoted', text: 'Zirbelholz')}" })
+ expect(page.css('[data-glossary-row] span div, [data-glossary-row] span form')).to be_empty
+ end
end
describe 'with manage_glossary' do
@@ -553,6 +632,40 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
before { sign_in writer }
include_examples 'may keep the glossary'
+
+ # Review round 4 of #113: a form opened before another change wrote the
+ # old spelling back.
+ it 'shows the current values and the stale message when someone else saved first' do
+ opened_with = term.lock_version
+ term.update!(term: 'Lala Base')
+
+ patch organisation_glossary_term_path(organisation, term),
+ params: { glossary_term: { term: 'Lalabase', category: 'company', lock_version: opened_with } }
+
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(response.body).to include(CGI.escapeHTML(I18n.t('controllers.glossary.update.stale')))
+ form = Nokogiri::HTML(response.body)
+ expect(form.css('#glossary_term_term').first['value']).to eq('Lala Base')
+ expect(form.css('input[name="glossary_term[lock_version]"]').first['value']).to eq(term.reload.lock_version.to_s)
+ expect([term.term, term.category]).to eq(['Lala Base', 'product'])
+ end
+
+ it 'sends the lock_version along with the form of a saved term, none with a new one' do
+ get edit_organisation_glossary_term_path(organisation, term), headers: frame_headers
+ expect(Nokogiri::HTML(response.body).css('input[name="glossary_term[lock_version]"]').map { |input| input['value'] })
+ .to eq([term.lock_version.to_s])
+
+ get new_organisation_glossary_term_path(organisation), headers: frame_headers
+ expect(response.body).not_to include('glossary_term[lock_version]')
+ end
+
+ # Review round 4 of #113 (optional): require.permit crashed on a string.
+ it 'answers a form that is no form with 400, not an error' do
+ patch organisation_glossary_term_path(organisation, term), params: { glossary_term: 'Lalabase' }
+
+ expect(response).to have_http_status(:bad_request)
+ expect(term.reload.term).to eq('Lalabase')
+ end
end
describe 'with manage_glossary on a guest role (billable: false)' do
diff --git a/spec/services/actors/merge_glossary_terms_spec.rb b/spec/services/actors/merge_glossary_terms_spec.rb
index 1d89a60..d00cb4e 100644
--- a/spec/services/actors/merge_glossary_terms_spec.rb
+++ b/spec/services/actors/merge_glossary_terms_spec.rb
@@ -81,6 +81,19 @@ RSpec.describe Actors::MergeGlossaryTerms, :ci_guard, type: :service do
expect(source.reload.term_corrections.count).to eq(1)
end
+ # Review round 4 of #113 (optional): the other half of lock_both's check.
+ it 'refuses a source deleted in the meantime, and the target keeps its heard forms' do
+ kept = create(:term_correction, organisation: organisation, glossary_term: target)
+ gone = source
+ GlossaryTerm.where(id: gone.id).delete_all
+
+ result = merge(gone, target)
+
+ expect(result).not_to be_success
+ expect(result.code).to eq(:not_found)
+ expect(target.reload.term_corrections).to contain_exactly(kept)
+ end
+
# The one lock order of the glossary (Glossary::TermLock): rows in the order
# of their ids, in one statement, before any heard form moves.
it 'locks both terms in one statement ordered by id, before it moves anything' do
diff --git a/spec/services/actors/save_glossary_term_spec.rb b/spec/services/actors/save_glossary_term_spec.rb
index c0dcf57..506302f 100644
--- a/spec/services/actors/save_glossary_term_spec.rb
+++ b/spec/services/actors/save_glossary_term_spec.rb
@@ -3,7 +3,7 @@
require 'rails_helper'
# Creating and changing a glossary term by hand (K4a). Invented words only.
-RSpec.describe Actors::SaveGlossaryTerm, type: :service do
+RSpec.describe Actors::SaveGlossaryTerm, :ci_guard, type: :service do
let(:organisation) { create(:organisation) }
let(:other_organisation) { create(:organisation) }
let(:writer) { create(:user) }
@@ -96,6 +96,44 @@ RSpec.describe Actors::SaveGlossaryTerm, type: :service do
expect(result.errors).to eq([I18n.t('controllers.glossary.not_found')])
end
+ # Review round 4 of #113: the lock reloaded the row and the form's old values
+ # wrote over the newer change.
+ describe 'a stale save (lock_version)' do
+ let!(:term) { create(:glossary_term, organisation: organisation, term: 'Lalabse', category: 'product') }
+
+ it 'refuses a save from a form opened before another change, and keeps that change' do
+ opened_with = term.lock_version
+ save({ term: 'Lalabase', lock_version: opened_with }, id: term.id)
+
+ result = save({ term: 'Lalabse', category: 'company', lock_version: opened_with }, id: term.id)
+
+ expect(result).not_to be_success
+ expect(result.code).to eq(:stale_object)
+ expect(term.reload.slice(:term, :category)).to eq('term' => 'Lalabase', 'category' => 'product')
+ end
+
+ it 'saves with the lock_version the term has now, and counts it up' do
+ result = save({ category: 'company', lock_version: term.lock_version }, id: term.id)
+
+ expect(result).to be_success
+ expect(term.reload.lock_version).to eq(1)
+ end
+
+ ['', 'drei', '-1', (2**31).to_s].each do |sent|
+ it "answers the lock_version #{sent.inspect} as stale, a number the column cannot hold" do
+ expect(save({ term: 'Neu', lock_version: sent }, id: term.id).code).to eq(:stale_object)
+ expect(term.reload.term).to eq('Lalabse')
+ end
+ end
+
+ it 'takes no lock_version for a new term' do
+ result = save({ term: 'Wortmarke', lock_version: '7' })
+
+ expect(result).to be_success
+ expect(result.resource.reload.lock_version).to eq(0)
+ end
+ end
+
it 'finds no term of another organisation' do
foreign = ActsAsTenant.with_tenant(other_organisation) { create(:glossary_term, organisation: other_organisation, term: 'Fremd') }
diff --git a/spec/services/user_data_exports/builder_spec.rb b/spec/services/user_data_exports/builder_spec.rb
index f73a3c5..a6a4b89 100644
--- a/spec/services/user_data_exports/builder_spec.rb
+++ b/spec/services/user_data_exports/builder_spec.rb
@@ -107,6 +107,24 @@ RSpec.describe UserDataExports::Builder,
expect(org_folders.join).not_to include('fremd')
end
+ # Review round 4 of #113: a heard form spoken as the account's own row of
+ # the people directory is data about the account as well.
+ it 'exports the heard forms the account spoke, as member and as its own directory row' do
+ ActsAsTenant.with_tenant(org_a) do
+ term = create(:glossary_term, organisation: org_a, term: 'Lalabase')
+ own_row = create(:person, organisation: org_a, user: user, name: 'Eigene Zeile')
+ other_row = create(:person, organisation: org_a, name: 'Fremde Zeile')
+ create(:term_correction, organisation: org_a, glossary_term: term, heard: 'als mitglied', user: user)
+ create(:term_correction, organisation: org_a, glossary_term: term, heard: 'als eigene zeile', person: own_row)
+ create(:term_correction, organisation: org_a, glossary_term: term, heard: 'als fremde zeile', person: other_row)
+ create(:term_correction, organisation: org_a, glossary_term: term, heard: 'als anderes mitglied', user: other_user)
+ end
+
+ rows = JSON.parse(files["organisations/#{expected_folder(org_a)}/term_corrections.json"])
+ expect(rows.map { |row| row['heard'] }).to contain_exactly('als mitglied', 'als eigene zeile')
+ expect(rows.map { |row| row['term'] }.uniq).to eq(['Lalabase'])
+ end
+
it 'writes empty sources as [] — deterministic structure' do
folder = org_folders.first
expect(files["organisations/#{folder}/posts.json"].strip).to eq('[]')