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
List a comment's files wherever a comment is served
Guido Boyke0f80f09111a3
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.ymlindex d13c292..fa8667c 100644--- a/.github/workflows/guards.yml+++ b/.github/workflows/guards.yml@@ -303,6 +303,7 @@ jobs:spec/requests/api/v1/capabilities_spec.rbspec/requests/api/v1/time_session_booking_spec.rbspec/requests/api/v1/ticket_view_spec.rb+ spec/requests/api/v1/comment_files_spec.rbspec/requests/api/v1/people_spec.rbspec/requests/api/people_parity_spec.rbspec/requests/api/v1/post_comment_format_spec.rbdiff --git a/app/services/api/v1/capabilities.rb b/app/services/api/v1/capabilities.rbindex 73f9f7e..f7ef029 100644--- a/app/services/api/v1/capabilities.rb+++ b/app/services/api/v1/capabilities.rb@@ -17,8 +17,10 @@ module Api# never: an existing name, field or meaning does not change. 1.2.0 added# the People API; 1.3.0 added the REST ticket view (R1); 1.4.0 adds# time_sessions.book (R6); 1.5.0 adds posts.plain (R3a); 1.6.0 adds- # knowledge.search (R2); 1.7.0 adds tickets.changes (R3b).- API_VERSION = '1.7.0'+ # knowledge.search (R2); 1.7.0 adds tickets.changes (R3b); 1.8.0 adds a+ # comment's attachments (R7), a field and no capability: a client takes+ # its presence as the signal.+ API_VERSION = '1.8.0'# name => [verb, path as the router spells it]ENDPOINTS = {diff --git a/app/services/lalabase/tools/get_ticket.rb b/app/services/lalabase/tools/get_ticket.rbindex c883a96..abd77e3 100644--- a/app/services/lalabase/tools/get_ticket.rb+++ b/app/services/lalabase/tools/get_ticket.rb@@ -17,7 +17,9 @@ module Lalabase# names a referenced ticket but never its content (Bezugs-Sammlung E5), so a# question about the attached PDF is answered from this payload or not at all.# A `text_status` per file says whether that text exists, is missing, or was- # never extractable — silence would be answered with a guess.+ # never extractable — silence would be answered with a guess. A comment's files+ # are another matter: they come with the comment as name, type and size only+ # (Tickets::Serializer#post_attachments), metadata like its author, no text.## Caps (D9, over-fetching / DoS): long bodies are truncated, the posts list is# bounded, and so are the attachments in both directions (how many, and how muchdiff --git a/app/services/mcp/dispatcher.rb b/app/services/mcp/dispatcher.rbindex 490a102..fe2aca8 100644--- a/app/services/mcp/dispatcher.rb+++ b/app/services/mcp/dispatcher.rb@@ -51,7 +51,9 @@ module Mcp# It narrows an existing argument on purpose, released as a fix: a key of 256# bytes up to about 2.6 KB used to be stored and replayed (one stored before# is refused now, not replayed), a longer one wrote again on every retry.- SERVER_VERSION = '0.13.1'+ # 0.14 = a comment in get_ticket lists its files (`attachments`: id, filename,+ # content_type, byte_size; REST R7), beside attachments_count.+ SERVER_VERSION = '0.14.0'# MCP surface — sourced from the single tool registry (D6): the :mcp set is the# ONE definition of this surface, so a registry refactor can't drift it (R3);diff --git a/app/services/tickets/reading.rb b/app/services/tickets/reading.rbindex ae402a5..e31ec3f 100644--- a/app/services/tickets/reading.rb+++ b/app/services/tickets/reading.rb@@ -10,7 +10,8 @@# Visibility is the serializer's: every page and count comes out of# ticket.posts.readable_by, so posts_total never counts a comment the reader# may not see. The attachments are the ticket's OWN files (TicketDocument);-# files on comments are not part of this list.+# files on comments are not part of this list, each comment lists its own+# (Tickets::Serializer#post_attachments, REST R7).## Entry point: optionsmodule Ticketsdiff --git a/app/services/tickets/serializer.rb b/app/services/tickets/serializer.rbindex 194e7a8..e8f2a31 100644--- a/app/services/tickets/serializer.rb+++ b/app/services/tickets/serializer.rb@@ -144,10 +144,10 @@ module Ticketsend# Eager-load everything serialized below (author, rich-text body, attachment- # rows) so a ticket with many posts does not N+1. Shared by the API show- # action and the MCP get_ticket tool, both of which can return many posts.+ # rows and their blobs) so a ticket with many posts does not N+1. Shared by the+ # API show action and the MCP get_ticket tool, both of which can return many posts.def loaded(scope)- scope.includes(:user, :post_documents).with_rich_text_content+ scope.includes(:user, post_documents: { post_document_file_attachment: :blob }).with_rich_text_contentenddef post_payload(post)@@ -162,28 +162,43 @@ module Tickets# post_document_files), so the old count answered 0 for every comment that# had one — and handed that 0 to the model as a fact.# .size on the preloaded association — avoids a COUNT(*) per post.+ # Counts rows: a document whose blob went missing stays here and is+ # dropped from the list below, as #attachments_total does for a ticket.attachments_count: post.post_documents.size,+ attachments: post_attachments(post),created_at: post.created_at.iso8601,updated_at: post.updated_at.iso8601}end+ # A comment's files in id order. The id is the PostDocument's, which the file+ # proxy takes (/org/:org/files/post_document/:id, a comment's file opens for+ # whoever may read the comment), NOT the Active Storage attachment's that+ # GET /tickets/:id/attachments hands out. Metadata only: no signed URL (see the+ # NOTE on this class), and no text, so the caps of get_ticket hold as they were.+ def post_attachments(post)+ post.post_documents.sort_by(&:id).filter_map do |document|+ blob = document.post_document_file&.blob+ blob && file_fields(document, blob)+ end+ end+def attachment(document)blob = document.ticket_document_file&.blobreturn nil if blob.nil?raw = document.plain_text_version- {- id: document.id,- filename: blob.filename.to_s,- content_type: blob.content_type,- byte_size: blob.byte_size,+ file_fields(document, blob).merge(text: raw.presence,# The four-word vocabulary (available / unsupported / unavailable / empty)# and the ⚠️ about reading the RAW column live with the extractor's# allowlist, shared with Tools::GetDocument.text_status: ExtractPlainTextProcessingService.text_status(raw, blob.content_type)- }+ )+ end++ def file_fields(document, blob)+ { id: document.id, filename: blob.filename.to_s, content_type: blob.content_type, byte_size: blob.byte_size }endendenddiff --git a/spec/contracts/mcp_contract_recorder.rb b/spec/contracts/mcp_contract_recorder.rbindex cac2f99..e5bced3 100644--- a/spec/contracts/mcp_contract_recorder.rb+++ b/spec/contracts/mcp_contract_recorder.rb@@ -106,7 +106,7 @@ module McpContractrole: 21, other_role: 22, guest_role: 23,website: 31, internal: 32, handbook: 33, foreign_project: 34, archive: 35,login_ticket: 41, export_ticket: 42, hidden_ticket: 43, archived_ticket: 44, internal_ticket: 45,- first_post: 51, second_post: 52,+ first_post: 51, second_post: 52, first_post_file: 53,deploy_note: 61,unread_notification: 71, read_notification: 72, archived_notification: 73,write_token: 81, read_token: 82, deactivated_token: 83, limited_token: 84, dora_token: 85,@@ -350,7 +350,30 @@ module McpContract'get_person' => get_person_calls,# MCP 0.13.1, appended last: refusals that write nothing, so every# answer after them stays as it was.- 'idempotency_key' => idempotency_key_calls(website)+ 'idempotency_key' => idempotency_key_calls(website),+ # MCP 0.14 (REST R7), appended last: the file of Ben's comment, made+ # right before it.+ 'comment_file' => comment_file_calls(website)+ }+ end++ # A comment's file, by the id of its PostDocument: fixed, because the file+ # proxy takes that id and the client builds its address from it. Ben's comment+ # is the oldest on the login ticket, so a page of one holds it. Without+ # `record`: no tick, no clock moved for the REST section, which lists this+ # file too (attachment_calls, ticket_view).+ def comment_file_calls(website)+ in_org do+ attach_fixture(PostDocument.new(id: id(:first_post_file), post: Post.find(id(:first_post)), organisation: @organisation,+ create_embeddings: false),+ :post_document_file, :post)+ end+ login = { project_id: website, ticket_id: id(:login_ticket) }+ {+ 'page' => tool_call(:read, 'get_ticket', **login, posts_per_page: 1),+ 'one_post' => tool_call(:read, 'get_ticket', **login, post_id: id(:first_post)),+ # The comment beside it has no file, and says so.+ 'no_file' => tool_call(:read, 'get_ticket', **login, post_id: id(:second_post))}end@@ -546,8 +569,9 @@ module McpContract'empty' => rest_get(:read, "/api/v1/projects?organisation_id=#{id(:other_organisation)}"),'unauthorized' => rest_get(nil, '/api/v1/projects')},- # Terminal client S5, appended last: its files are made right before it,- # so every answer above stays as it was.+ # Terminal client S5, appended last: the ticket's file is made right before+ # it and the comment's after the MCP calls, so every answer above stays as+ # it was.'GET /api/v1/tickets/:id/attachments' => attachment_calls,# REST R0 (cli_rest_plan D6, D7), appended last for the same reason: one# answer per error code, then a write with an Idempotency-Key, its replay@@ -681,6 +705,8 @@ module McpContract# the comments the recorded writes added share one second and would be# ordered by their random ids.'show_paged' => rest_get(:read, "#{login}?posts_per_page=1&posts_page=2&attachments_page=1"),+ # R7: page one is Ben's comment, with its file (comment_file_calls).+ 'show_paged_comment_file' => rest_get(:read, "#{login}?posts_per_page=1"),'show_invalid_paging' => rest_get(:read, "#{login}?posts_order=random"),'by_number' => rest_get(:read, by_number.call(:website, 2)),'by_number_not_found' => rest_get(:read, by_number.call(:website, 999)),@@ -814,9 +840,10 @@ module McpContract}end- # One file on the login ticket, one on Ben's public comment there, both from- # fixed fixture files so name, type and size are the same on every run.- # Without `record`: no tick, no clock moved for anything recorded later.+ # One file on the login ticket, made here, one on Ben's public comment there,+ # made by comment_file_calls, both from fixed fixture files so name, type and+ # size are the same on every run. Without `record`: no tick, no clock moved+ # for anything recorded later.ATTACHMENT_FIXTURES = {ticket: ['test_document.pdf', 'application/pdf'],post: ['test_file.txt', 'text/plain']@@ -826,8 +853,6 @@ module McpContractin_org doattach_fixture(TicketDocument.new(ticket: @login, organisation: @organisation, create_embeddings: false),:ticket_document_file, :ticket)- attach_fixture(PostDocument.new(post: Post.find(id(:first_post)), organisation: @organisation, create_embeddings: false),- :post_document_file, :post)endpath = ->(ticket) { "/api/v1/tickets/#{id(ticket)}/attachments" }{diff --git a/spec/fixtures/mcp_contract.json b/spec/fixtures/mcp_contract.jsonindex 5d1e2ce..8e631ef 100644--- a/spec/fixtures/mcp_contract.json+++ b/spec/fixtures/mcp_contract.json@@ -1,9 +1,9 @@{"header": {"regenerate": "RAILS_ENV=test bin/rails mcp:contract",- "core_commit": "44bc4f0b91ee75a3a4bbc0a1fec7d8f18747952f",+ "core_commit": "80d75a190772f8f15546fb4b7c200cc9a0b88de8","core_dirty": true,- "contract_sha256": "8a85b28c00bd355eee3ae577db4757959078cc7a5f34d8e7c461bdfe2d26b73d"+ "contract_sha256": "bce4a6d9eec92d9e35ccce8217316d3be5650ed01217ed6915125a1cf78790d2"},"contract": {"mcp": {@@ -42,7 +42,7 @@},"serverInfo": {"name": "lalabase",- "version": "0.13.1"+ "version": "0.14.0"}}}@@ -863,7 +863,7 @@"content": [{"type": "text",- "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000051\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n \"body_html\": \"Tritt nur in Safari auf.\",\n \"body_text\": \"Tritt nur in Safari auf.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"created_at\": \"2026-01-05T09:25:00Z\",\n \"updated_at\": \"2026-01-05T09:25:00Z\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000052\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"body_html\": \"Ich schaue es mir an.\",\n \"body_text\": \"Ich schaue es mir an.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"created_at\": \"2026-01-05T09:26:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\"\n }\n ],\n \"posts_total\": 2,\n \"posts_truncated\": false,\n \"posts_page\": 1,\n \"posts_per_page\": 50,\n \"posts_pages\": 1,\n \"posts_order\": \"oldest\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"+ "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000051\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n \"body_html\": \"Tritt nur in Safari auf.\",\n \"body_text\": \"Tritt nur in Safari auf.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"attachments\": [],\n \"created_at\": \"2026-01-05T09:25:00Z\",\n \"updated_at\": \"2026-01-05T09:25:00Z\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000052\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"body_html\": \"Ich schaue es mir an.\",\n \"body_text\": \"Ich schaue es mir an.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"attachments\": [],\n \"created_at\": \"2026-01-05T09:26:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\"\n }\n ],\n \"posts_total\": 2,\n \"posts_truncated\": false,\n \"posts_page\": 1,\n \"posts_per_page\": 50,\n \"posts_pages\": 1,\n \"posts_order\": \"oldest\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"}],"isError": false,@@ -897,7 +897,7 @@"content": [{"type": "text",- "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000051\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n \"body_html\": \"Tritt nur in Safari auf.\",\n \"body_text\": \"Tritt nur in Safari auf.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"created_at\": \"2026-01-05T09:25:00Z\",\n \"updated_at\": \"2026-01-05T09:25:00Z\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000052\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"body_html\": \"Ich schaue es mir an.\",\n \"body_text\": \"Ich schaue es mir an.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"created_at\": \"2026-01-05T09:26:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\"\n }\n ],\n \"posts_total\": 2,\n \"posts_truncated\": false,\n \"posts_page\": 1,\n \"posts_per_page\": 50,\n \"posts_pages\": 1,\n \"posts_order\": \"oldest\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"+ "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000051\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n \"body_html\": \"Tritt nur in Safari auf.\",\n \"body_text\": \"Tritt nur in Safari auf.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"attachments\": [],\n \"created_at\": \"2026-01-05T09:25:00Z\",\n \"updated_at\": \"2026-01-05T09:25:00Z\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000052\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"body_html\": \"Ich schaue es mir an.\",\n \"body_text\": \"Ich schaue es mir an.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"attachments\": [],\n \"created_at\": \"2026-01-05T09:26:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\"\n }\n ],\n \"posts_total\": 2,\n \"posts_truncated\": false,\n \"posts_page\": 1,\n \"posts_per_page\": 50,\n \"posts_pages\": 1,\n \"posts_order\": \"oldest\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"}],"isError": false,@@ -1069,7 +1069,7 @@"content": [{"type": "text",- "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000052\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"body_html\": \"Ich schaue es mir an.\",\n \"body_text\": \"Ich schaue es mir an.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"created_at\": \"2026-01-05T09:26:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\"\n }\n ],\n \"posts_total\": 2,\n \"posts_truncated\": true,\n \"posts_page\": 1,\n \"posts_per_page\": 1,\n \"posts_pages\": 2,\n \"posts_order\": \"newest\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"+ "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000052\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"body_html\": \"Ich schaue es mir an.\",\n \"body_text\": \"Ich schaue es mir an.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"attachments\": [],\n \"created_at\": \"2026-01-05T09:26:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\"\n }\n ],\n \"posts_total\": 2,\n \"posts_truncated\": true,\n \"posts_page\": 1,\n \"posts_per_page\": 1,\n \"posts_pages\": 2,\n \"posts_order\": \"newest\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"}],"isError": false,@@ -1105,7 +1105,7 @@"content": [{"type": "text",- "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000051\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n \"body_html\": \"Tritt nur in Safari auf.\",\n \"body_text\": \"Tritt nur in Safari auf.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"created_at\": \"2026-01-05T09:25:00Z\",\n \"updated_at\": \"2026-01-05T09:25:00Z\"\n }\n ],\n \"posts_total\": 2,\n \"posts_truncated\": true,\n \"post_id\": \"00000000-0000-4000-8000-000000000051\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"+ "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000051\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n \"body_html\": \"Tritt nur in Safari auf.\",\n \"body_text\": \"Tritt nur in Safari auf.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"attachments\": [],\n \"created_at\": \"2026-01-05T09:25:00Z\",\n \"updated_at\": \"2026-01-05T09:25:00Z\"\n }\n ],\n \"posts_total\": 2,\n \"posts_truncated\": true,\n \"post_id\": \"00000000-0000-4000-8000-000000000051\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"}],"isError": false,@@ -3729,6 +3729,113 @@}}}+ },+ "comment_file": {+ "page": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "get_ticket",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000031",+ "ticket_id": "00000000-0000-4000-8000-000000000041",+ "posts_per_page": 1+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000013\",\n \"name\": \"Carla Conrad\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:36:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000051\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n \"body_html\": \"Tritt nur in Safari auf.\",\n \"body_text\": \"Tritt nur in Safari auf.\",\n \"is_private\": false,\n \"attachments_count\": 1,\n \"attachments\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000053\",\n \"filename\": \"test_file.txt\",\n \"content_type\": \"text/plain\",\n \"byte_size\": 500\n }\n ],\n \"created_at\": \"2026-01-05T09:25:00Z\",\n \"updated_at\": \"2026-01-05T09:36:00Z\"\n }\n ],\n \"posts_total\": 6,\n \"posts_truncated\": true,\n \"posts_page\": 1,\n \"posts_per_page\": 1,\n \"posts_pages\": 6,\n \"posts_order\": \"oldest\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"+ }+ ],+ "isError": false,+ "_meta": {+ "lalabase/kind": "ok"+ }+ }+ }+ }+ },+ "one_post": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "get_ticket",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000031",+ "ticket_id": "00000000-0000-4000-8000-000000000041",+ "post_id": "00000000-0000-4000-8000-000000000051"+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000013\",\n \"name\": \"Carla Conrad\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:36:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000051\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n \"body_html\": \"Tritt nur in Safari auf.\",\n \"body_text\": \"Tritt nur in Safari auf.\",\n \"is_private\": false,\n \"attachments_count\": 1,\n \"attachments\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000053\",\n \"filename\": \"test_file.txt\",\n \"content_type\": \"text/plain\",\n \"byte_size\": 500\n }\n ],\n \"created_at\": \"2026-01-05T09:25:00Z\",\n \"updated_at\": \"2026-01-05T09:36:00Z\"\n }\n ],\n \"posts_total\": 6,\n \"posts_truncated\": true,\n \"post_id\": \"00000000-0000-4000-8000-000000000051\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"+ }+ ],+ "isError": false,+ "_meta": {+ "lalabase/kind": "ok"+ }+ }+ }+ }+ },+ "no_file": {+ "token": "read",+ "request": {+ "jsonrpc": "2.0",+ "id": 1,+ "method": "tools/call",+ "params": {+ "name": "get_ticket",+ "arguments": {+ "project_id": "00000000-0000-4000-8000-000000000031",+ "ticket_id": "00000000-0000-4000-8000-000000000041",+ "post_id": "00000000-0000-4000-8000-000000000052"+ }+ }+ },+ "response": {+ "status": 200,+ "body": {+ "jsonrpc": "2.0",+ "id": 1,+ "result": {+ "content": [+ {+ "type": "text",+ "text": "{\n \"id\": \"00000000-0000-4000-8000-000000000041\",\n \"number\": 1,\n \"title\": \"Login bricht ab\",\n \"status\": \"in_progress\",\n \"status_functions\": [\n \"is_in_progress\"\n ],\n \"ticket_type\": \"support\",\n \"parent_id\": null,\n \"assignees\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000012\",\n \"name\": \"Ben Berger\"\n },\n {\n \"id\": \"00000000-0000-4000-8000-000000000013\",\n \"name\": \"Carla Conrad\"\n }\n ],\n \"creator\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"created_at\": \"2026-01-05T09:21:00Z\",\n \"updated_at\": \"2026-01-05T09:36:00Z\",\n \"summary\": null,\n \"description_html\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"description_text\": \"Nach dem Absenden bleibt die Seite weiß.\",\n \"custom_attributes\": {\n \"status\": \"in_progress\",\n \"priority\": \"high\"\n },\n \"project\": {\n \"id\": \"00000000-0000-4000-8000-000000000031\",\n \"name\": \"Website-Relaunch\"\n },\n \"posts\": [\n {\n \"id\": \"00000000-0000-4000-8000-000000000052\",\n \"author\": {\n \"id\": \"00000000-0000-4000-8000-000000000011\",\n \"name\": \"Anna Albers\"\n },\n \"body_html\": \"Ich schaue es mir an.\",\n \"body_text\": \"Ich schaue es mir an.\",\n \"is_private\": false,\n \"attachments_count\": 0,\n \"attachments\": [],\n \"created_at\": \"2026-01-05T09:26:00Z\",\n \"updated_at\": \"2026-01-05T09:26:00Z\"\n }\n ],\n \"posts_total\": 6,\n \"posts_truncated\": true,\n \"post_id\": \"00000000-0000-4000-8000-000000000052\",\n \"attachments\": [],\n \"attachments_total\": 0,\n \"attachments_truncated\": false,\n \"attachments_page\": 1,\n \"attachments_pages\": 0\n}"+ }+ ],+ "isError": false,+ "_meta": {+ "lalabase/kind": "ok"+ }+ }+ }+ }+ }}}},@@ -3764,7 +3871,7 @@"all_projects": true}],- "api_version": "1.7.0",+ "api_version": "1.8.0","capabilities": ["error_codes","idempotency",@@ -3830,7 +3937,7 @@"all_projects": true}],- "api_version": "1.7.0",+ "api_version": "1.8.0","capabilities": ["error_codes","idempotency",@@ -4910,6 +5017,7 @@"body_text": "Ich schaue es mir an.","is_private": false,"attachments_count": 0,+ "attachments": [],"created_at": "2026-01-05T09:26:00Z","updated_at": "2026-01-05T09:26:00Z"}@@ -4966,6 +5074,130 @@}}},+ "show_paged_comment_file": {+ "token": "read",+ "request": {+ "path": "/api/v1/tickets/00000000-0000-4000-8000-000000000041?posts_per_page=1"+ },+ "response": {+ "status": 200,+ "body": {+ "data": {+ "id": "00000000-0000-4000-8000-000000000041",+ "number": 1,+ "title": "Login bricht ab",+ "status": "in_progress",+ "status_functions": [+ "is_in_progress"+ ],+ "ticket_type": "support",+ "parent_id": null,+ "assignees": [+ {+ "id": "00000000-0000-4000-8000-000000000011",+ "name": "Anna Albers"+ },+ {+ "id": "00000000-0000-4000-8000-000000000012",+ "name": "Ben Berger"+ },+ {+ "id": "00000000-0000-4000-8000-000000000013",+ "name": "Carla Conrad"+ }+ ],+ "creator": {+ "id": "00000000-0000-4000-8000-000000000011",+ "name": "Anna Albers"+ },+ "created_at": "2026-01-05T09:21:00Z",+ "updated_at": "2026-01-05T09:36:00Z",+ "summary": null,+ "description_html": "Nach dem Absenden bleibt die Seite weiß.",+ "description_text": "Nach dem Absenden bleibt die Seite weiß.",+ "custom_attributes": {+ "status": "in_progress",+ "priority": "high"+ },+ "project": {+ "id": "00000000-0000-4000-8000-000000000031",+ "name": "Website-Relaunch"+ },+ "posts": [+ {+ "id": "00000000-0000-4000-8000-000000000051",+ "author": {+ "id": "00000000-0000-4000-8000-000000000012",+ "name": "Ben Berger"+ },+ "body_html": "Tritt nur in Safari auf.",+ "body_text": "Tritt nur in Safari auf.",+ "is_private": false,+ "attachments_count": 1,+ "attachments": [+ {+ "id": "00000000-0000-4000-8000-000000000053",+ "filename": "test_file.txt",+ "content_type": "text/plain",+ "byte_size": 500+ }+ ],+ "created_at": "2026-01-05T09:25:00Z",+ "updated_at": "2026-01-05T09:36:00Z"+ }+ ],+ "posts_total": 7,+ "posts_truncated": true,+ "posts_page": 1,+ "posts_per_page": 1,+ "posts_pages": 7,+ "posts_order": "oldest",+ "attachments": [+ {+ "id": "<generated-id-8>",+ "filename": "test_document.pdf",+ "content_type": "application/pdf",+ "byte_size": 452,+ "text": null,+ "text_status": "unavailable"+ }+ ],+ "attachments_total": 1,+ "attachments_truncated": false,+ "attachments_page": 1,+ "attachments_pages": 1+ },+ "permissions": {+ "is_account_admin": false,+ "tickets": {+ "read": true,+ "write": true+ },+ "documents": {+ "read": false,+ "write": false+ },+ "posts": {+ "can_create": true,+ "can_update_own": true,+ "can_destroy_own": true+ },+ "time_sessions": {+ "can_view_own": true,+ "can_view_all": false,+ "can_create_own": true,+ "can_edit_own": true,+ "can_edit_all": false,+ "can_delete_own": true,+ "can_delete_all": false+ },+ "activities": {+ "read": true+ }+ }+ }+ }+ },"show_invalid_paging": {"token": "read","request": {@@ -5098,6 +5330,14 @@"body_text": "Tritt nur in Safari auf.","is_private": false,"attachments_count": 1,+ "attachments": [+ {+ "id": "00000000-0000-4000-8000-000000000053",+ "filename": "test_file.txt",+ "content_type": "text/plain",+ "byte_size": 500+ }+ ],"created_at": "2026-01-05T09:25:00Z","updated_at": "2026-01-05T09:36:00Z"}diff --git a/spec/requests/api/v1/capabilities_spec.rb b/spec/requests/api/v1/capabilities_spec.rbindex 8a6427c..88d9f56 100644--- a/spec/requests/api/v1/capabilities_spec.rb+++ b/spec/requests/api/v1/capabilities_spec.rb@@ -33,7 +33,7 @@ RSpec.describe 'API V1 capabilities', :ci_guard, type: :request doit 'names the API version and the capabilities beside the existing fields' dodata = me(token(read_only: false))- expect(data['api_version']).to eq('1.7.0')+ expect(data['api_version']).to eq('1.8.0')expect(data['capabilities']).to eq(Api::V1::Capabilities.names)expect(data.keys).to include('user', 'token', 'scoped_organisations')enddiff --git a/spec/requests/api/v1/comment_files_spec.rb b/spec/requests/api/v1/comment_files_spec.rbnew file mode 100644index 0000000..f8c865c--- /dev/null+++ b/spec/requests/api/v1/comment_files_spec.rb@@ -0,0 +1,290 @@+# frozen_string_literal: true++require 'rails_helper'++# REST R7: a comment hands out its files wherever a comment is served, on REST and+# on MCP. One payload (Tickets::Serializer#post_payload), and every road to it is+# walked here, so a road that loses the preload or builds its own shape turns red.+#+# The list answers three questions the terminal client builds on. Which file: `id`+# is the PostDocument's, the id the file proxy takes, not the Active Storage+# attachment's that GET /tickets/:id/attachments hands out. What it says about the+# file: name, type and size, never a signed link or the extracted text. Who sees+# it: whoever may read the comment (Post.readable_by), by no second rule.+RSpec.describe 'Comment files in the ticket view', :ci_guard, type: :request do+ let(:organisation) { create(:organisation) }+ let(:role) { create(:role, organisation: organisation) }+ let(:project) { create(:project, organisation: organisation) }++ def member(role_for = role, tickets: 'read_only')+ Prosopite.pause do+ ActsAsTenant.with_tenant(organisation) do+ user = create(:user)+ create(:membership, user: user, organisation: organisation, role: role_for, active: true)+ create(:project_permission, user: user, project: project, tickets_access: tickets) if tickets+ user+ end+ end+ end++ let(:author) { member }+ let(:addressee) { member }+ let(:other) { member }+ let(:admin_role) { Prosopite.pause { ActsAsTenant.with_tenant(organisation) { create(:admin_role, organisation: organisation) } } }+ let(:admin) { member(admin_role, tickets: nil) }+ let(:ticket) { create(:ticket, project: project, organisation: organisation, creator: author) }++ def comment(minute, **attributes)+ create(:post, ticket: ticket, organisation: organisation, user: author, content: "Kommentar #{minute}",+ create_embeddings: false, created_at: 2.hours.ago + minute.minutes, **attributes)+ end++ def file(on, filename, content_type, id: nil)+ document = PostDocument.new(id: id, post: on, organisation: organisation, create_embeddings: false)+ document.post_document_file.attach(io: StringIO.new('Inhalt'), filename: filename,+ content_type: content_type, identify: false)+ document.save!+ document+ end++ # The file with the higher id is made first: the list follows the id, not the+ # order the rows were written in.+ let(:higher_id) { 'ffffffff-ffff-4fff-8fff-ffffffffffff' }+ let(:lower_id) { '00000000-0000-4000-8000-00000000000a' }++ # In order: two files, a private comment with one, no file, one file.+ let!(:comments) do+ Prosopite.pause do+ ActsAsTenant.with_tenant(organisation) do+ with_files = comment(0)+ file(with_files, 'screenshot.png', 'image/png', id: higher_id)+ file(with_files, 'bericht.pdf', 'application/pdf', id: lower_id)+ hidden = comment(1, is_private: true, visible_to_user: addressee)+ file(hidden, 'geheim.txt', 'text/plain')+ empty = comment(2)+ last = comment(3)+ file(last, 'protokoll.txt', 'text/plain')+ { with_files: with_files, hidden: hidden, empty: empty, last: last }+ end+ end+ end++ after { ActsAsTenant.current_tenant = nil }++ def token_for(user)+ Prosopite.pause { create(:personal_access_token, user: user, organisations: [organisation]).token }+ end++ def get_json(user, path, params = {})+ get path, params: params, headers: { 'Authorization' => "Bearer #{token_for(user)}" }+ response.parsed_body+ end++ # Through the whole MCP road: dispatcher, token, tool. The tool's answer is JSON+ # in a text field.+ def mcp_ticket(user, **arguments)+ post '/api/mcp',+ params: { jsonrpc: '2.0', id: 1, method: 'tools/call',+ params: { name: 'get_ticket', arguments: { project_id: project.id, ticket_id: ticket.id, **arguments } } }.to_json,+ headers: { 'Authorization' => "Bearer #{token_for(user)}", 'CONTENT_TYPE' => 'application/json' }+ expect(response).to have_http_status(:ok)+ response.parsed_body.dig('result', 'content', 0, 'text')+ end++ def ticket_path = "/api/v1/tickets/#{ticket.id}"+ def number_path = "/api/v1/projects/#{project.id}/tickets/number/#{ticket.number}"+ def comment_path(key) = "#{ticket_path}/posts/#{comments.fetch(key).id}"++ def listed_on(posts, key)+ posts.find { |entry| entry['id'] == comments.fetch(key).id }&.fetch('attachments')+ end++ def filenames(posts)+ posts.flat_map { |entry| entry['attachments'].pluck('filename') }+ end++ def proxy_get(id)+ get organisation_file_download_path(organisation_id: organisation.id, kind: 'post_document', id: id)+ end++ let(:both_files) do+ [{ 'id' => lower_id, 'filename' => 'bericht.pdf', 'content_type' => 'application/pdf', 'byte_size' => 6 },+ { 'id' => higher_id, 'filename' => 'screenshot.png', 'content_type' => 'image/png', 'byte_size' => 6 }]+ end++ describe 'on every road to a comment' do+ it 'lists them on the whole ticket, in id order, with nothing but these four fields' do+ posts = get_json(other, ticket_path).dig('data', 'posts')+ expect(listed_on(posts, :with_files)).to eq(both_files)+ end++ it 'lists them on a page of the ticket' do+ posts = get_json(other, ticket_path, { posts_per_page: 1 }).dig('data', 'posts')+ expect(listed_on(posts, :with_files)).to eq(both_files)+ end++ it 'lists them on the ticket by number' do+ posts = get_json(other, number_path).dig('data', 'posts')+ expect(listed_on(posts, :with_files)).to eq(both_files)+ end++ it 'lists them on a page of the ticket by number' do+ posts = get_json(other, number_path, { posts_order: 'newest', posts_per_page: 3 }).dig('data', 'posts')+ expect(listed_on(posts, :with_files)).to eq(both_files)+ end++ it 'lists them on one comment' do+ expect(get_json(other, comment_path(:with_files)).dig('data', 'attachments')).to eq(both_files)+ end++ it 'lists them on MCP get_ticket' do+ expect(listed_on(JSON.parse(mcp_ticket(other))['posts'], :with_files)).to eq(both_files)+ end++ it 'lists them on one comment of MCP get_ticket' do+ answer = JSON.parse(mcp_ticket(other, post_id: comments[:with_files].id))+ expect(listed_on(answer['posts'], :with_files)).to eq(both_files)+ end++ it 'answers an empty list for a comment without files, beside its count' do+ body = get_json(other, comment_path(:empty))+ expect(body['data'].slice('attachments', 'attachments_count')).to eq('attachments' => [], 'attachments_count' => 0)+ end++ it 'keeps the ticket files apart: a page of them holds no file of a comment' do+ body = get_json(other, ticket_path, { attachments_page: 1 })['data']+ expect(body['attachments']).to eq([])+ expect(listed_on(body['posts'], :with_files)).to eq(both_files)+ end+ end++ describe 'the id' do+ it 'opens the file through the proxy, for the person who read the list' do+ id = get_json(other, comment_path(:with_files)).dig('data', 'attachments', 0, 'id')+ sign_in other+ proxy_get(id)+ expect(response).to have_http_status(:ok)+ expect(response.body).to eq('Inhalt')+ end++ it 'is not the id the attachments route hands out' do+ token = token_for(other)+ get "#{ticket_path}/attachments", headers: { 'Authorization' => "Bearer #{token}" }+ routed = response.parsed_body['data'].find { |entry| entry['filename'] == 'bericht.pdf' }+ expect(routed['id']).not_to eq(lower_id)+ sign_in other+ proxy_get(routed['id'])+ expect(response).to have_http_status(:not_found)+ end+ end++ describe 'a file of a private comment' do+ let(:hidden_file) { ActsAsTenant.with_tenant(organisation) { comments[:hidden].post_documents.first } }++ # One example per reader: Prosopite watches each request on its own.+ %i[author addressee admin].each do |reader|+ it "is listed for the #{reader}, with the comment" do+ posts = get_json(public_send(reader), ticket_path).dig('data', 'posts')+ expect(listed_on(posts, :hidden).pluck('filename')).to eq(['geheim.txt'])+ end++ it "opens through the proxy for the #{reader}" do+ sign_in public_send(reader)+ proxy_get(hidden_file.id)+ expect(response).to have_http_status(:ok)+ end+ end++ # Each list is shown to be there, with the public files on it, so an absent+ # name means the filter worked and not that the answer was empty.+ context 'for a member who may not read the comment' do+ let(:public_names) { %w[bericht.pdf screenshot.png protokoll.txt] }++ it 'is missing from the whole ticket' do+ posts = get_json(other, ticket_path).dig('data', 'posts')+ expect(filenames(posts)).to eq(public_names)+ expect(response.body).not_to include('geheim.txt')+ end++ it 'is missing from a page, and from its count' do+ data = get_json(other, ticket_path, { posts_page: 1 })['data']+ expect(filenames(data['posts'])).to eq(public_names)+ expect(data['posts_total']).to eq(3)+ expect(response.body).not_to include('geheim.txt')+ end++ it 'is missing from the ticket by number' do+ posts = get_json(other, number_path).dig('data', 'posts')+ expect(filenames(posts)).to eq(public_names)+ expect(response.body).not_to include('geheim.txt')+ end++ it 'is missing from MCP get_ticket' do+ answer = mcp_ticket(other)+ expect(filenames(JSON.parse(answer)['posts'])).to eq(public_names)+ expect(answer).not_to include('geheim.txt')+ end++ it 'answers its comment as not found' do+ get_json(other, comment_path(:hidden))+ expect(response).to have_http_status(:not_found)+ expect(response.body).not_to include('geheim.txt')+ end++ it 'answers its comment on MCP as not found' do+ expect(mcp_ticket(other, post_id: comments[:hidden].id)).to start_with('No comment found')+ expect(response.body).not_to include('geheim.txt')+ end++ it 'does not open through the proxy, known id or not' do+ sign_in other+ proxy_get(hidden_file.id)+ expect(response).to have_http_status(:not_found)+ end+ end+ end++ describe 'a document that lost its blob' do+ before do+ Prosopite.pause do+ ActsAsTenant.with_tenant(organisation) do+ ActiveStorage::Attachment.where(record_type: 'PostDocument', record_id: higher_id).delete_all+ end+ end+ end++ it 'is dropped from the list and stays in the count' do+ data = get_json(other, comment_path(:with_files))['data']+ expect(data['attachments']).to eq(both_files.first(1))+ expect(data['attachments_count']).to eq(2)+ end++ it 'is dropped from the list of MCP get_ticket and stays in the count' do+ entry = JSON.parse(mcp_ticket(other))['posts'].first+ expect(entry['attachments']).to eq(both_files.first(1))+ expect(entry['attachments_count']).to eq(2)+ end+ end++ # Prosopite watches every example here, and four files on three comments are+ # enough for it to speak. This one says what it would only imply: one read of+ # each table for a whole page.+ describe 'the reads behind the list' do+ def sql_during(&)+ statements = []+ counter = ->(*, payload) { statements << payload[:sql] }+ ActiveSupport::Notifications.subscribed(counter, 'sql.active_record', &)+ statements+ end++ it 'read the attachment rows and the blobs once for a page of comments' do+ token = token_for(admin)+ statements = sql_during do+ get ticket_path, params: { posts_page: 1 }, headers: { 'Authorization' => "Bearer #{token}" }+ end+ expect(response.parsed_body.dig('data', 'posts').sum { |entry| entry['attachments'].size }).to eq(4)+ expect(statements.grep(/FROM "active_storage_attachments"/).size).to eq(1)+ expect(statements.grep(/FROM "active_storage_blobs"/).size).to eq(1)+ end+ end+enddiff --git a/spec/services/tickets/serializer_spec.rb b/spec/services/tickets/serializer_spec.rbindex 71aee7b..bfef5a1 100644--- a/spec/services/tickets/serializer_spec.rb+++ b/spec/services/tickets/serializer_spec.rb@@ -122,7 +122,21 @@ RSpec.describe Tickets::Serializer doexpect(hash[:posts].size).to eq(1)expect(hash[:posts].first.keys).to contain_exactly(- :id, :author, :body_html, :body_text, :is_private, :attachments_count, :created_at, :updated_at+ :id, :author, :body_html, :body_text, :is_private, :attachments_count, :attachments, :created_at, :updated_at+ )+ end++ # What a comment says about its file: no signed URL, no extracted text. Pinned+ # with text in the column, which is what #attachments would hand on.+ it 'pins the key set of a comment file, by the id of its PostDocument' do+ document, hash = ActsAsTenant.with_tenant(organisation) do+ post = create(:post, ticket: ticket, user: viewer, is_private: false)+ made = create(:post_document, :with_pdf, post: post, organisation: organisation, plain_text_version: 'Inhalt')+ [made, serializer.full(ticket)]+ end++ expect(hash[:posts].first[:attachments]).to eq(+ [{ id: document.id, filename: 'test_document.pdf', content_type: 'application/pdf', byte_size: 25 }])end