BigW Consortium Gitlab

Allow feature gate removal through the API

Features could be listed and added through the api, now also removed. This was needed in the case of gitlab.com as the number of gates that were ever used just grows and cleaning up is hard.
parent 8dca091f
---
title: Allow feature gates to be removed through the API
merge_request:
author:
type: added
......@@ -86,3 +86,11 @@ Example response:
]
}
```
## Delete a feature
Removes a feature gate. Response is equal when the gate exists, or doesn't.
```
DELETE /features/:name
```
......@@ -65,6 +65,13 @@ module API
present feature, with: Entities::Feature, current_user: current_user
end
desc 'Remove the gate value for the given feature'
delete ':name' do
Feature.get(params[:name]).remove
status 204
end
end
end
end
require 'spec_helper'
describe API::Features do
let(:user) { create(:user) }
let(:admin) { create(:admin) }
set(:user) { create(:user) }
set(:admin) { create(:admin) }
before do
Flipper.unregister_groups
......@@ -249,4 +249,43 @@ describe API::Features do
end
end
end
describe 'DELETE /feature/:name' do
let(:feature_name) { 'my_feature' }
context 'when the user has no access' do
it 'returns a 401 for anonymous users' do
delete api("/features/#{feature_name}")
expect(response).to have_gitlab_http_status(401)
end
it 'returns a 403 for users' do
delete api("/features/#{feature_name}", user)
expect(response).to have_gitlab_http_status(403)
end
end
context 'when the user has access' do
it 'returns 204 when the value is not set' do
delete api("/features/#{feature_name}", admin)
expect(response).to have_gitlab_http_status(204)
end
context 'when the gate value was set' do
before do
Feature.get(feature_name).enable
end
it 'deletes an enabled feature' do
delete api("/features/#{feature_name}", admin)
expect(response).to have_gitlab_http_status(204)
expect(Feature.get(feature_name)).not_to be_enabled
end
end
end
end
end
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