Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Pin the ticket finders at their decision points
Guido Boyke410c81a2f0a4
diff --git a/spec/services/actors/destroy_ticket_relation_spec.rb b/spec/services/actors/destroy_ticket_relation_spec.rbindex feddb90..1c24fdf 100644--- a/spec/services/actors/destroy_ticket_relation_spec.rb+++ b/spec/services/actors/destroy_ticket_relation_spec.rb@@ -45,6 +45,25 @@ RSpec.describe Actors::DestroyTicketRelation doexpect(TicketRelation.count).to eq(2)end+ # The caller found the row, then someone else removed it. destroy! on the stale object would+ # report success for a write that never happened.+ it 'does not find a relation removed after the caller found it' do+ stale = TicketRelation.find(relation.id)+ TicketRelation.where(id: relation.id).delete_all++ result = described_class.call(ticket: ticket_a, relation: stale, current_user: user)++ expect(result.code).to eq(:not_found)+ expect(TicketRelation.pluck(:id)).to eq([neighbour.id])+ end++ it 'does not remove a found relation through a ticket it does not touch' do+ result = described_class.call(ticket: ticket_c, relation: relation, current_user: user)++ expect(result.code).to eq(:not_found)+ expect(TicketRelation.exists?(relation.id)).to be(true)+ end+it 'does not find an unknown id' doexpect(unlink(ticket_a, SecureRandom.uuid).code).to eq(:not_found)enddiff --git a/spec/services/tickets/readable_for_token_spec.rb b/spec/services/tickets/readable_for_token_spec.rbindex 7e88aa1..ff6766f 100644--- a/spec/services/tickets/readable_for_token_spec.rb+++ b/spec/services/tickets/readable_for_token_spec.rb@@ -138,6 +138,55 @@ RSpec.describe Tickets::ReadableForToken, :ci_guard doendend+ describe 'a token that reaches several places' do+ it 'finds every listed project, not only the first' do+ token = token_for(admin, organisations: [organisation], project_scopes: { organisation => [project_a, project_b] })+ tickets = all_tickets++ expect(found_tickets(admin, tickets, token: token)).to contain_exactly(ticket_a, ticket_b)+ end++ # Reach is per organisation. A rule that read another organisation's entry would widen one+ # of these two tokens, whichever order the entries come in. The admin is a member of both:+ # a token holds an organisation only while its owner does.+ before do+ Prosopite.pause do+ ActsAsTenant.with_tenant(foreign_organisation) do+ create(:membership, user: admin, organisation: foreign_organisation,+ role: create(:admin_role, organisation: foreign_organisation), active: true)+ end+ end+ end++ it "cuts by this organisation's entry when another organisation is open" do+ token = token_for(admin, organisations: [foreign_organisation, organisation],+ project_scopes: { organisation => [project_a] })++ expect(token.reach.organisation_ids).to contain_exactly(organisation.id, foreign_organisation.id)+ expect(found(admin, ticket_a.id, token: token)).to eq(ticket_a)+ expect(found(admin, ticket_b.id, token: token)).to be_nil+ end++ it 'opens this organisation by its own entry when another organisation is limited' do+ foreign_project = new_project(foreign_organisation)+ token = token_for(admin, organisations: [foreign_organisation, organisation],+ project_scopes: { foreign_organisation => [foreign_project] })++ expect(token.reach.organisation_ids).to contain_exactly(organisation.id, foreign_organisation.id)+ expect(found(admin, ticket_b.id, token: token)).to eq(ticket_b)+ end+ end++ describe 'an id that names nothing' do+ ['not-a-uuid', '', nil].each do |id|+ it "gives nil for #{id.inspect}, and no database error" do+ ticket_a++ expect(found(admin, id, token: token_reaching_everything(admin))).to be_nil+ end+ end+ end+describe 'an empty reach' do{'a token outside the organisation' => -> { token_for(admin, organisations: [foreign_organisation]) },diff --git a/spec/services/tickets/relation_access_spec.rb b/spec/services/tickets/relation_access_spec.rbindex 2ee1765..6b22fc6 100644--- a/spec/services/tickets/relation_access_spec.rb+++ b/spec/services/tickets/relation_access_spec.rb@@ -106,6 +106,21 @@ RSpec.describe Tickets::RelationAccess, :ci_guard doexpect(other_ticket(admin, ticket_b.id, token: token_reaching_a(admin))).to be_nilend+ it 'finds nothing through a token outside the organisation, never everything' do+ token = Prosopite.pause { create(:personal_access_token, user: admin, organisations: [foreign_organisation]) }++ expect(other_ticket(admin, ticket_a.id)).to eq(ticket_a)+ expect(other_ticket(admin, ticket_a.id, token: token)).to be_nil+ end++ ['not-a-uuid', '', nil].each do |id|+ it "gives nil for #{id.inspect}, and no database error" do+ ticket_a++ expect(other_ticket(admin, id)).to be_nil+ end+ end+it 'finds project B for the account admin without a token' doexpect(other_ticket(admin, ticket_b.id)).to eq(ticket_b)end@@ -145,6 +160,29 @@ RSpec.describe Tickets::RelationAccess, :ci_guard doexpect(relation(admin, ticket_a, edge.id, token: token)).to be_nilend+ it 'stops at the reach whichever end lies outside it' do+ incoming = link(ticket_b, ticket_a)+ token = token_reaching_a(admin)++ expect(relation(admin, ticket_a, incoming.id)).to eq(incoming)+ expect(relation(admin, ticket_a, incoming.id, token: token)).to be_nil+ end++ it 'finds nothing through a token outside the organisation, never everything' do+ edge = link(ticket_a, ticket_a2)+ token = Prosopite.pause { create(:personal_access_token, user: admin, organisations: [foreign_organisation]) }++ expect(relation(admin, ticket_a, edge.id, token: token)).to be_nil+ end++ ['not-a-uuid', '', nil].each do |id|+ it "gives nil for #{id.inspect}, and no database error" do+ link(ticket_a, ticket_a2)++ expect(relation(admin, ticket_a, id)).to be_nil+ end+ end+it 'finds the relation A-B for the account admin without a token' doedge = link(ticket_a, ticket_b)