Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
16a49237
Commit
16a49237
authored
Mar 26, 2020
by
Jason Goodman
Committed by
Shinya Maeda
Mar 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support new version feature flags PUT and DELETE requests in controller
Hide behind a feature flag
parent
f1dd55e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
221 additions
and
1 deletion
+221
-1
ee/app/controllers/projects/feature_flags_controller.rb
ee/app/controllers/projects/feature_flags_controller.rb
+3
-1
ee/spec/controllers/projects/feature_flags_controller_spec.rb
...pec/controllers/projects/feature_flags_controller_spec.rb
+218
-0
No files found.
ee/app/controllers/projects/feature_flags_controller.rb
View file @
16a49237
...
...
@@ -117,7 +117,9 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
params
.
require
(
:operations_feature_flag
)
.
permit
(
:name
,
:description
,
:active
,
scopes_attributes:
[
:id
,
:environment_scope
,
:active
,
:_destroy
,
strategies:
[
:name
,
parameters:
[
:groupId
,
:percentage
,
:userIds
]]])
strategies:
[
:name
,
parameters:
[
:groupId
,
:percentage
,
:userIds
]]],
strategies_attributes:
[
:id
,
:name
,
:_destroy
,
parameters:
[
:groupId
,
:percentage
,
:userIds
],
scopes_attributes:
[
:id
,
:environment_scope
,
:_destroy
]])
end
def
feature_flag_json
(
feature_flag
)
...
...
ee/spec/controllers/projects/feature_flags_controller_spec.rb
View file @
16a49237
...
...
@@ -757,6 +757,20 @@ describe Projects::FeatureFlagsController do
end
end
context
'when the feature flag does not exist'
do
let
(
:params
)
do
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
0
}
end
it
'returns not found'
do
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'when there is an additional scope'
do
let!
(
:scope
)
{
create_scope
(
feature_flag
,
'production'
,
false
)
}
...
...
@@ -764,6 +778,30 @@ describe Projects::FeatureFlagsController do
expect
{
subject
}.
to
change
{
Operations
::
FeatureFlagScope
.
count
}.
by
(
-
2
)
end
end
context
'with a version 2 flag'
do
let!
(
:new_version_flag
)
{
create
(
:operations_feature_flag
,
:new_version_flag
,
project:
project
)
}
let
(
:params
)
do
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
new_version_flag
.
id
}
end
it
'deletes the flag'
do
expect
{
subject
}.
to
change
{
Operations
::
FeatureFlag
.
count
}.
by
(
-
1
)
end
context
'when new version flags are disabled'
do
it
'returns a 404'
do
stub_feature_flags
(
feature_flags_new_version:
false
)
expect
{
subject
}.
not_to
change
{
Operations
::
FeatureFlag
.
count
}
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
end
end
describe
'PUT update.json'
do
...
...
@@ -1168,6 +1206,186 @@ describe Projects::FeatureFlagsController do
expect
(
json_response
[
'message'
]).
to
eq
([
"Scopes strategies parameters are invalid"
])
end
end
context
'with a version 2 feature flag'
do
let!
(
:new_version_flag
)
do
create
(
:operations_feature_flag
,
:new_version_flag
,
name:
'new-feature'
,
active:
true
,
project:
project
)
end
it
'creates a new strategy and scope'
do
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
new_version_flag
.
id
,
operations_feature_flag:
{
strategies_attributes:
[{
name:
'userWithId'
,
parameters:
{
userIds:
'user1'
},
scopes_attributes:
[{
environment_scope:
'production'
}]
}]
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'strategies'
].
count
).
to
eq
(
1
)
strategy_json
=
json_response
[
'strategies'
].
first
expect
(
strategy_json
[
'name'
]).
to
eq
(
'userWithId'
)
expect
(
strategy_json
[
'parameters'
]).
to
eq
({
'userIds'
=>
'user1'
})
expect
(
strategy_json
[
'scopes'
].
count
).
to
eq
(
1
)
scope_json
=
strategy_json
[
'scopes'
].
first
expect
(
scope_json
[
'environment_scope'
]).
to
eq
(
'production'
)
end
it
'creates a gradualRolloutUserId strategy'
do
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
new_version_flag
.
id
,
operations_feature_flag:
{
strategies_attributes:
[{
name:
'gradualRolloutUserId'
,
parameters:
{
groupId:
'default'
,
percentage:
'30'
}
}]
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'strategies'
].
count
).
to
eq
(
1
)
strategy_json
=
json_response
[
'strategies'
].
first
expect
(
strategy_json
[
'name'
]).
to
eq
(
'gradualRolloutUserId'
)
expect
(
strategy_json
[
'parameters'
]).
to
eq
({
'groupId'
=>
'default'
,
'percentage'
=>
'30'
})
expect
(
strategy_json
[
'scopes'
]).
to
eq
([])
end
it
'updates an existing strategy'
do
strategy
=
create
(
:operations_strategy
,
feature_flag:
new_version_flag
,
name:
'default'
,
parameters:
{})
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
new_version_flag
.
id
,
operations_feature_flag:
{
strategies_attributes:
[{
id:
strategy
.
id
,
name:
'userWithId'
,
parameters:
{
userIds:
'user2,user3'
}
}]
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'strategies'
]).
to
eq
([{
'id'
=>
strategy
.
id
,
'name'
=>
'userWithId'
,
'parameters'
=>
{
'userIds'
=>
'user2,user3'
},
'scopes'
=>
[]
}])
end
it
'updates an existing scope'
do
strategy
=
create
(
:operations_strategy
,
feature_flag:
new_version_flag
,
name:
'default'
,
parameters:
{})
scope
=
create
(
:operations_scope
,
strategy:
strategy
,
environment_scope:
'staging'
)
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
new_version_flag
.
id
,
operations_feature_flag:
{
strategies_attributes:
[{
id:
strategy
.
id
,
scopes_attributes:
[{
id:
scope
.
id
,
environment_scope:
'sandbox'
}]
}]
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'strategies'
].
first
[
'scopes'
]).
to
eq
([{
'id'
=>
scope
.
id
,
'environment_scope'
=>
'sandbox'
}])
end
it
'deletes an existing strategy'
do
strategy
=
create
(
:operations_strategy
,
feature_flag:
new_version_flag
,
name:
'default'
,
parameters:
{})
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
new_version_flag
.
id
,
operations_feature_flag:
{
strategies_attributes:
[{
id:
strategy
.
id
,
_destroy:
true
}]
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'strategies'
]).
to
eq
([])
end
it
'deletes an existing scope'
do
strategy
=
create
(
:operations_strategy
,
feature_flag:
new_version_flag
,
name:
'default'
,
parameters:
{})
scope
=
create
(
:operations_scope
,
strategy:
strategy
,
environment_scope:
'staging'
)
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
new_version_flag
.
id
,
operations_feature_flag:
{
strategies_attributes:
[{
id:
strategy
.
id
,
scopes_attributes:
[{
id:
scope
.
id
,
_destroy:
true
}]
}]
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'strategies'
].
first
[
'scopes'
]).
to
eq
([])
end
it
'does not update the flag if version 2 flags are disabled'
do
stub_feature_flags
(
feature_flags_new_version:
false
)
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
new_version_flag
.
id
,
operations_feature_flag:
{
name:
'some-other-name'
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
new_version_flag
.
reload
.
name
).
to
eq
(
'new-feature'
)
end
end
end
private
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment