Commit d12c12cc authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'ff-update-name-put' into 'master'

Support Renaming a Feature Flag via the API

Closes #233026

See merge request gitlab-org/gitlab!38425
parents 8d75358f 96ba4573
......@@ -96,13 +96,13 @@ Example response:
Gets a single feature flag.
```plaintext
GET /projects/:id/feature_flags/:name
GET /projects/:id/feature_flags/:feature_flag_name
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding). |
| `name` | string | yes | The name of the feature flag. |
| `feature_flag_name` | string | yes | The name of the feature flag. |
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature
......@@ -201,15 +201,16 @@ Example response:
Updates a feature flag.
```plaintext
PUT /projects/:id/feature_flags/:name
PUT /projects/:id/feature_flags/:feature_flag_name
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding). |
| `name` | string | yes | The name of the feature flag. |
| `feature_flag_name` | string | yes | The current name of the feature flag. |
| `description` | string | no | The description of the feature flag. |
| `active` | boolean | no | The active state of the flag. [Supported](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350) in GitLab 13.3 and later. |
| `name` | string | no | The new name of the feature flag. [Supported](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350) in GitLab 13.3 and later. |
| `strategies` | JSON | no | The feature flag [strategies](../operations/feature_flags.md#feature-flag-strategies). |
| `strategies:id` | JSON | no | The feature flag strategy id. |
| `strategies:name` | JSON | no | The strategy name. |
......@@ -275,13 +276,13 @@ Example response:
Deletes a feature flag.
```plaintext
DELETE /projects/:id/feature_flags/:name
DELETE /projects/:id/feature_flags/:feature_flag_name
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding). |
| `name` | string | yes | The name of the feature flag. |
| `feature_flag_name` | string | yes | The name of the feature flag. |
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" --request DELETE "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"
......
---
title: Support renaming feature flags via the api
merge_request: 38425
author:
type: fixed
......@@ -81,9 +81,9 @@ module API
end
params do
requires :name, type: String, desc: 'The name of the feature flag'
requires :feature_flag_name, type: String, desc: 'The name of the feature flag'
end
resource 'feature_flags/:name', requirements: FEATURE_FLAG_ENDPOINT_REQUIREMENTS do
resource 'feature_flags/:feature_flag_name', requirements: FEATURE_FLAG_ENDPOINT_REQUIREMENTS do
desc 'Get a feature flag of a project' do
detail 'This feature was introduced in GitLab 12.5'
success EE::API::Entities::FeatureFlag
......@@ -145,6 +145,7 @@ module API
success EE::API::Entities::FeatureFlag
end
params do
optional :name, type: String, desc: 'The name of the feature flag'
optional :description, type: String, desc: 'The description of the feature flag'
optional :active, type: Boolean, desc: 'Active/inactive value of the flag'
optional :strategies, type: Array do
......@@ -237,9 +238,9 @@ module API
def feature_flag
@feature_flag ||= if feature_flags_new_version_enabled?
user_project.operations_feature_flags.find_by_name!(params[:name])
user_project.operations_feature_flags.find_by_name!(params[:feature_flag_name])
else
user_project.operations_feature_flags.legacy_flag.find_by_name!(params[:name])
user_project.operations_feature_flags.legacy_flag.find_by_name!(params[:feature_flag_name])
end
end
......
......@@ -816,6 +816,17 @@ RSpec.describe API::FeatureFlags do
expect(feature_flag.reload.active).to eq(false)
end
it 'updates the feature flag name' do
params = { name: 'new-name' }
put api("/projects/#{project.id}/feature_flags/feature1", user), params: params
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/feature_flag', dir: 'ee')
expect(json_response['name']).to eq('new-name')
expect(feature_flag.reload.name).to eq('new-name')
end
it 'ignores a provided version parameter' do
params = { description: 'other description', version: 'bad_value' }
......
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