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 uncut attachment text, the author reader and token reach on R1 routes
Guido Boykece61484a85f9
diff --git a/CLAUDE.md b/CLAUDE.mdindex 58081e0..1be296a 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -819,7 +819,10 @@ feature by feature):switches the answer to the paged fields of MCP `get_ticket` (`posts_total`,`posts_truncated`, `attachments`, ...). **Without them the body stays byte-equal** (thecontract records it; gboyke/lalabase-mcp reads it). Invalid values: 422 `invalid_input`,- checked before the ticket is looked up. REST does not truncate bodies.+ checked before the ticket is looked up. A key without a value switches too. REST does not+ truncate bodies, nor the extracted `text` of attachments (up to 10 per page). These+ `attachments` are the ticket's own files only, with text and without URL (`attachments_total`+ counts those); `GET /tickets/:id/attachments` lists ticket and comment files with signed URLs.* `GET /projects/:project_id/tickets/number/:number` answers what `GET /tickets/:id` answers,paging included. Missing, malformed (`abc`, `0`), unreadable, out of reach or foreign: thesame 404. The number is looked up only inside that project.diff --git a/app/services/tickets/serializer.rb b/app/services/tickets/serializer.rbindex 7df9555..194e7a8 100644--- a/app/services/tickets/serializer.rb+++ b/app/services/tickets/serializer.rb@@ -77,10 +77,11 @@ module Tickets# upload time (ExtractPlainTextProcessingService).## Its OWN method rather than a key in #full, because the two surfaces want- # opposite things: the HTTP API renders #full on every show and builds its own- # attachment list with signed URLs, so a body of PDF text in there would be+ # opposite things: the plain HTTP show renders #full and the attachments route+ # builds its own list with signed URLs, so a body of PDF text in there would be# payload nobody asked for. The MCP read tool wants exactly that text and can do- # nothing with a URL it cannot open.+ # nothing with a URL it cannot open; the REST ticket view hands it out only on+ # request, in pages of ten (Tickets::Reading, REST R1), uncut.## Ordered oldest first, like the posts: the caller bounds the list, and which# files survive that bound must not depend on the order the database felt like.diff --git a/spec/requests/api/v1/ticket_view_spec.rb b/spec/requests/api/v1/ticket_view_spec.rbindex 115c038..434336c 100644--- a/spec/requests/api/v1/ticket_view_spec.rb+++ b/spec/requests/api/v1/ticket_view_spec.rb@@ -114,7 +114,7 @@ RSpec.describe 'REST ticket view', :ci_guard, type: :request dodescribe 'GET /tickets/:id with paging parameters' do# One example per reader: Prosopite watches each request on its own.- { other: 5, addressee: 7, admin: 7 }.each do |reader, total|+ { other: 5, addressee: 7, author: 7, admin: 7 }.each do |reader, total|it "pages and counts what the #{reader} may read, like MCP get_ticket" douser = public_send(reader)body = get_json(user, ticket_path, { posts_per_page: '3', posts_order: 'newest' })@@ -207,6 +207,16 @@ RSpec.describe 'REST ticket view', :ci_guard, type: :request doexpect(body['attachments'].size).to eq(1)expect(response.body).not_to include('geheim.txt')end++ it 'hands out the text of a file whole where MCP cuts it' do+ Prosopite.pause do+ ActsAsTenant.with_tenant(organisation) { files.first.update_column(:plain_text_version, long_text) }+ end+ body = get_json(other, ticket_path, { attachments_page: 1 })['data']+ expect(body.dig('attachments', 0, 'text')).to eq(long_text)+ mcp = mcp_answer(other, :GetTicket, ticket_id: ticket.id)+ expect(mcp.dig('attachments', 0, 'text').length).to be < long_text.length+ endendend@@ -228,6 +238,10 @@ RSpec.describe 'REST ticket view', :ci_guard, type: :request doexpect(body.dig('data', 'id')).to eq(private_post.id)end+ it 'serves a private comment to its author' do+ expect(get_json(author, post_path(private_post.id)).dig('data', 'id')).to eq(private_post.id)+ end+it 'serves a private comment to an account admin' doexpect(get_json(admin, post_path(private_post.id)).dig('data', 'id')).to eq(private_post.id)end@@ -335,6 +349,35 @@ RSpec.describe 'REST ticket view', :ci_guard, type: :request doexpect_not_foundend+ it 'treats an empty selected-project list as no reach' do+ token = token_for(admin, project_scopes: { organisation => [] })+ get_json(admin, number_path(ticket.number), {}, token: token)+ expect_not_found+ end++ it 'hides an organisation the token excludes although the reader still belongs to it' do+ other_org = Prosopite.pause { create(:organisation) }+ Prosopite.pause do+ ActsAsTenant.with_tenant(other_org) do+ create(:membership, user: admin, organisation: other_org, role: create(:admin_role, organisation: other_org), active: true)+ end+ end+ token = Prosopite.pause { create(:personal_access_token, user: admin, organisations: [other_org]).token }+ get_json(admin, number_path(ticket.number), {}, token: token)+ expect_not_found+ get_json(admin, "/api/v1/tickets/#{ticket.id}/posts/#{posts[1].id}", {}, token: token)+ expect_not_found+ end++ it 'follows the current membership, not the token, once it was deactivated' do+ token = token_for(admin)+ Prosopite.pause { Membership.unscoped.find_by!(user: admin, organisation: organisation).update!(active: false) }+ get_json(admin, number_path(ticket.number), {}, token: token)+ expect_not_found+ get_json(admin, "/api/v1/tickets/#{ticket.id}/posts/#{posts[1].id}", {}, token: token)+ expect_not_found+ end+it 'hides a ticket of another organisation' doforeign = Prosopite.pause doorg = create(:organisation)