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
Answer a parent_id on the ticket PATCH instead of dropping it
Guido Boyke6ebe279f7caa
diff --git a/CLAUDE.md b/CLAUDE.mdindex bf0a934..d5d7be7 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -942,7 +942,10 @@ the de and en keys are three lists kept by hand; the guard holds them together).`change[add_assignee_ids]` and `change[remove_assignee_ids]` (at most 50 each, `"me"` is the tokenowner) against the current list. The kind is decided by the keys present, not their values. Itanswers 200 with the ticket summary, like `PATCH /tickets/:id`, which stays as it is: its-`assignee_ids` REPLACE the list, and `gboyke/lalabase-mcp` relies on that. Status and assignees+`assignee_ids` REPLACE the list, and `gboyke/lalabase-mcp` relies on that. `parent_id` on that+PATCH reaches the model (`Ticket#parent_unchanged`, a saved ticket keeps its parent): another+parent or an empty value is a 422 `validation_failed`/`invalid_input`, the current parent is no+change, so a client may send back what it read. Status and assigneesgo through `Actors::ApplyTicketChanges` like a board drag (a `TicketBulkRun` included), the titlethrough `Actors::SaveTicket` alone under a lock on the row in its project, so the side effects arethe web's and MCP's, once. Order: read-only token 403, then the read gate (missing, malformed,diff --git a/app/controllers/api/v1/tickets_controller.rb b/app/controllers/api/v1/tickets_controller.rbindex 21e1be2..0b2dffe 100644--- a/app/controllers/api/v1/tickets_controller.rb+++ b/app/controllers/api/v1/tickets_controller.rb@@ -93,7 +93,9 @@ module Apiend# PATCH /api/v1/tickets/:id- # Allowed fields: status, assignee_ids (replace semantics).+ # Allowed fields: status, assignee_ids (replace semantics). parent_id passes through so+ # the model answers it (Ticket#parent_unchanged): another parent is a 422, the current+ # one is no change, and nothing is dropped silently.def updatewith_readable_ticket(params[:id]) do |ticket, project|authorize ticket, :update?@@ -241,12 +243,12 @@ module Api# --- Update helpers --------------------------------------------------def update_params- permitted = params.require(:ticket).permit(:status, assignee_ids: [])+ permitted = params.require(:ticket).permit(:status, :parent_id, assignee_ids: [])# Use to_h.symbolize_keys so we can introspect with .key?permitted.to_h.symbolize_keysend- # Maps the API update whitelist (status, assignee_ids) onto SaveTicket params.+ # Maps the API update whitelist (status, assignee_ids, parent_id) onto SaveTicket params.# status is merged into custom_attributes (preserving the other keys), as the# previous apply_status_change did. assignee_ids is forwarded only when the# client sent the key, so a status-only update leaves assignees untouched@@ -256,6 +258,7 @@ module Apimapped = {}mapped[:custom_attributes] = (ticket.custom_attributes || {}).merge('status' => attrs[:status].to_s) if attrs.key?(:status)mapped[:assignee_ids] = attrs[:assignee_ids] if attrs.key?(:assignee_ids)+ mapped[:parent_id] = attrs[:parent_id].presence if attrs.key?(:parent_id)mappedenddiff --git a/spec/requests/api/v1/write_endpoints_spec.rb b/spec/requests/api/v1/write_endpoints_spec.rbindex 0ef315b..0b0ae06 100644--- a/spec/requests/api/v1/write_endpoints_spec.rb+++ b/spec/requests/api/v1/write_endpoints_spec.rb@@ -419,6 +419,56 @@ RSpec.describe 'API V1 Write Endpoints', :ci_guard, type: :request do# PATCH /api/v1/tickets/:id (status + assignees)# ------------------------------------------------------------------describe 'PATCH /api/v1/tickets/:id' do+ # Ticket#parent_unchanged decides, as on the web: a client that names another parent hears+ # no, and one that sends back the parent_id it just read has changed nothing.+ context 'with a parent_id' do+ let(:child) do+ ActsAsTenant.with_tenant(organisation) do+ create(:ticket, project: project, organisation: organisation, creator: user, parent: ticket)+ end+ end+ let(:other) do+ ActsAsTenant.with_tenant(organisation) do+ create(:ticket, project: project, organisation: organisation, creator: user)+ end+ end++ def parent_id_of(record)+ ActsAsTenant.with_tenant(organisation) { record.reload.parent_id }+ end++ it 'refuses another parent, says so and changes nothing' do+ patch "/api/v1/tickets/#{child.id}", params: { ticket: { parent_id: other.id } }, headers: auth_headers++ expect(response).to have_http_status(:unprocessable_content)+ body = response.parsed_body+ expect(body).to include('error' => 'validation_failed', 'code' => 'invalid_input')+ expect(body['errors'].join).to include(I18n.t('activerecord.errors.models.ticket.attributes.parent_id.cannot_change'))+ expect(parent_id_of(child)).to eq(ticket.id)+ end++ it 'refuses a parent for a top-level ticket' do+ patch "/api/v1/tickets/#{other.id}", params: { ticket: { parent_id: ticket.id } }, headers: auth_headers++ expect(response).to have_http_status(:unprocessable_content)+ expect(parent_id_of(other)).to be_nil+ end++ it 'refuses clearing the parent with an empty value' do+ patch "/api/v1/tickets/#{child.id}", params: { ticket: { parent_id: '' } }, headers: auth_headers++ expect(response).to have_http_status(:unprocessable_content)+ expect(parent_id_of(child)).to eq(ticket.id)+ end++ it 'accepts the parent the ticket already has' do+ patch "/api/v1/tickets/#{child.id}", params: { ticket: { parent_id: ticket.id } }, headers: auth_headers++ expect(response).to have_http_status(:ok)+ expect(parent_id_of(child)).to eq(ticket.id)+ end+ end+it 'updates the status' dopatch "/api/v1/tickets/#{ticket.id}",params: { ticket: { status: 'in_progress' } },