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.

Judge a meeting's linked tickets against each ticket's own project

Guido Boyke07a3d08ece1c
diff --git a/app/models/meeting.rb b/app/models/meeting.rb
index e032a0a..283389d 100644
--- a/app/models/meeting.rb
+++ b/app/models/meeting.rb
@@ -201,15 +201,6 @@ class Meeting < ApplicationRecord
Meetings::ParticipantFilter.call(all, [name])
}
- # Meetings that link to `record` (a ticket), oldest link first. Says nothing
- # about who may read them: compose it onto MeetingPolicy::Scope, which judges
- # every meeting against its OWN project. A ticket moved to another project keeps
- # its links, so the ticket's project is the wrong question for its meetings.
- scope :linking_to, lambda { |record|
- joins(:outgoing_references).merge(Reference.pointing_to(record))
- .order(Reference.arel_table[:created_at])
- }
-
# Removes a leading YAML frontmatter block (FRONTMATTER_BLOCK) from `text`. Pure
# function (mirrors MeetingParticipant.normalize_name) so display, the excerpt and
# summary_source share ONE codepath — the raw value in the DB / edit textarea is
diff --git a/app/services/tickets/linked_meetings.rb b/app/services/tickets/linked_meetings.rb
new file mode 100644
index 0000000..5d0ac69
--- /dev/null
+++ b/app/services/tickets/linked_meetings.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+# The meetings that link to a ticket and that a person may read, oldest link
+# first, projects preloaded for the paths. Each meeting is judged against its OWN
+# project (MeetingPolicy::Scope): a ticket moved to another project keeps its
+# meeting links, so the ticket's project answers neither who may see a meeting
+# nor where its page is. The one owner of this question; nothing composes the
+# join without the scope.
+#
+# Entry point: call
+module Tickets
+ class LinkedMeetings
+ def self.call(ticket:, user:)
+ new(ticket: ticket, user: user).call
+ end
+
+ def initialize(ticket:, user:)
+ @ticket = ticket
+ @user = user
+ end
+
+ def call
+ links = Reference.pointing_to(@ticket).where(source_type: Meeting.polymorphic_name)
+ # Most tickets have no meeting: answer without resolving permissions.
+ return Meeting.none unless links.exists?
+
+ MeetingPolicy::Scope.new(@user, Meeting).resolve
+ .joins(:outgoing_references).merge(links)
+ .includes(:project)
+ .order(Reference.arel_table[:created_at])
+ end
+ end
+end
diff --git a/app/views/organisations/meetings/_ticket_links_section.html.erb b/app/views/organisations/meetings/_ticket_links_section.html.erb
index 0d0392b..c19b025 100644
--- a/app/views/organisations/meetings/_ticket_links_section.html.erb
+++ b/app/views/organisations/meetings/_ticket_links_section.html.erb
@@ -19,6 +19,11 @@
map (not filter_map): target_id is NOT NULL, so it is never nil — even a
tombstone keeps the deleted ticket's id. %>
<% linked_ids = references.map(&:target_id) %>
+<%# Which linked tickets this reader may open, each against the TICKET's own
+ project: a ticket moved out of this project keeps its link, and can_read_tickets
+ above answers for this project only. One policy scope query for all of them. %>
+<% live_ids = references.filter_map { |ref| ref.target_id if ref.target.present? } %>
+<% readable_ids = live_ids.any? ? policy_scope(Ticket).where(id: live_ids).pluck(:id) : [] %>
<%# Frame id is the shared contract with MeetingTicketLinksController (see the
helper) — never inline dom_id here, or the two can drift. %>
@@ -35,16 +40,20 @@
<li class="flex items-center gap-3 py-2 text-sm" id="<%= dom_id(ref, :meeting_ticket_link) %>">
<i class="bi bi-card-checklist text-cream-500 shrink-0"></i>
<% if ref.target.present? %>
- <% if can_read_tickets %>
+ <% if readable_ids.include?(ref.target_id) %>
<%# _top: this link sits inside the section's turbo-frame, but the
tickets page has no frame with that id — without the escape
Turbo renders "Content missing" instead of navigating. %>
<%= link_to ref.target.display_title,
- organisation_project_tickets_path(@current_organisation, project, ticket_id: ref.target.id),
+ organisation_project_tickets_path(@current_organisation, ref.target.project_id, ticket_id: ref.target.id),
class: 'flex-1 min-w-0 truncate text-cream-900 hover:underline',
data: { turbo_frame: '_top' } %>
- <% else %>
+ <% elsif ref.target.project_id == project.id %>
<span class="flex-1 min-w-0 truncate text-cream-900"><%= ref.target.display_title %></span>
+ <% else %>
+ <%# Moved to a project this reader cannot see: the title it had when
+ it was linked here, nothing it became over there. %>
+ <span class="flex-1 min-w-0 truncate text-cream-900"><%= ref.target_title_snapshot %></span>
<% end %>
<% else %>
<%# Tombstone: the linked ticket was hard-deleted — show the snapshot,
diff --git a/app/views/organisations/tickets/_meeting_references_section.html.erb b/app/views/organisations/tickets/_meeting_references_section.html.erb
index 8d6a133..ca6de21 100644
--- a/app/views/organisations/tickets/_meeting_references_section.html.erb
+++ b/app/views/organisations/tickets/_meeting_references_section.html.erb
@@ -3,17 +3,17 @@
(Gespräche Slice 3): meetings that link TO this ticket. Sits between the
sub-tasks section and the comment timeline, styled after _subtasks_section.
- GATE (here, per meeting): a meeting shows only to people who may read meetings
- in the MEETING's project (MeetingPolicy::Scope), and its link names that project.
+ GATE (here, per meeting, Tickets::LinkedMeetings): a meeting shows only to
+ people who may read meetings in the MEETING's project, and its link names that
+ project.
A ticket moved to another project keeps its meeting links, so the ticket's
project answers neither question. Somebody who may read none of the meetings
does not learn that links exist: the section renders nothing without an entry,
so it never appears empty.
No tombstones on this side: a meeting owns its outgoing link (dependent:
- :destroy), so a backlink's source meeting always exists. includes(:project)
- avoids an N+1 across the linking meetings' paths. %>
-<% meetings = policy_scope(Meeting).linking_to(ticket).includes(:project).to_a %>
+ :destroy), so a backlink's source meeting always exists. %>
+<% meetings = Tickets::LinkedMeetings.call(ticket: ticket, user: current_user).to_a %>
<% if meetings.any? %>
<section id="meeting-references-<%= ticket.id %>" class="meeting-references-section mb-6">
<ul class="divide-y divide-cream-200 overflow-hidden rounded-lg bg-cream-50">
diff --git a/spec/requests/organisations/ticket_meeting_references_access_spec.rb b/spec/requests/organisations/ticket_meeting_references_access_spec.rb
index 2fbdeee..1357de8 100644
--- a/spec/requests/organisations/ticket_meeting_references_access_spec.rb
+++ b/spec/requests/organisations/ticket_meeting_references_access_spec.rb
@@ -32,10 +32,17 @@ RSpec.describe 'Ticket meeting references after a move', :ci_guard, type: :reque
end
end
- def member
+ # A member whose role may carry organisation-wide permissions ("all projects"),
+ # or the account admin role.
+ def member(global: [], admin: false)
user = create(:user)
ActsAsTenant.with_tenant(organisation) do
- role = create(:role, title: "Role #{SecureRandom.hex(4)}", organisation: organisation)
+ role = if admin
+ create(:admin_role, organisation: organisation)
+ else
+ create(:role, title: "Role #{SecureRandom.hex(4)}", organisation: organisation)
+ end
+ global.each { |action| create(:permission, role: role, category: 'projects', action: action, allowed: true) }
create(:membership, user: user, organisation: organisation, role: role, active: true)
end
user
@@ -132,4 +139,97 @@ RSpec.describe 'Ticket meeting references after a move', :ci_guard, type: :reque
expect(body).not_to include(organisation_project_meetings_path(organisation, project_b, meeting_id: meeting.id))
end
end
+
+ context 'viewer reads meetings in all projects through the role' do
+ let(:viewer) do
+ member(global: %w[read_access_meetings_all_projects]).tap do |user|
+ grant(user, project_b, tickets_access: 'read_only')
+ end
+ end
+
+ it 'names the meeting of A and links into A' do
+ sign_in viewer
+ body = ticket_page
+
+ expect(body).to include('Planning-Meeting-QV')
+ expect(body).to include(organisation_project_meetings_path(organisation, project_a, meeting_id: meeting.id))
+ end
+ end
+
+ context 'viewer reads meetings in all projects through the role, but not in A' do
+ let(:viewer) do
+ member(global: %w[read_access_meetings_all_projects]).tap do |user|
+ grant(user, project_b, tickets_access: 'read_only')
+ grant(user, project_a, meetings_access: 'no_access')
+ end
+ end
+
+ it 'does not name the meeting of A' do
+ sign_in viewer
+ body = ticket_page
+
+ expect(body).not_to include('Planning-Meeting-QV')
+ expect(body).not_to include("meeting-references-#{ticket.id}")
+ end
+ end
+
+ context 'viewer is an account admin' do
+ let(:viewer) { member(admin: true) }
+
+ it 'names the meeting of A and links into A' do
+ sign_in viewer
+ body = ticket_page
+
+ expect(body).to include('Planning-Meeting-QV')
+ expect(body).to include(organisation_project_meetings_path(organisation, project_a, meeting_id: meeting.id))
+ end
+ end
+
+ # The other side of the same link: the meeting in A lists the ticket that now
+ # lives in B. The ticket is judged against B, its link names B, and a reader
+ # who cannot see it learns nothing newer than the title it had when linked.
+ describe "the meeting's linked tickets" do
+ before do
+ ActsAsTenant.with_tenant(organisation) { ticket.update!(title: 'Renamed-in-B-QV') }
+ end
+
+ def meeting_page
+ get organisation_project_meeting_path(organisation, project_a, meeting)
+ expect(response).to have_http_status(:ok)
+ response.body
+ end
+
+ context 'viewer reads tickets and meetings in A, nothing in B' do
+ let(:viewer) do
+ member.tap { |user| grant(user, project_a, tickets_access: 'read_only', meetings_access: 'read_only') }
+ end
+
+ it 'shows the title from the time of linking, without a link' do
+ sign_in viewer
+ body = meeting_page
+
+ expect(body).to include('Moved ticket')
+ expect(body).not_to include('Renamed-in-B-QV')
+ expect(body).not_to include("ticket_id=#{ticket.id}")
+ end
+ end
+
+ context 'viewer reads meetings in A and tickets in B' do
+ let(:viewer) do
+ member.tap do |user|
+ grant(user, project_a, meetings_access: 'read_only')
+ grant(user, project_b, tickets_access: 'read_only')
+ end
+ end
+
+ it 'links the ticket into its own project B' do
+ sign_in viewer
+ body = meeting_page
+
+ expect(body).to include('Renamed-in-B-QV')
+ expect(body).to include(organisation_project_tickets_path(organisation, project_b, ticket_id: ticket.id))
+ expect(body).not_to include(organisation_project_tickets_path(organisation, project_a, ticket_id: ticket.id))
+ end
+ end
+ end
end
diff --git a/spec/services/tickets/linked_meetings_spec.rb b/spec/services/tickets/linked_meetings_spec.rb
new file mode 100644
index 0000000..3cdb1bc
--- /dev/null
+++ b/spec/services/tickets/linked_meetings_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Tickets::LinkedMeetings do
+ let(:organisation) { create(:organisation) }
+ let(:creator) { create(:user) }
+ let(:project) { ActsAsTenant.with_tenant(organisation) { create(:project, organisation: organisation) } }
+ let(:ticket) do
+ ActsAsTenant.with_tenant(organisation) { create(:ticket, project: project, organisation: organisation, creator: creator) }
+ end
+ let(:reader) do
+ create(:user).tap do |user|
+ ActsAsTenant.with_tenant(organisation) do
+ role = create(:role, organisation: organisation)
+ create(:membership, user: user, organisation: organisation, role: role, active: true)
+ create(:project_permission, user: user, project: project, meetings_access: 'read_only')
+ end
+ end
+ end
+
+ def meeting_linked_at(time, title)
+ ActsAsTenant.with_tenant(organisation) do
+ meeting = create(:meeting, project: project, organisation: organisation, creator: creator, title: title)
+ meeting.outgoing_references.create!(organisation: organisation, target: ticket,
+ target_title_snapshot: ticket.display_title, created_at: time)
+ meeting
+ end
+ end
+
+ before { ActsAsTenant.current_tenant = organisation }
+ after { ActsAsTenant.current_tenant = nil }
+
+ it 'resolves no permissions for a ticket without meeting links' do
+ expect(MeetingPolicy::Scope).not_to receive(:new)
+
+ expect(described_class.call(ticket: ticket, user: reader)).to be_empty
+ end
+
+ it 'lists the linking meetings oldest link first, whatever their own dates' do
+ later = meeting_linked_at(1.hour.ago, 'Linked second')
+ earlier = meeting_linked_at(2.hours.ago, 'Linked first')
+
+ expect(described_class.call(ticket: ticket, user: reader).map(&:title)).to eq([earlier.title, later.title])
+ end
+
+ it 'ignores a reference from something other than a meeting' do
+ note = create(:note, project: project, organisation: organisation, creator: creator)
+ Reference.create!(organisation: organisation, source: note, target: ticket,
+ target_title_snapshot: ticket.display_title)
+
+ expect(described_class.call(ticket: ticket, user: reader)).to be_empty
+ end
+end