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.

Close the remaining gaps around a meeting move

Guido Boyke816628a265fc
diff --git a/app/models/meeting.rb b/app/models/meeting.rb
index 283389d..fcf7a32 100644
--- a/app/models/meeting.rb
+++ b/app/models/meeting.rb
@@ -217,6 +217,13 @@ class Meeting < ApplicationRecord
# to the notes, and the LLM never sees the id:/parent: noise. Controller guard,
# view gate and Meetings::SummaryService all derive from THIS method so the rule
# cannot drift apart (review #235).
+ # The live summary stream names the project: after a move (Actors::MoveMeeting)
+ # a page still open in the old project hears nothing of what is written in
+ # the new one. The view subscribes through the same method.
+ def summary_stream_name
+ "#{dom_id(self)}_#{project_id}_summary"
+ end
+
def summary_source
self.class.strip_frontmatter(transcript).presence || self.class.strip_frontmatter(notes).presence
end
@@ -265,7 +272,7 @@ class Meeting < ApplicationRecord
saved_change_to_summary_creation_error?
broadcast_replace_to(
- "#{dom_id(self)}_summary",
+ summary_stream_name,
target: "#{dom_id(self)}_summary_section",
partial: 'organisations/meetings/summary_section',
locals: { meeting: self }
diff --git a/app/services/actors/move_meeting.rb b/app/services/actors/move_meeting.rb
index f4f8388..07d6a1d 100644
--- a/app/services/actors/move_meeting.rb
+++ b/app/services/actors/move_meeting.rb
@@ -33,7 +33,8 @@ module Actors
time_sessions_count: sessions.count,
billed_time_sessions_count: sessions.where(billed: true).count,
open_suggestions_count: @meeting.meeting_ticket_suggestions.open.count,
- ticket_links_count: ticket_links.count
+ ticket_links_count: ticket_links.count,
+ bound_analyses_count: bound_analyses.size
}
end
@@ -78,6 +79,7 @@ module Actors
def guard_movable!
refuse!(:moved_meanwhile) if @meeting.project_id != @source_project.id
refuse!(:has_ticket_links) if ticket_links.exists?
+ refuse!(:published_analyses_bound) if bound_analyses.any?
refuse!(:suggestion_run_active) if suggestion_run_active?
end
@@ -93,22 +95,55 @@ module Actors
end
# A saved analysis may be published when its sources are this meeting
- # (Assistant::AnalysisSources.publishable?), and a meeting citation names
- # the project it was read in. The meeting is the same one after the move,
- # so its citations follow it; every other source keeps its project and
- # stays a reason not to publish (a chat narrowed to the source project too).
+ # (Assistant::AnalysisSources.publishable?), and a citation of the meeting
+ # names the project it was read in; the source list links through that
+ # project too (Lalabase::CitationLink). The meeting and its analyses are the
+ # same records after the move, so their citations follow them, in the
+ # provenance and in the displayed list. Every other source keeps its
+ # project and stays a reason not to publish (a chat narrowed to the source
+ # project too, see #bound_analyses).
+ CARRIED_LISTS = %w[provenance citations].freeze
+
def carry_meeting_citations
+ analysis_ids = @meeting.meeting_analyses.pluck(:id)
@meeting.meeting_analyses.where.not(source_context: nil).find_each do |analysis|
- provenance = analysis.source_context['provenance']
- next unless provenance.is_a?(Array)
-
- carried = provenance.map do |citation|
- own = citation.is_a?(Hash) && citation['type'] == 'meeting' && citation['id'] == @meeting.id
- own ? citation.merge('project_id' => @target_project.id) : citation
+ context = analysis.source_context
+ carried = CARRIED_LISTS.select { |key| context[key].is_a?(Array) }.index_with do |key|
+ context[key].map { |citation| carry(citation, analysis_ids, to: @target_project.id) }
end
- next if carried == provenance
+ next if carried.all? { |key, list| list == context[key] }
+
+ analysis.update_columns(source_context: context.merge(carried))
+ end
+ end
- analysis.update_columns(source_context: analysis.source_context.merge('provenance' => carried))
+ def carry(citation, analysis_ids, to:)
+ return citation unless citation.is_a?(Hash)
+
+ own = (citation['type'] == 'meeting' && citation['id'] == @meeting.id) ||
+ (citation['type'] == 'meeting_analysis' && analysis_ids.include?(citation['id']))
+ own ? citation.merge('project_id' => to) : citation
+ end
+
+ # Published analyses that could not be published in the target, the
+ # meeting citations already carried along: their other sources (in practice
+ # a chat narrowed to the source project) stay behind. The move does not
+ # decide their visibility silently; they are unpublished first. Asked
+ # through the publication rule itself, with the meeting in a project that
+ # is not the source: the answer is the same for every target, so the dialog
+ # can ask before one is chosen.
+ ELSEWHERE = 'elsewhere'
+
+ def bound_analyses
+ @bound_analyses ||= begin
+ moved = Struct.new(:id, :project_id).new(@meeting.id, ELSEWHERE)
+ analysis_ids = @meeting.meeting_analyses.pluck(:id)
+ @meeting.meeting_analyses.where(is_private: false).where.not(source_context: nil).reject do |analysis|
+ context = analysis.source_context
+ provenance = context['provenance']
+ carried = provenance.is_a?(Array) ? provenance.map { |c| carry(c, analysis_ids, to: ELSEWHERE) } : provenance
+ Assistant::AnalysisSources.publishable?(context: context.merge('provenance' => carried), meeting: moved)
+ end
end
end
diff --git a/app/services/actors/save_meeting.rb b/app/services/actors/save_meeting.rb
index 2ae6680..994b3d3 100644
--- a/app/services/actors/save_meeting.rb
+++ b/app/services/actors/save_meeting.rb
@@ -19,6 +19,7 @@ module Actors
# Extract BEFORE find_meeting: a new record does project.meetings.build(params),
# which would choke on a :participants key that is not a Meeting column.
@participants_payload = extract_participants(params)
+ @project = project
@meeting = find_meeting(project, params, id)
@meeting_params = params
@current_user = current_user
@@ -32,6 +33,7 @@ module Actors
raise ActorError, 'Meeting not found' if @meeting.nil?
if @meeting.id.present?
+ guard_still_in_project!
@meeting.update!(@meeting_params)
else
@meeting.creator = @current_user
@@ -70,6 +72,18 @@ module Actors
# Tenant-scoped lookup. A given id that matches no meeting in this tenant
# (including a foreign-tenant id) yields nil, which #perform turns into a
# "Meeting not found" failure. A blank id builds a new meeting in the project.
+ # The caller authorized the edit against @project. Actors::MoveMeeting holds
+ # the meeting's row lock while it moves it; a move that committed meanwhile
+ # has taken the meeting where this edit was never authorized. Under the lock
+ # the meeting is gone from this project, as a deleted one would be.
+ def guard_still_in_project!
+ @meeting.lock!
+ return if @meeting.project_id == @project.id
+
+ @meeting = nil
+ raise ActorError, 'Meeting not found'
+ end
+
def find_meeting(project, params, id)
if id.present?
Meeting.where(organisation: project.organisation, id: id).first
diff --git a/app/views/organisations/meetings/_meeting_show.html.erb b/app/views/organisations/meetings/_meeting_show.html.erb
index 1eb50b0..fa7db88 100644
--- a/app/views/organisations/meetings/_meeting_show.html.erb
+++ b/app/views/organisations/meetings/_meeting_show.html.erb
@@ -5,7 +5,7 @@
<% visible_analyses = visible_meeting_analyses(meeting) %>
<% can_see_time = policy(meeting.project).area_access?(:time_sessions, :read) %>
-<%= turbo_stream_from "#{dom_id(meeting)}_summary" %>
+<%= turbo_stream_from meeting.summary_stream_name %>
<div id="meeting-header" class="meeting-content min-w-0" <%= assistant_context_attributes(meeting) %>>
<%= render 'organisations/meetings/lane_head', meeting: meeting, current_frame_id: current_frame_id %>
diff --git a/app/views/organisations/meetings/_move_modal.html.erb b/app/views/organisations/meetings/_move_modal.html.erb
index 81e8217..9fce63a 100644
--- a/app/views/organisations/meetings/_move_modal.html.erb
+++ b/app/views/organisations/meetings/_move_modal.html.erb
@@ -5,7 +5,8 @@
a refused move replaces exactly it with the message. Shape and lifecycle after
README_MODAL_PATTERN.md.
- A meeting with linked tickets cannot move: the dialog says so and offers no form.
+ A meeting with linked tickets, or with a published analysis that draws on this
+ project, cannot move: the dialog says why and offers no form.
The form goes to _top, so a successful move is a visit to the meeting in its new
place; a refusal answers with a stream into this opening. %>
<% mm = 'views.organisations.meetings.move' %>
@@ -13,6 +14,7 @@
<% field_class = 'w-full rounded border border-cream-300 bg-surface-raised px-3 py-2 text-sm focus:border-ink focus:outline-none focus:ring-1 focus:ring-ink' %>
<% cancel_class = 'h-9 rounded border border-cream-300 bg-cream-100 px-4 text-sm font-medium text-cream-800 hover:bg-cream-200' %>
<% linked = impact[:ticket_links_count] %>
+<% bound = impact[:bound_analyses_count] %>
<div id="<%= meeting_move_modal_instance_id(meeting, token) %>"
data-controller="meeting-move-modal"
data-meeting-move-modal-return-id-value="<%= meeting_move_trigger_id(meeting) %>"
@@ -46,8 +48,13 @@
</div>
<% end %>
- <% if linked.positive? %>
- <p class="text-sm text-cream-800"><%= t("#{mm}.has_ticket_links", count: linked) %></p>
+ <% if linked.positive? || bound.positive? %>
+ <% if linked.positive? %>
+ <p class="text-sm text-cream-800"><%= t("#{mm}.has_ticket_links", count: linked) %></p>
+ <% end %>
+ <% if bound.positive? %>
+ <p class="text-sm text-cream-800"><%= t("#{mm}.published_analyses_bound", count: bound) %></p>
+ <% end %>
<div class="flex justify-end border-t border-cream-200 pt-3">
<button type="button" class="<%= cancel_class %>" data-meeting-move-modal-target="first"
data-action="click->meeting-move-modal#close">
diff --git a/config/locales/services.de.yml b/config/locales/services.de.yml
index 1895792..0318e0b 100644
--- a/config/locales/services.de.yml
+++ b/config/locales/services.de.yml
@@ -51,6 +51,7 @@ de:
same_project: "Das Meeting liegt schon in diesem Projekt."
forbidden_target: "In diesem Projekt darfst du keine Meetings anlegen."
has_ticket_links: "Das Meeting ist mit Tickets verknüpft. Entferne die Verknüpfungen, dann kannst du es verschieben."
+ published_analyses_bound: "Eine veröffentlichte Analyse stützt sich auf das alte Projekt. Mach sie wieder privat, dann kannst du das Meeting verschieben."
moved_meanwhile: "Das Meeting wurde gerade schon verschoben. Lade die Seite neu."
suggestion_run_active: "Für das Meeting werden gerade Ticket-Vorschläge erzeugt. Versuche es gleich noch einmal."
move_ticket:
diff --git a/config/locales/services.en.yml b/config/locales/services.en.yml
index 184abf8..ff3dca7 100644
--- a/config/locales/services.en.yml
+++ b/config/locales/services.en.yml
@@ -51,6 +51,7 @@ en:
same_project: "The meeting is already in this project."
forbidden_target: "You may not add meetings to this project."
has_ticket_links: "The meeting is linked to tickets. Remove the links, then you can move it."
+ published_analyses_bound: "A published analysis draws on the old project. Make it private again, then you can move the meeting."
moved_meanwhile: "The meeting was just moved already. Reload the page."
suggestion_run_active: "Ticket suggestions are being generated for this meeting. Try again in a moment."
move_ticket:
diff --git a/config/locales/views/meetings.de.yml b/config/locales/views/meetings.de.yml
index 2287a39..7f6a871 100644
--- a/config/locales/views/meetings.de.yml
+++ b/config/locales/views/meetings.de.yml
@@ -114,6 +114,9 @@ de:
has_ticket_links:
one: Das Meeting ist mit einem Ticket verknüpft und kann deshalb nicht verschoben werden. Entferne zuerst die Verknüpfung.
other: Das Meeting ist mit %{count} Tickets verknüpft und kann deshalb nicht verschoben werden. Entferne zuerst die Verknüpfungen.
+ published_analyses_bound:
+ one: Eine veröffentlichte Analyse stützt sich auf das alte Projekt. Mach sie zuerst wieder privat.
+ other: "%{count} veröffentlichte Analysen stützen sich auf das alte Projekt. Mach sie zuerst wieder privat."
time_sessions:
zero: Auf dieses Meeting ist keine Zeit gebucht.
one: Die gebuchte Zeit zieht mit um (1 Eintrag, davon %{billed} abgerechnet).
diff --git a/config/locales/views/meetings.en.yml b/config/locales/views/meetings.en.yml
index 9918833..cbf2e43 100644
--- a/config/locales/views/meetings.en.yml
+++ b/config/locales/views/meetings.en.yml
@@ -113,6 +113,9 @@ en:
has_ticket_links:
one: The meeting is linked to a ticket and therefore cannot be moved. Remove the link first.
other: The meeting is linked to %{count} tickets and therefore cannot be moved. Remove the links first.
+ published_analyses_bound:
+ one: A published analysis draws on the old project. Make it private first.
+ other: "%{count} published analyses draw on the old project. Make them private first."
time_sessions:
zero: No time is booked on this meeting.
one: The booked time moves with it (1 entry, %{billed} of it billed).
diff --git a/spec/models/meeting_spec.rb b/spec/models/meeting_spec.rb
index 748999f..99cb76e 100644
--- a/spec/models/meeting_spec.rb
+++ b/spec/models/meeting_spec.rb
@@ -378,7 +378,7 @@ RSpec.describe Meeting, type: :model do
# live updates), and an unrelated edit must NOT broadcast (the guard).
describe 'summary broadcast (after_update_commit)' do
let(:meeting) { create(:meeting, organisation: organisation, project: project, creator: creator, notes: 'x') }
- let(:stream) { "#{ActionView::RecordIdentifier.dom_id(meeting)}_summary" }
+ let(:stream) { "#{ActionView::RecordIdentifier.dom_id(meeting)}_#{project.id}_summary" }
let(:target) { "#{ActionView::RecordIdentifier.dom_id(meeting)}_summary_section" }
it 'broadcasts the summary section when a summary column changes' do
@@ -387,6 +387,18 @@ RSpec.describe Meeting, type: :model do
meeting.update!(summary_creation_flag: true)
end
+ # A reader of the old project may still have the meeting open after a move
+ # (Actors::MoveMeeting). The stream names the project, so the summaries
+ # written after the move reach only pages rendered in the new one.
+ it 'sends to the stream of the project the meeting is in now' do
+ elsewhere = create(:project, organisation: organisation)
+ meeting.update_columns(project_id: elsewhere.id)
+ moved_stream = "#{ActionView::RecordIdentifier.dom_id(meeting)}_#{elsewhere.id}_summary"
+
+ expect(meeting).to receive(:broadcast_replace_to).with(moved_stream, anything)
+ meeting.update!(summary_creation_flag: true)
+ end
+
it 'does not broadcast on an unrelated update (title only)' do
expect(meeting).not_to receive(:broadcast_replace_to)
meeting.update!(title: 'Renamed meeting')
diff --git a/spec/requests/organisations/meeting_move_spec.rb b/spec/requests/organisations/meeting_move_spec.rb
index 31e7047..c65302b 100644
--- a/spec/requests/organisations/meeting_move_spec.rb
+++ b/spec/requests/organisations/meeting_move_spec.rb
@@ -89,6 +89,18 @@ RSpec.describe 'Organisations::Meetings move', :ci_guard, type: :request do
expect(response.body).not_to include('name="target_project_id"')
end
+ it 'says up front that a published analysis drawing on this project keeps the meeting here' do
+ ActsAsTenant.with_tenant(organisation) do
+ create(:meeting_analysis, meeting: meeting, organisation: organisation, creator: mover, is_private: false,
+ source_context: { 'provenance' => [{ 'type' => 'project', 'id' => source.id }] })
+ end
+ sign_in mover
+ frame_get preflight_path
+
+ expect(response.body).to include(I18n.t('views.organisations.meetings.move.published_analyses_bound', count: 1))
+ expect(response.body).not_to include('name="target_project_id"')
+ end
+
it 'refuses a member without move_meetings' do
user = member(move: false, access: { source => 'read_write', target => 'read_write' })
sign_in user
diff --git a/spec/services/actors/move_meeting_spec.rb b/spec/services/actors/move_meeting_spec.rb
index 5fa0138..a9639ea 100644
--- a/spec/services/actors/move_meeting_spec.rb
+++ b/spec/services/actors/move_meeting_spec.rb
@@ -94,6 +94,23 @@ RSpec.describe Actors::MoveMeeting, type: :service do
expect(scoped.reload).not_to be_sources_publishable
end
+ it 'carries the displayed citations of this meeting and its analyses along' do
+ analysis = create(:meeting_analysis, meeting: meeting, organisation: organisation, creator: admin,
+ source_context: { 'citations' => [
+ { 'type' => 'meeting', 'id' => meeting.id, 'project_id' => source_project.id },
+ { 'type' => 'ticket', 'id' => SecureRandom.uuid, 'project_id' => source_project.id }
+ ], 'provenance' => [] })
+ analysis.source_context['citations'] << { 'type' => 'meeting_analysis', 'id' => analysis.id,
+ 'project_id' => source_project.id }
+ analysis.save!
+
+ move
+
+ projects = analysis.reload.source_context['citations'].to_h { |citation| [citation['type'], citation['project_id']] }
+ expect(projects).to eq('meeting' => target_project.id, 'meeting_analysis' => target_project.id,
+ 'ticket' => source_project.id)
+ end
+
describe '#preflight' do
it 'names the booked time, the billed part and the open suggestions' do
create(:time_session, project: source_project, organisation: organisation, meeting: meeting)
@@ -104,7 +121,7 @@ RSpec.describe Actors::MoveMeeting, type: :service do
impact = described_class.new(meeting: meeting, target_project: target_project, current_user: admin).preflight
expect(impact).to include(time_sessions_count: 2, billed_time_sessions_count: 1,
- open_suggestions_count: 1, ticket_links_count: 0)
+ open_suggestions_count: 1, ticket_links_count: 0, bound_analyses_count: 0)
end
end
@@ -168,6 +185,26 @@ RSpec.describe Actors::MoveMeeting, type: :service do
expect(meeting.reload.project_id).not_to eq(target_project.id)
end
+ # A chat narrowed to the source project is a source of its own: the
+ # analysis may not be public in the target, so the move does not decide
+ # that silently. Unpublish it first.
+ it 'refuses while a published analysis cites the source project' do
+ create(:meeting_analysis, meeting: meeting, organisation: organisation, creator: admin, is_private: false,
+ source_context: { 'provenance' => [
+ { 'type' => 'meeting', 'id' => meeting.id, 'project_id' => source_project.id },
+ { 'type' => 'project', 'id' => source_project.id }
+ ] })
+
+ expect_refusal(move, :published_analyses_bound)
+ end
+
+ it 'moves when such an analysis is private' do
+ create(:meeting_analysis, meeting: meeting, organisation: organisation, creator: admin,
+ source_context: { 'provenance' => [{ 'type' => 'project', 'id' => source_project.id }] })
+
+ expect(move).to be_success
+ end
+
it 'refuses the project the meeting is already in' do
expect_refusal(move(target: source_project), :same_project)
end
diff --git a/spec/services/actors/save_meeting_spec.rb b/spec/services/actors/save_meeting_spec.rb
index 757038a..ad330e8 100644
--- a/spec/services/actors/save_meeting_spec.rb
+++ b/spec/services/actors/save_meeting_spec.rb
@@ -53,6 +53,25 @@ RSpec.describe Actors::SaveMeeting do
expect(result.success).to be(false)
expect(ActsAsTenant.with_tenant(other_org) { foreign_meeting.reload.title }).not_to eq('Kickoff')
end
+
+ # The edit was authorized against this project. A move (Actors::MoveMeeting)
+ # that committed meanwhile has taken the meeting into another one, where the
+ # editor may have no rights: the edit finds no meeting here.
+ it 'does not edit a meeting that has moved to another project' do
+ meeting = create(:meeting, project: project, organisation: organisation, creator: user, title: 'Alt')
+ elsewhere = create(:project, organisation: organisation)
+ allow(Meeting).to receive(:where).and_wrap_original do |original, *args, **kwargs|
+ relation = original.call(*args, **kwargs)
+ Meeting.unscoped.where(id: meeting.id).update_all(project_id: elsewhere.id)
+ relation
+ end
+
+ result = described_class.call(project: project, params: valid_params, id: meeting.id, current_user: user)
+
+ expect(result.success).to be(false)
+ expect(result.resource).to be_nil
+ expect(meeting.reload.title).to eq('Alt')
+ end
end
describe 'participant sync' do