Commit c5ead91f authored by Magdalena Frankiewicz's avatar Magdalena Frankiewicz Committed by Vitali Tatarintev

Enable to delete a value stream

But only if it is not default value stream
Expose is_custom field on value stream
parent 56ce8920
...@@ -24,6 +24,17 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Analytics::App ...@@ -24,6 +24,17 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Analytics::App
end end
end end
def destroy
value_stream = @group.value_streams.find(params[:id])
if value_stream.custom?
value_stream.delete
render json: {}, status: :ok
else
render json: { message: s_('ValueStream|The Default Value Stream cannot be deleted') }, status: :unprocessable_entity
end
end
private private
def value_stream_params def value_stream_params
......
...@@ -7,4 +7,8 @@ class Analytics::CycleAnalytics::GroupValueStream < ApplicationRecord ...@@ -7,4 +7,8 @@ class Analytics::CycleAnalytics::GroupValueStream < ApplicationRecord
validates :group, :name, presence: true validates :group, :name, presence: true
validates :name, length: { minimum: 3, maximum: 100, allow_nil: false }, uniqueness: { scope: :group_id } validates :name, length: { minimum: 3, maximum: 100, allow_nil: false }, uniqueness: { scope: :group_id }
def custom?
name != Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME
end
end end
...@@ -4,6 +4,9 @@ module Analytics ...@@ -4,6 +4,9 @@ module Analytics
class GroupValueStreamEntity < Grape::Entity class GroupValueStreamEntity < Grape::Entity
expose :name expose :name
expose :id expose :id
expose :is_custom do |object|
object.custom?
end
private private
......
---
title: Enable to delete a custom value stream
merge_request: 40127
author:
type: added
...@@ -39,7 +39,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do ...@@ -39,7 +39,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
get :records get :records
end end
end end
resources :value_streams, only: [:index, :create] do resources :value_streams, only: [:index, :create, :destroy] do
resources :stages, only: [:index, :create, :update, :destroy] do resources :stages, only: [:index, :create, :update, :destroy] do
member do member do
get :duration_chart get :duration_chart
......
...@@ -62,4 +62,33 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do ...@@ -62,4 +62,33 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do
end end
end end
end end
describe 'DELETE #destroy' do
def destroy_value_stream
delete :destroy, params: { group_id: group, id: value_stream }
end
context 'when it is a default value stream' do
let!(:value_stream) { create(:cycle_analytics_group_value_stream, group: group, name: 'default') }
it 'returns an unprocessable entity 422 response without deleting the value stream' do
expect { destroy_value_stream }.not_to change { Analytics::CycleAnalytics::GroupValueStream.count }
expect(response).to have_gitlab_http_status(:unprocessable_entity)
expect(json_response["message"]).to eq('The Default Value Stream cannot be deleted')
end
end
context 'when it is a custom value stream' do
let!(:value_stream) { create(:cycle_analytics_group_value_stream, group: group, name: 'some custom value stream') }
let!(:stage) { create(:cycle_analytics_group_stage, value_stream: value_stream) }
it 'deletes the value stream and its stages, and returns a successful 200 response' do
expect { destroy_value_stream }.to change { Analytics::CycleAnalytics::GroupValueStream.count }.by(-1)
.and change { Analytics::CycleAnalytics::GroupStage.where(value_stream: value_stream).count }.from(1).to(0)
expect(response).to have_gitlab_http_status(:ok)
end
end
end
end end
{ {
"type": "object", "type": "object",
"required": ["name", "id"], "required": ["name", "id", "is_custom"],
"properties": { "properties": {
"id": { "id": {
"type": ["integer", "string"] "type": ["integer", "string"]
}, },
"name": { "name": {
"type": "string" "type": "string"
},
"is_custom": {
"type": "boolean"
} }
}, },
"additionalProperties": false "additionalProperties": false
......
...@@ -27066,6 +27066,9 @@ msgstr "" ...@@ -27066,6 +27066,9 @@ msgstr ""
msgid "ValueStreamAnalytics|Median time from issue created to issue closed." msgid "ValueStreamAnalytics|Median time from issue created to issue closed."
msgstr "" msgstr ""
msgid "ValueStream|The Default Value Stream cannot be deleted"
msgstr ""
msgid "Variable" msgid "Variable"
msgstr "" msgstr ""
......
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