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): show open heard forms and confirm or reject them

Guido Boyke402fbc748544
diff --git a/app/controllers/organisations/glossary_controller.rb b/app/controllers/organisations/glossary_controller.rb
index c2ef017..dfbb60b 100644
--- a/app/controllers/organisations/glossary_controller.rb
+++ b/app/controllers/organisations/glossary_controller.rb
@@ -11,7 +11,9 @@
# state. The index answers a lane frame request with the lane alone.
#
# Writes go through the glossary actors and leave the frame (_top): they land
-# on the list again, with the term open where one is left. A refused save
+# on the list again, with the term open where one is left. An open heard form
+# (K4b, E3: a correction in a meeting without manage_glossary) is confirmed or
+# rejected here, form by form. A refused save
# renders the index with the form and its reason (422).
#
# Rights: GlossaryPolicy (view_glossary / manage_glossary, account admins
@@ -120,8 +122,29 @@ module Organisations
failure_lane: { term_id: @term.id })
end
+ # An open heard form of this term (K4b, E3), named by one of its
+ # corrections: its proposals confirmed (they work from then on), or
+ # rejected (they go; a confirmed correction of the same form stays).
+ def confirm_heard_form
+ decide_heard_form(Actors::ConfirmHeardForm, notice: 'controllers.glossary.heard_form.confirm.success')
+ end
+
+ def reject_heard_form
+ decide_heard_form(Actors::RejectHeardForm, notice: 'controllers.glossary.heard_form.reject.success')
+ end
+
private
+ # The write right first (403 before the correction is looked up), then
+ # only a correction of this term.
+ def decide_heard_form(actor, notice:)
+ authorize @term, :update?
+ correction = policy_scope(TermCorrection).where(glossary_term_id: @term.id).find(params[:correction_id])
+ authorize correction, :update?
+ result = actor.call(correction: correction, current_user: current_user)
+ land(result, notice: notice, lane: { term_id: @term.id }, failure_lane: { term_id: @term.id })
+ end
+
# The right first (403 without it, before anything is looked up), then
# through the policy scope: a term of another organisation is no term at
# all (404).
diff --git a/app/helpers/glossary_helper.rb b/app/helpers/glossary_helper.rb
index 621011e..3fdfff9 100644
--- a/app/helpers/glossary_helper.rb
+++ b/app/helpers/glossary_helper.rb
@@ -82,6 +82,12 @@ module GlossaryHelper
end
end
+ # How many heard forms of a term are open (K4b, E3): forms with at least one
+ # proposal, which work nowhere until confirmed. Reads the loaded corrections.
+ def glossary_open_form_count(term)
+ term.term_corrections.select(&:proposed?).map(&:normalized_heard).uniq.size
+ end
+
# The line under a term in the list: its heard forms, each with its count
# when it was heard more than once.
def glossary_row_forms(term)
diff --git a/app/services/actors/confirm_heard_form.rb b/app/services/actors/confirm_heard_form.rb
new file mode 100644
index 0000000..6bf4179
--- /dev/null
+++ b/app/services/actors/confirm_heard_form.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+# app/services/actors/confirm_heard_form.rb
+#
+# Confirms an open heard form of a glossary term (K4b, E3): the proposals of
+# that form at that term, named by one of its corrections, become confirmed,
+# so they work from now on (TermCorrection.effective). A correction in a
+# meeting without manage_glossary made them. Rights are the caller's
+# (GlossaryPolicy, manage_glossary).
+#
+# The term is locked first (Glossary::TermLock). A term gone in the meantime is
+# refused as gone, a form with nothing open any more (someone confirmed or
+# rejected it meanwhile) as not open.
+module Actors
+ class ConfirmHeardForm < BaseActor
+ def initialize(correction:, current_user:)
+ super()
+ @correction = correction
+ @current_user = current_user
+ end
+
+ def record
+ @correction
+ end
+
+ def perform
+ Glossary::TermLock.call(term: @correction.glossary_term)
+ changed = TermCorrection.where(glossary_term_id: @correction.glossary_term_id, normalized_heard: @correction.normalized_heard,
+ status: 'proposed').update_all(status: 'confirmed', updated_at: Time.current)
+ raise ActorError.new(I18n.t('controllers.glossary.heard_form.not_open'), code: :not_open) if changed.zero?
+ end
+
+ private
+
+ attr_reader :current_user
+ end
+end
diff --git a/app/services/actors/reject_heard_form.rb b/app/services/actors/reject_heard_form.rb
new file mode 100644
index 0000000..5f1219f
--- /dev/null
+++ b/app/services/actors/reject_heard_form.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+# app/services/actors/reject_heard_form.rb
+#
+# Rejects an open heard form of a glossary term (K4b, E3): the proposals of
+# that form at that term, named by one of its corrections, are deleted, as
+# "delete a heard form" deletes (Actors::DestroyHeardForm), but only the
+# proposals. A confirmed correction of the same form stays: someone with the
+# right confirmed it, and it works. Rights are the caller's (GlossaryPolicy,
+# manage_glossary).
+#
+# The term is locked first (Glossary::TermLock). A term gone in the meantime is
+# refused as gone, a form with nothing open any more as not open.
+module Actors
+ class RejectHeardForm < BaseActor
+ def initialize(correction:, current_user:)
+ super()
+ @correction = correction
+ @current_user = current_user
+ end
+
+ # A rejection leaves no surviving primary record of its own.
+ def record
+ nil
+ end
+
+ def perform
+ Glossary::TermLock.call(term: @correction.glossary_term)
+ deleted = TermCorrection.where(glossary_term_id: @correction.glossary_term_id, normalized_heard: @correction.normalized_heard,
+ status: 'proposed').delete_all
+ raise ActorError.new(I18n.t('controllers.glossary.heard_form.not_open'), code: :not_open) if deleted.zero?
+ end
+
+ private
+
+ attr_reader :current_user
+ end
+end
diff --git a/app/services/actors/set_glossary_term_status.rb b/app/services/actors/set_glossary_term_status.rb
index 71ef5e4..63e1dba 100644
--- a/app/services/actors/set_glossary_term_status.rb
+++ b/app/services/actors/set_glossary_term_status.rb
@@ -8,6 +8,12 @@
# proposed. A rejected term stays, so it is not proposed again; confirming it
# later is allowed. The term is locked first (Glossary::TermLock), so a term
# deleted or merged away in the meantime is refused as gone.
+#
+# Confirming a PROPOSED term confirms its open heard forms with it (K4b, E3):
+# they came with the proposal, and the lane shows them to whoever confirms.
+# Rejecting leaves them as they are (at a rejected term no form works), and so
+# does confirming a rejected term later: what is open then is confirmed form
+# by form (Actors::ConfirmHeardForm).
module Actors
class SetGlossaryTermStatus < BaseActor
SETTABLE = %w[confirmed rejected].freeze
@@ -27,11 +33,17 @@ module Actors
raise ActorError.new(I18n.t('controllers.glossary.status.not_allowed'), code: :invalid_status) unless SETTABLE.include?(@status)
Glossary::TermLock.call(term: @term)
+ was_proposed = @term.proposed?
@term.update!(status: @status)
+ confirm_open_forms if was_proposed && @term.confirmed?
end
private
attr_reader :current_user
+
+ def confirm_open_forms
+ TermCorrection.where(glossary_term_id: @term.id, status: 'proposed').update_all(status: 'confirmed', updated_at: Time.current)
+ end
end
end
diff --git a/app/views/organisations/glossary/_correction.html.erb b/app/views/organisations/glossary/_correction.html.erb
index 776f9bd..1618e5f 100644
--- a/app/views/organisations/glossary/_correction.html.erb
+++ b/app/views/organisations/glossary/_correction.html.erb
@@ -30,5 +30,8 @@
<% if correction.replaced_count > 1 %>
· <%= t('views.organisations.glossary.show.replaced', count: correction.replaced_count) %>
<% end %>
+ <% if correction.proposed? %>
+ · <span class="glossary-heard__proposed"><%= t('views.organisations.glossary.show.proposed_row') %></span>
+ <% end %>
</span>
</li>
diff --git a/app/views/organisations/glossary/_detail.html.erb b/app/views/organisations/glossary/_detail.html.erb
index 2ffbdbf..61b1c28 100644
--- a/app/views/organisations/glossary/_detail.html.erb
+++ b/app/views/organisations/glossary/_detail.html.erb
@@ -34,10 +34,37 @@
<% else %>
<ul class="glossary-heard__groups">
<% groups.each do |group| %>
+ <% open_count = group.count(&:proposed?) %>
+ <% form_name = t('views.organisations.glossary.quoted', text: group.first.heard) %>
<li class="glossary-heard__group">
<div class="glossary-heard__form">
- <%= t('views.organisations.glossary.quoted', text: group.first.heard) %>
+ <%= form_name %>
<span class="glossary-heard__count"><%= t('views.organisations.glossary.show.times', count: group.size) %></span>
+ <%# K4b (E3): a form with proposals works nowhere until someone with
+ manage_glossary confirms it; rejecting removes the proposals only. %>
+ <% if open_count.positive? %>
+ <span class="glossary-status glossary-status--proposed"><%= t('views.organisations.glossary.show.open_form') %></span>
+ <% if can_write %>
+ <span class="glossary-heard__decide">
+ <%= render Neo::Buttons::ButtonComponent.new(
+ variant: :secondary, size: :small, icon: 'check-lg',
+ form: { action: confirm_heard_form_organisation_glossary_term_path(@current_organisation, term, correction_id: group.first.id),
+ method: :patch, params: list_state, data: { turbo_frame: '_top' } }
+ ) do %>
+ <%= t('views.organisations.glossary.show.confirm') %><span class="sr-only"> <%= form_name %></span>
+ <% end %>
+ <%= render Neo::Buttons::ButtonComponent.new(
+ variant: :secondary, size: :small, icon: 'x-lg',
+ confirm: t('views.organisations.glossary.show.reject_form_confirm', heard: group.first.heard, term: term.term,
+ count: open_count),
+ form: { action: reject_heard_form_organisation_glossary_term_path(@current_organisation, term, correction_id: group.first.id),
+ method: :delete, params: list_state, data: { turbo_frame: '_top' } }
+ ) do %>
+ <%= t('views.organisations.glossary.show.reject') %><span class="sr-only"> <%= form_name %></span>
+ <% end %>
+ </span>
+ <% end %>
+ <% end %>
<% if can_write %>
<%# The whole form goes, with every correction of it (plan §6: a form learnt wrong). %>
<span class="glossary-heard__delete">
diff --git a/app/views/organisations/glossary/_row.html.erb b/app/views/organisations/glossary/_row.html.erb
index 8e9dabc..4d99d59 100644
--- a/app/views/organisations/glossary/_row.html.erb
+++ b/app/views/organisations/glossary/_row.html.erb
@@ -23,6 +23,10 @@
<% unless term.confirmed? %>
<span class="glossary-status <%= term.rejected? ? 'glossary-status--rejected' : 'glossary-status--proposed' %>"><%= glossary_status_name(term.status) %></span>
<% end %>
+ <% open_forms = glossary_open_form_count(term) %>
+ <% if open_forms.positive? %>
+ <span class="glossary-status glossary-status--proposed"><%= t('views.organisations.glossary.index.open_forms', count: open_forms) %></span>
+ <% end %>
</span>
<% if count.positive? %>
<span class="people-row__sub"><%= t('views.organisations.glossary.index.heard_as', forms: glossary_row_forms(term)) %></span>
diff --git a/config/locales/views/glossar.de.yml b/config/locales/views/glossar.de.yml
index 318b042..7886442 100644
--- a/config/locales/views/glossar.de.yml
+++ b/config/locales/views/glossar.de.yml
@@ -23,8 +23,13 @@ de:
no_target: "Bitte einen Begriff wählen, mit dem zusammengeführt wird."
heard_form:
not_found: "Diese gehörte Form gibt es nicht mehr."
+ not_open: "Diese gehörte Form ist nicht mehr offen. Jemand hat sie inzwischen bestätigt oder verworfen."
destroy:
success: "Gehörte Form gelöscht."
+ confirm:
+ success: "Gehörte Form bestätigt."
+ reject:
+ success: "Vorschlag verworfen."
views:
organisations:
glossary:
@@ -69,6 +74,10 @@ de:
corrections_count:
one: "1 Korrektur"
other: "%{count} Korrekturen"
+ # Heard forms with a proposal (K4b, E3), beside the term in the list.
+ open_forms:
+ one: "1 offene Form"
+ other: "%{count} offene Formen"
show:
edit: "Bearbeiten"
close: "Schließen"
@@ -85,6 +94,12 @@ de:
one: "1-mal ersetzt"
other: "%{count}-mal ersetzt"
delete_heard: "Gehörte Form „%{heard}“ löschen"
+ # An open heard form (K4b, E3): a proposal from a meeting, not yet working.
+ open_form: "Vorschlag"
+ proposed_row: "Vorschlag"
+ reject_form_confirm:
+ one: "Den Vorschlag „%{heard}“ bei „%{term}“ verwerfen?"
+ other: "Die %{count} Vorschläge „%{heard}“ bei „%{term}“ verwerfen?"
delete_heard_confirm:
one: "Die gehörte Form „%{heard}“ bei „%{term}“ löschen?"
other: "Die gehörte Form „%{heard}“ bei „%{term}“ löschen, mit allen %{count} Korrekturen?"
diff --git a/config/locales/views/glossar.en.yml b/config/locales/views/glossar.en.yml
index 04323c5..81065f3 100644
--- a/config/locales/views/glossar.en.yml
+++ b/config/locales/views/glossar.en.yml
@@ -23,8 +23,13 @@ en:
no_target: "Please choose the term to merge with."
heard_form:
not_found: "This heard form no longer exists."
+ not_open: "This heard form is no longer open. Someone has confirmed or rejected it in the meantime."
destroy:
success: "Heard form deleted."
+ confirm:
+ success: "Heard form confirmed."
+ reject:
+ success: "Proposal rejected."
views:
organisations:
glossary:
@@ -69,6 +74,10 @@ en:
corrections_count:
one: "1 correction"
other: "%{count} corrections"
+ # Heard forms with a proposal (K4b, E3), beside the term in the list.
+ open_forms:
+ one: "1 open form"
+ other: "%{count} open forms"
show:
edit: "Edit"
close: "Close"
@@ -85,6 +94,12 @@ en:
one: "replaced once"
other: "replaced %{count} times"
delete_heard: "Delete heard form “%{heard}”"
+ # An open heard form (K4b, E3): a proposal from a meeting, not yet working.
+ open_form: "Proposal"
+ proposed_row: "proposal"
+ reject_form_confirm:
+ one: "Reject the proposal “%{heard}” of “%{term}”?"
+ other: "Reject the %{count} proposals “%{heard}” of “%{term}”?"
delete_heard_confirm:
one: "Delete the heard form “%{heard}” of “%{term}”?"
other: "Delete the heard form “%{heard}” of “%{term}”, with all %{count} corrections?"
diff --git a/config/routes.rb b/config/routes.rb
index 2f22a5b..b75f929 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -346,6 +346,9 @@ Rails.application.routes.draw do
patch :reject
post :merge
delete 'heard/:correction_id', action: :destroy_heard_form, as: :heard_form
+ # An open heard form (K4b, E3): confirm its proposals, or reject them.
+ patch 'heard/:correction_id/confirm', action: :confirm_heard_form, as: :confirm_heard_form
+ delete 'heard/:correction_id/proposals', action: :reject_heard_form, as: :reject_heard_form
end
end
diff --git a/spec/requests/organisations/glossary_spec.rb b/spec/requests/organisations/glossary_spec.rb
index 9815821..2407f12 100644
--- a/spec/requests/organisations/glossary_spec.rb
+++ b/spec/requests/organisations/glossary_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
# Every write of the page, one example each: Prosopite reads requests sent
# from one line of a loop as an N+1.
def self.write_names
- %w[create update destroy confirm reject merge destroy_heard_form]
+ %w[create update destroy confirm reject merge destroy_heard_form confirm_heard_form reject_heard_form]
end
# [verb, path, params] of a write, against the given term.
@@ -71,7 +71,9 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
'confirm' => [:patch, confirm_organisation_glossary_term_path(organisation, target), {}],
'reject' => [:patch, reject_organisation_glossary_term_path(organisation, target), {}],
'merge' => [:post, merge_organisation_glossary_term_path(organisation, target), { target_id: proposal.id }],
- 'destroy_heard_form' => [:delete, heard_form_organisation_glossary_term_path(organisation, target, correction_id: open_correction.id), {}]
+ 'destroy_heard_form' => [:delete, heard_form_organisation_glossary_term_path(organisation, target, correction_id: open_correction.id), {}],
+ 'confirm_heard_form' => [:patch, confirm_heard_form_organisation_glossary_term_path(organisation, target, correction_id: open_correction.id), {}],
+ 'reject_heard_form' => [:delete, reject_heard_form_organisation_glossary_term_path(organisation, target, correction_id: open_correction.id), {}]
}.fetch(name)
end
@@ -88,7 +90,7 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
end
def glossary_state
- [GlossaryTerm.order(:id).pluck(:id, :term, :status, :category), TermCorrection.order(:id).pluck(:id, :glossary_term_id)]
+ [GlossaryTerm.order(:id).pluck(:id, :term, :status, :category), TermCorrection.order(:id).pluck(:id, :glossary_term_id, :status)]
end
describe 'without the right' do
@@ -880,6 +882,116 @@ RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do
end
end
+ # K4b (E3): a correction in a meeting without manage_glossary leaves an open
+ # heard form, also at a confirmed term. The page shows it as open, and only
+ # manage_glossary confirms it (it works from then on) or rejects it (its
+ # proposals go, a confirmed correction of the same form stays).
+ describe 'open heard forms' do
+ let!(:open_form) do
+ create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lala beis', status: 'proposed',
+ project: open_project)
+ end
+ let(:gs) { 'views.organisations.glossary' }
+
+ def lane_markup
+ get organisation_glossary_term_path(organisation, term), headers: frame_headers
+ Nokogiri::HTML(response.body)
+ end
+
+ def open_group(page)
+ page.css('.glossary-heard__group').find { |group| group.text.include?('lala beis') }
+ end
+
+ it 'marks a term with open forms in the list, also for a reader' do
+ sign_in viewer
+ get organisation_glossary_terms_path(organisation)
+
+ row = Nokogiri::HTML(response.body).css('[data-glossary-row]').find { |node| node.text.include?('Lalabase') }
+ expect(row.text).to include(I18n.t("#{gs}.index.open_forms", count: 1))
+ end
+
+ it 'shows the open form as a proposal in the lane, without buttons for a reader' do
+ sign_in viewer
+ group = open_group(lane_markup)
+
+ expect(group.text).to include(I18n.t("#{gs}.show.open_form"))
+ expect(group.css('form')).to be_empty
+ closed = lane_markup.css('.glossary-heard__group').find { |node| node.text.include?('la la base') }
+ expect(closed.text).not_to include(I18n.t("#{gs}.show.open_form"))
+ end
+
+ it 'offers confirm and reject of the open form with manage_glossary' do
+ sign_in manager
+ group = open_group(lane_markup)
+
+ actions = group.css('form').pluck('action')
+ expect(actions).to include(confirm_heard_form_organisation_glossary_term_path(organisation, term, correction_id: open_form.id),
+ reject_heard_form_organisation_glossary_term_path(organisation, term, correction_id: open_form.id))
+ end
+
+ it 'confirms the form, which works from then on' do
+ sign_in manager
+ patch confirm_heard_form_organisation_glossary_term_path(organisation, term, correction_id: open_form.id)
+
+ expect(response).to redirect_to(organisation_glossary_terms_path(organisation, term_id: term.id))
+ expect(flash[:notice]).to eq(I18n.t('controllers.glossary.heard_form.confirm.success'))
+ expect(TermCorrection.effective.where(id: open_form.id)).to exist
+ end
+
+ it 'rejects the form: its proposals go, its confirmed corrections stay' do
+ kept = create(:term_correction, organisation: organisation, glossary_term: term, heard: 'Lala Beis')
+ sign_in manager
+
+ delete reject_heard_form_organisation_glossary_term_path(organisation, term, correction_id: open_form.id)
+
+ expect(flash[:notice]).to eq(I18n.t('controllers.glossary.heard_form.reject.success'))
+ expect(TermCorrection.where(id: open_form.id)).not_to exist
+ expect(TermCorrection.where(id: kept.id)).to exist
+ end
+
+ it 'says so when nothing of the form is open any more' do
+ sign_in manager
+ open_form.update!(status: 'confirmed')
+
+ patch confirm_heard_form_organisation_glossary_term_path(organisation, term, correction_id: open_form.id)
+
+ expect(flash[:alert]).to eq(I18n.t('controllers.glossary.heard_form.not_open'))
+ end
+
+ it 'answers 404 for a heard form of another term or another organisation, and changes nothing' do
+ foreign = ActsAsTenant.with_tenant(other_organisation) do
+ create(:term_correction, organisation: other_organisation, status: 'proposed')
+ end
+ user = manager
+ before = glossary_state
+
+ # One sign-in per request: a 404 of the exceptions app writes no session.
+ sign_in user
+ patch confirm_heard_form_organisation_glossary_term_path(organisation, proposal, correction_id: open_form.id)
+ expect(response).to have_http_status(:not_found)
+ sign_in user
+ delete reject_heard_form_organisation_glossary_term_path(organisation, term, correction_id: foreign.id)
+ expect(response).to have_http_status(:not_found)
+ sign_in user
+ patch confirm_heard_form_organisation_glossary_term_path(organisation, foreign.glossary_term_id, correction_id: foreign.id)
+ expect(response).to have_http_status(:not_found)
+ expect(glossary_state).to eq(before)
+ expect(ActsAsTenant.without_tenant { foreign.reload.status }).to eq('proposed')
+ end
+
+ it 'confirms the open forms of a proposed term with the term' do
+ proposed_form = create(:term_correction, organisation: organisation, glossary_term: proposal, heard: 'zirbel holz',
+ status: 'proposed')
+ sign_in manager
+
+ patch confirm_organisation_glossary_term_path(organisation, proposal)
+
+ expect(proposal.reload).to be_confirmed
+ expect(proposed_form.reload).to be_confirmed
+ expect(open_form.reload).to be_proposed
+ end
+ end
+
# Prosopite watches every example: the list preloads heard forms, speakers
# and projects, and asks the write right once, however many rows.
describe 'queries' do
diff --git a/spec/requests/organisations/meeting_term_corrections_spec.rb b/spec/requests/organisations/meeting_term_corrections_spec.rb
index 6349462..c4a6f4c 100644
--- a/spec/requests/organisations/meeting_term_corrections_spec.rb
+++ b/spec/requests/organisations/meeting_term_corrections_spec.rb
@@ -346,12 +346,15 @@ RSpec.describe 'Organisations::MeetingTermCorrections', :ci_guard, type: :reques
role: create(:role, organisation: stranger_org, title: Role::ACCOUNT_ADMIN_TITLE), active: true)
user
end
+ # One sign-in per request: a 404 of the exceptions app writes no session.
sign_in stranger
-
get new_path, headers: frame
expect(response.status).to be_in([302, 404])
+ expect(response.location.to_s).not_to include(new_user_session_path)
+ sign_in stranger
post_correction
expect(response.status).to be_in([302, 404])
+ expect(response.location.to_s).not_to include(new_user_session_path)
expect(meeting.reload.transcript).to eq(transcript)
expect(TermCorrection.count).to eq(0)
end
diff --git a/spec/services/actors/confirm_heard_form_spec.rb b/spec/services/actors/confirm_heard_form_spec.rb
new file mode 100644
index 0000000..707eeb8
--- /dev/null
+++ b/spec/services/actors/confirm_heard_form_spec.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+# Confirming an open heard form (K4b, E3): the proposals of that form at that
+# term become confirmed, so they work from now on (TermCorrection.effective).
+# Nothing else changes: the term keeps its status, other forms stay open.
+RSpec.describe Actors::ConfirmHeardForm, type: :service do
+ let(:organisation) { create(:organisation) }
+ let(:writer) { create(:user) }
+
+ before { ActsAsTenant.current_tenant = organisation }
+ after { ActsAsTenant.current_tenant = nil }
+
+ let(:term) { create(:glossary_term, organisation: organisation, term: 'Lalabase') }
+ let(:other_term) { create(:glossary_term, organisation: organisation, term: 'Zirbel') }
+
+ def form(heard, status:, at: term)
+ create(:term_correction, organisation: organisation, glossary_term: at, heard: heard, status: status)
+ end
+
+ it 'confirms every proposal of the form at this term, whatever its spelling, and nothing else' do
+ open = form('lala bass', status: 'proposed')
+ open_again = form('Lala Bass', status: 'proposed')
+ other_form = form('la la base', status: 'proposed')
+ elsewhere = form('lala bass', status: 'proposed', at: other_term)
+
+ result = described_class.call(correction: open, current_user: writer)
+
+ expect(result).to be_success
+ expect(TermCorrection.where(id: [open.id, open_again.id]).pluck(:status)).to eq(%w[confirmed confirmed])
+ expect(TermCorrection.where(id: [other_form.id, elsewhere.id]).pluck(:status)).to eq(%w[proposed proposed])
+ expect(term.reload).to be_confirmed
+ end
+
+ it 'makes the form work at a confirmed term' do
+ open = form('lala bass', status: 'proposed')
+
+ expect { described_class.call(correction: open, current_user: writer) }
+ .to change { TermCorrection.effective.where(id: open.id).exists? }.from(false).to(true)
+ end
+
+ it 'answers a form with nothing open any more as not open' do
+ confirmed = form('lala bass', status: 'confirmed')
+
+ result = described_class.call(correction: confirmed, current_user: writer)
+
+ expect(result.code).to eq(:not_open)
+ expect(result.errors).to eq([I18n.t('controllers.glossary.heard_form.not_open')])
+ end
+
+ it 'answers a term deleted in the meantime as gone' do
+ open = TermCorrection.find(form('lala bass', status: 'proposed').id)
+ GlossaryTerm.where(id: term.id).delete_all
+
+ expect(described_class.call(correction: open, current_user: writer).code).to eq(:not_found)
+ end
+
+ it 'locks the term before it changes the form' do
+ open = form('lala bass', status: 'proposed')
+ expect(Glossary::TermLock).to receive(:call).with(term: open.glossary_term).ordered.and_call_original
+ expect(TermCorrection).to receive(:where).ordered.and_call_original
+
+ described_class.call(correction: open, current_user: writer)
+ end
+end
diff --git a/spec/services/actors/reject_heard_form_spec.rb b/spec/services/actors/reject_heard_form_spec.rb
new file mode 100644
index 0000000..509d7ac
--- /dev/null
+++ b/spec/services/actors/reject_heard_form_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+# Rejecting an open heard form (K4b, E3): its proposals at that term are
+# deleted, like "delete a heard form" (K4a), but only the proposals. A
+# confirmed correction of the same form stays: it was confirmed by someone
+# with the right and still works.
+RSpec.describe Actors::RejectHeardForm, type: :service do
+ let(:organisation) { create(:organisation) }
+ let(:writer) { create(:user) }
+
+ before { ActsAsTenant.current_tenant = organisation }
+ after { ActsAsTenant.current_tenant = nil }
+
+ let(:term) { create(:glossary_term, organisation: organisation, term: 'Lalabase') }
+ let(:other_term) { create(:glossary_term, organisation: organisation, term: 'Zirbel') }
+
+ def form(heard, status:, at: term)
+ create(:term_correction, organisation: organisation, glossary_term: at, heard: heard, status: status)
+ end
+
+ it 'deletes the proposals of the form at this term and keeps its confirmed corrections and everything else' do
+ open = form('lala bass', status: 'proposed')
+ open_again = form('Lala Bass', status: 'proposed')
+ confirmed = form('lala bass', status: 'confirmed')
+ other_form = form('la la base', status: 'proposed')
+ elsewhere = form('lala bass', status: 'proposed', at: other_term)
+
+ result = described_class.call(correction: open, current_user: writer)
+
+ expect(result).to be_success
+ expect(TermCorrection.where(id: [open.id, open_again.id])).not_to exist
+ expect(TermCorrection.where(id: [confirmed.id, other_form.id, elsewhere.id]).count).to eq(3)
+ expect(GlossaryTerm.where(id: term.id)).to exist
+ end
+
+ it 'answers a form with nothing open any more as not open' do
+ confirmed = form('lala bass', status: 'confirmed')
+
+ result = described_class.call(correction: confirmed, current_user: writer)
+
+ expect(result.code).to eq(:not_open)
+ expect(TermCorrection.where(id: confirmed.id)).to exist
+ end
+
+ it 'answers a term deleted in the meantime as gone' do
+ open = TermCorrection.find(form('lala bass', status: 'proposed').id)
+ GlossaryTerm.where(id: term.id).delete_all
+
+ expect(described_class.call(correction: open, current_user: writer).code).to eq(:not_found)
+ end
+end
diff --git a/spec/services/actors/set_glossary_term_status_spec.rb b/spec/services/actors/set_glossary_term_status_spec.rb
index 80fffa6..d59ea17 100644
--- a/spec/services/actors/set_glossary_term_status_spec.rb
+++ b/spec/services/actors/set_glossary_term_status_spec.rb
@@ -25,6 +25,37 @@ RSpec.describe Actors::SetGlossaryTermStatus, type: :service do
expect(term.reload.status).to eq('confirmed')
end
+ # K4b (E3): a proposed term came with its heard forms, proposed alike, and
+ # the one who confirms it sees them in the lane. Rejecting leaves the forms
+ # (they work nowhere at a rejected term anyway); a term confirmed again
+ # later keeps what is open.
+ describe 'the open heard forms' do
+ let!(:open_form) { create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lala bass', status: 'proposed') }
+
+ it 'are confirmed with the proposal they came with' do
+ described_class.call(term: term, status: 'confirmed', current_user: writer)
+
+ expect(open_form.reload).to be_confirmed
+ end
+
+ it 'stay open when the term is rejected, and when a rejected term is confirmed' do
+ described_class.call(term: term, status: 'rejected', current_user: writer)
+ expect(open_form.reload).to be_proposed
+
+ described_class.call(term: term, status: 'confirmed', current_user: writer)
+ expect(open_form.reload).to be_proposed
+ end
+
+ it 'of another term stay open' do
+ other = create(:glossary_term, :proposed, organisation: organisation, term: 'Zirbel')
+ elsewhere = create(:term_correction, organisation: organisation, glossary_term: other, heard: 'zirbel holz', status: 'proposed')
+
+ described_class.call(term: term, status: 'confirmed', current_user: writer)
+
+ expect(elsewhere.reload).to be_proposed
+ end
+ end
+
it 'never proposes, and refuses any other value' do
confirmed = create(:glossary_term, organisation: organisation)