From caca8f34ffb56aed98a7894c98af6c4d1a5de78f Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Tue, 3 Apr 2018 13:35:26 +0200 Subject: 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. --- .../unreleased/zj-feature-gate-remove-http-api.yml | 5 +++ doc/api/features.md | 8 ++++ lib/api/features.rb | 7 ++++ spec/requests/api/features_spec.rb | 43 +++++++++++++++++++++- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/zj-feature-gate-remove-http-api.yml diff --git a/changelogs/unreleased/zj-feature-gate-remove-http-api.yml b/changelogs/unreleased/zj-feature-gate-remove-http-api.yml new file mode 100644 index 00000000000..2095f60146c --- /dev/null +++ b/changelogs/unreleased/zj-feature-gate-remove-http-api.yml @@ -0,0 +1,5 @@ +--- +title: Allow feature gates to be removed through the API +merge_request: +author: +type: added diff --git a/doc/api/features.md b/doc/api/features.md index 6861dbf00a2..6ee1c36ef5b 100644 --- a/doc/api/features.md +++ b/doc/api/features.md @@ -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 +``` diff --git a/lib/api/features.rb b/lib/api/features.rb index 9385c6ca174..11d848584d9 100644 --- a/lib/api/features.rb +++ b/lib/api/features.rb @@ -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 diff --git a/spec/requests/api/features_spec.rb b/spec/requests/api/features_spec.rb index 267058d98ee..c5354c2d639 100644 --- a/spec/requests/api/features_spec.rb +++ b/spec/requests/api/features_spec.rb @@ -1,8 +1,8 @@ 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 -- cgit v1.2.1