Commit 0d4c2f98 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'delete-custom-value-stream' into 'master'

Enable to delete a value stream

See merge request gitlab-org/gitlab!40127
parents 0a37ccf8 c5ead91f
......@@ -24,6 +24,17 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Analytics::App
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
def value_stream_params
......
......@@ -7,4 +7,8 @@ class Analytics::CycleAnalytics::GroupValueStream < ApplicationRecord
validates :group, :name, presence: true
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
......@@ -4,6 +4,9 @@ module Analytics
class GroupValueStreamEntity < Grape::Entity
expose :name
expose :id
expose :is_custom do |object|
object.custom?
end
private
......
---
title: Enable to delete a custom value stream
merge_request: 40127
author:
type: added
......@@ -39,7 +39,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
get :records
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
member do
get :duration_chart
......
......@@ -62,4 +62,33 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do
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
{
"type": "object",
"required": ["name", "id"],
"required": ["name", "id", "is_custom"],
"properties": {
"id": {
"type": ["integer", "string"]
},
"name": {
"type": "string"
},
"is_custom": {
"type": "boolean"
}
},
"additionalProperties": false
......
......@@ -27066,6 +27066,9 @@ msgstr ""
msgid "ValueStreamAnalytics|Median time from issue created to issue closed."
msgstr ""
msgid "ValueStream|The Default Value Stream cannot be deleted"
msgstr ""
msgid "Variable"
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