Commit fbe9a501 authored by Adam Hegyi's avatar Adam Hegyi

Fix updating value stream record without stages

This change fixes the 404 error when updating value stream record
without persisted stages.
parent e5dfb288
...@@ -23,7 +23,7 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Groups::Analyt ...@@ -23,7 +23,7 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Groups::Analyt
end end
def update def update
value_stream = Analytics::CycleAnalytics::GroupValueStream.find(params[:id]) value_stream = @group.value_streams.find(params[:id])
result = Analytics::CycleAnalytics::ValueStreams::UpdateService.new(group: @group, params: update_params, current_user: current_user, value_stream: value_stream).execute result = Analytics::CycleAnalytics::ValueStreams::UpdateService.new(group: @group, params: update_params, current_user: current_user, value_stream: value_stream).execute
if result.success? if result.success?
......
...@@ -37,6 +37,7 @@ module Analytics ...@@ -37,6 +37,7 @@ module Analytics
raw_params[:stages_attributes] = raw_params.delete(:stages) || [] raw_params[:stages_attributes] = raw_params.delete(:stages) || []
raw_params[:stages_attributes].map! { |attrs| build_stage_attributes(attrs) } raw_params[:stages_attributes].map! { |attrs| build_stage_attributes(attrs) }
remove_in_memory_stage_ids!(raw_params[:stages_attributes])
set_relative_positions!(raw_params[:stages_attributes]) set_relative_positions!(raw_params[:stages_attributes])
raw_params raw_params
...@@ -44,7 +45,7 @@ module Analytics ...@@ -44,7 +45,7 @@ module Analytics
def build_stage_attributes(stage_attributes) def build_stage_attributes(stage_attributes)
stage_attributes[:group] = group stage_attributes[:group] = group
return stage_attributes if stage_attributes[:custom] return stage_attributes if Gitlab::Utils.to_boolean(stage_attributes[:custom])
# if we're persisting a default stage, ignore the user provided attributes and use our attributes # if we're persisting a default stage, ignore the user provided attributes and use our attributes
use_default_stage_params(stage_attributes) use_default_stage_params(stage_attributes)
...@@ -71,6 +72,14 @@ module Analytics ...@@ -71,6 +72,14 @@ module Analytics
stage_attribute[:relative_position] = increment * i stage_attribute[:relative_position] = increment * i
end end
end end
def remove_in_memory_stage_ids!(stage_attributes)
stage_attributes.each do |stage_attribute|
if Gitlab::Analytics::CycleAnalytics::DefaultStages.names.include?(stage_attribute[:id])
stage_attribute.delete(:id)
end
end
end
end end
end end
end end
......
---
title: Fix updating value stream without persisted stages
merge_request: 59176
author:
type: fixed
...@@ -111,6 +111,28 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do ...@@ -111,6 +111,28 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do
expect(json_response['name']).to eq('new name') expect(json_response['name']).to eq('new name')
end end
context 'when updating value stream with in-memory stages' do
let(:value_stream_params) do
{
name: 'updated name',
stages: [
{
id: 'issue', # in memory stage
name: 'issue',
custom: false
}
]
}
end
it 'returns a successful 200 response' do
put :update, params: { id: value_stream.id, group_id: group, value_stream: value_stream_params }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['name']).to eq('updated name')
end
end
context 'with stages' do context 'with stages' do
let!(:stage) { create(:cycle_analytics_group_stage, group: group, value_stream: value_stream, name: 'stage 1', custom: true) } let!(:stage) { create(:cycle_analytics_group_stage, group: group, value_stream: value_stream, name: 'stage 1', custom: true) }
......
...@@ -70,7 +70,7 @@ RSpec.describe Analytics::CycleAnalytics::ValueStreams::CreateService do ...@@ -70,7 +70,7 @@ RSpec.describe Analytics::CycleAnalytics::ValueStreams::CreateService do
context 'when creating a default stage' do context 'when creating a default stage' do
before do before do
params[:stages] = [{ name: 'plan', custom: false }] params[:stages] = [{ id: 'plan', name: 'plan', custom: false }]
end end
let(:custom_stage) { subject.payload[:value_stream].stages.first } let(:custom_stage) { subject.payload[:value_stream].stages.first }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment