Commit 4c9e2831 authored by Jason Goodman's avatar Jason Goodman Committed by Shinya Maeda

Route feature flags based on internal id

Add spec for routing
parent 68d82ed0
---
title: Route to feature flags based on internal id
merge_request: 29740
author:
type: added
...@@ -96,9 +96,9 @@ class Projects::FeatureFlagsController < Projects::ApplicationController ...@@ -96,9 +96,9 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
def feature_flag def feature_flag
@feature_flag ||= if new_version_feature_flags_enabled? @feature_flag ||= if new_version_feature_flags_enabled?
project.operations_feature_flags.find(params[:id]) project.operations_feature_flags.find_by_iid!(params[:iid])
else else
project.operations_feature_flags.legacy_flag.find(params[:id]) project.operations_feature_flags.legacy_flag.find_by_iid!(params[:iid])
end end
end end
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
module Operations module Operations
class FeatureFlag < ApplicationRecord class FeatureFlag < ApplicationRecord
include AtomicInternalId include AtomicInternalId
include IidRoutes
self.table_name = 'operations_feature_flags' self.table_name = 'operations_feature_flags'
......
...@@ -26,7 +26,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -26,7 +26,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end end
end end
resources :feature_flags resources :feature_flags, param: :iid
resource :feature_flags_client, only: [] do resource :feature_flags_client, only: [] do
post :reset_token post :reset_token
end end
......
...@@ -250,7 +250,7 @@ describe Projects::FeatureFlagsController do ...@@ -250,7 +250,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id iid: feature_flag.iid
} }
end end
...@@ -266,6 +266,41 @@ describe Projects::FeatureFlagsController do ...@@ -266,6 +266,41 @@ describe Projects::FeatureFlagsController do
is_expected.to match_response_schema('feature_flag', dir: 'ee') is_expected.to match_response_schema('feature_flag', dir: 'ee')
end end
it 'routes based on iid' do
other_project = create(:project)
other_project.add_developer(user)
other_feature_flag = create(:operations_feature_flag, project: other_project,
name: 'other_flag')
params = {
namespace_id: other_project.namespace,
project_id: other_project,
iid: other_feature_flag.iid
}
get(:show, params: params, format: :json)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['name']).to eq(other_feature_flag.name)
end
it 'routes based on iid when new version flags are disabled' do
stub_feature_flags(feature_flags_new_version: false)
other_project = create(:project)
other_project.add_developer(user)
other_feature_flag = create(:operations_feature_flag, project: other_project,
name: 'other_flag')
params = {
namespace_id: other_project.namespace,
project_id: other_project,
iid: other_feature_flag.iid
}
get(:show, params: params, format: :json)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['name']).to eq(other_feature_flag.name)
end
context 'when feature flag is not found' do context 'when feature flag is not found' do
let!(:feature_flag) { } let!(:feature_flag) { }
...@@ -273,7 +308,7 @@ describe Projects::FeatureFlagsController do ...@@ -273,7 +308,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: 1 iid: 1
} }
end end
...@@ -339,7 +374,7 @@ describe Projects::FeatureFlagsController do ...@@ -339,7 +374,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: new_version_feature_flag.id iid: new_version_feature_flag.iid
} }
end end
...@@ -738,7 +773,7 @@ describe Projects::FeatureFlagsController do ...@@ -738,7 +773,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id iid: feature_flag.iid
} }
end end
...@@ -771,7 +806,7 @@ describe Projects::FeatureFlagsController do ...@@ -771,7 +806,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: 0 iid: 0
} }
end end
...@@ -794,7 +829,7 @@ describe Projects::FeatureFlagsController do ...@@ -794,7 +829,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: new_version_flag.id iid: new_version_flag.iid
} }
end end
...@@ -827,7 +862,7 @@ describe Projects::FeatureFlagsController do ...@@ -827,7 +862,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
name: 'ci_new_live_trace' name: 'ci_new_live_trace'
} }
...@@ -853,7 +888,7 @@ describe Projects::FeatureFlagsController do ...@@ -853,7 +888,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
active: false active: false
} }
...@@ -877,7 +912,7 @@ describe Projects::FeatureFlagsController do ...@@ -877,7 +912,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { active: true } operations_feature_flag: { active: true }
} }
put(:update, params: params, format: :json) put(:update, params: params, format: :json)
...@@ -903,7 +938,7 @@ describe Projects::FeatureFlagsController do ...@@ -903,7 +938,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
scopes_attributes: [{ environment_scope: 'production', active: false }] scopes_attributes: [{ environment_scope: 'production', active: false }]
} }
...@@ -923,7 +958,7 @@ describe Projects::FeatureFlagsController do ...@@ -923,7 +958,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
scopes_attributes: [{ environment_scope: '*', active: false }] scopes_attributes: [{ environment_scope: '*', active: false }]
} }
...@@ -940,7 +975,7 @@ describe Projects::FeatureFlagsController do ...@@ -940,7 +975,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
scopes_attributes: [ scopes_attributes: [
{ {
...@@ -966,7 +1001,7 @@ describe Projects::FeatureFlagsController do ...@@ -966,7 +1001,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
scopes_attributes: [ scopes_attributes: [
{ {
...@@ -988,7 +1023,7 @@ describe Projects::FeatureFlagsController do ...@@ -988,7 +1023,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
scopes_attributes: [ scopes_attributes: [
{ {
...@@ -1011,7 +1046,7 @@ describe Projects::FeatureFlagsController do ...@@ -1011,7 +1046,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
scopes_attributes: [ scopes_attributes: [
{ {
...@@ -1037,7 +1072,7 @@ describe Projects::FeatureFlagsController do ...@@ -1037,7 +1072,7 @@ describe Projects::FeatureFlagsController do
{ {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
scopes_attributes: [ scopes_attributes: [
{ {
...@@ -1163,7 +1198,7 @@ describe Projects::FeatureFlagsController do ...@@ -1163,7 +1198,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
scopes_attributes: [{ id: scope.id }] scopes_attributes: [{ id: scope.id }]
} }
...@@ -1187,7 +1222,7 @@ describe Projects::FeatureFlagsController do ...@@ -1187,7 +1222,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: feature_flag.id, iid: feature_flag.iid,
operations_feature_flag: { operations_feature_flag: {
scopes_attributes: [{ id: scope.id }] scopes_attributes: [{ id: scope.id }]
} }
...@@ -1229,7 +1264,7 @@ describe Projects::FeatureFlagsController do ...@@ -1229,7 +1264,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: new_version_flag.id, iid: new_version_flag.iid,
operations_feature_flag: { operations_feature_flag: {
strategies_attributes: [{ strategies_attributes: [{
name: 'userWithId', name: 'userWithId',
...@@ -1259,7 +1294,7 @@ describe Projects::FeatureFlagsController do ...@@ -1259,7 +1294,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: new_version_flag.id, iid: new_version_flag.iid,
operations_feature_flag: { operations_feature_flag: {
strategies_attributes: [{ strategies_attributes: [{
name: 'gradualRolloutUserId', name: 'gradualRolloutUserId',
...@@ -1286,7 +1321,7 @@ describe Projects::FeatureFlagsController do ...@@ -1286,7 +1321,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: new_version_flag.id, iid: new_version_flag.iid,
operations_feature_flag: { operations_feature_flag: {
strategies_attributes: [{ strategies_attributes: [{
id: strategy.id, id: strategy.id,
...@@ -1313,7 +1348,7 @@ describe Projects::FeatureFlagsController do ...@@ -1313,7 +1348,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: new_version_flag.id, iid: new_version_flag.iid,
operations_feature_flag: { operations_feature_flag: {
strategies_attributes: [{ strategies_attributes: [{
id: strategy.id, id: strategy.id,
...@@ -1339,7 +1374,7 @@ describe Projects::FeatureFlagsController do ...@@ -1339,7 +1374,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: new_version_flag.id, iid: new_version_flag.iid,
operations_feature_flag: { operations_feature_flag: {
strategies_attributes: [{ strategies_attributes: [{
id: strategy.id, id: strategy.id,
...@@ -1360,7 +1395,7 @@ describe Projects::FeatureFlagsController do ...@@ -1360,7 +1395,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: new_version_flag.id, iid: new_version_flag.iid,
operations_feature_flag: { operations_feature_flag: {
strategies_attributes: [{ strategies_attributes: [{
id: strategy.id, id: strategy.id,
...@@ -1383,7 +1418,7 @@ describe Projects::FeatureFlagsController do ...@@ -1383,7 +1418,7 @@ describe Projects::FeatureFlagsController do
params = { params = {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: new_version_flag.id, iid: new_version_flag.iid,
operations_feature_flag: { operations_feature_flag: {
name: 'some-other-name' name: 'some-other-name'
} }
......
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