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
349d6edc
Commit
349d6edc
authored
May 15, 2020
by
Jason Goodman
Committed by
Shinya Maeda
May 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support gitlabUserList strategies in feature flags controller
Support both PUT and POST actions
parent
3a953494
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
170 additions
and
2 deletions
+170
-2
ee/app/controllers/projects/feature_flags_controller.rb
ee/app/controllers/projects/feature_flags_controller.rb
+3
-2
ee/app/models/operations/feature_flags/strategy.rb
ee/app/models/operations/feature_flags/strategy.rb
+4
-0
ee/app/serializers/feature_flags/strategy_entity.rb
ee/app/serializers/feature_flags/strategy_entity.rb
+1
-0
ee/app/serializers/feature_flags/user_list_entity.rb
ee/app/serializers/feature_flags/user_list_entity.rb
+10
-0
ee/spec/controllers/projects/feature_flags_controller_spec.rb
...pec/controllers/projects/feature_flags_controller_spec.rb
+152
-0
No files found.
ee/app/controllers/projects/feature_flags_controller.rb
View file @
349d6edc
...
...
@@ -111,7 +111,7 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
.
permit
(
:name
,
:description
,
:active
,
:version
,
scopes_attributes:
[
:environment_scope
,
:active
,
strategies:
[
:name
,
parameters:
[
:groupId
,
:percentage
,
:userIds
]]],
strategies_attributes:
[
:name
,
parameters:
[
:groupId
,
:percentage
,
:userIds
],
scopes_attributes:
[
:environment_scope
]])
strategies_attributes:
[
:name
,
:user_list_id
,
parameters:
[
:groupId
,
:percentage
,
:userIds
],
scopes_attributes:
[
:environment_scope
]])
end
def
update_params
...
...
@@ -119,7 +119,8 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
.
permit
(
:name
,
:description
,
:active
,
scopes_attributes:
[
:id
,
:environment_scope
,
:active
,
:_destroy
,
strategies:
[
:name
,
parameters:
[
:groupId
,
:percentage
,
:userIds
]]],
strategies_attributes:
[
:id
,
:name
,
:_destroy
,
parameters:
[
:groupId
,
:percentage
,
:userIds
],
strategies_attributes:
[
:id
,
:name
,
:user_list_id
,
:_destroy
,
parameters:
[
:groupId
,
:percentage
,
:userIds
],
scopes_attributes:
[
:id
,
:environment_scope
,
:_destroy
]])
end
...
...
ee/app/models/operations/feature_flags/strategy.rb
View file @
349d6edc
...
...
@@ -35,6 +35,10 @@ module Operations
accepts_nested_attributes_for
:scopes
,
allow_destroy:
true
def
user_list_id
=
(
user_list_id
)
self
.
user_list
=
::
Operations
::
FeatureFlags
::
UserList
.
find
(
user_list_id
)
end
private
def
same_project_validation
...
...
ee/app/serializers/feature_flags/strategy_entity.rb
View file @
349d6edc
...
...
@@ -6,5 +6,6 @@ module FeatureFlags
expose
:name
expose
:parameters
expose
:scopes
,
with:
FeatureFlags
::
ScopeEntity
expose
:user_list
,
with:
FeatureFlags
::
UserListEntity
,
expose_nil:
false
end
end
ee/app/serializers/feature_flags/user_list_entity.rb
0 → 100644
View file @
349d6edc
# frozen_string_literal: true
module
FeatureFlags
class
UserListEntity
<
Grape
::
Entity
expose
:id
expose
:iid
expose
:name
expose
:user_xids
end
end
ee/spec/controllers/projects/feature_flags_controller_spec.rb
View file @
349d6edc
...
...
@@ -693,6 +693,50 @@ describe Projects::FeatureFlagsController do
end
end
context
'when creating a version 2 feature flag with a gitlabUserList strategy'
do
let!
(
:user_list
)
do
create
(
:operations_feature_flag_user_list
,
project:
project
,
name:
'My List'
,
user_xids:
'user1,user2'
)
end
let
(
:params
)
do
{
namespace_id:
project
.
namespace
,
project_id:
project
,
operations_feature_flag:
{
name:
'my_feature_flag'
,
active:
true
,
version:
'new_version_flag'
,
strategies_attributes:
[{
name:
'gitlabUserList'
,
parameters:
{},
user_list_id:
user_list
.
id
,
scopes_attributes:
[{
environment_scope:
'production'
}]
}]
}
}
end
it
'creates the new strategy'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'strategies'
]).
to
match
([
a_hash_including
({
'name'
=>
'gitlabUserList'
,
'parameters'
=>
{},
'user_list'
=>
{
'id'
=>
user_list
.
id
,
'iid'
=>
user_list
.
iid
,
'name'
=>
'My List'
,
'user_xids'
=>
'user1,user2'
},
'scopes'
=>
[
a_hash_including
({
'environment_scope'
=>
'production'
})]
})])
end
end
context
'when version parameter is invalid'
do
let
(
:params
)
do
{
...
...
@@ -1316,6 +1360,114 @@ describe Projects::FeatureFlagsController do
expect
(
strategy_json
[
'scopes'
]).
to
eq
([])
end
it
'creates a gitlabUserList strategy'
do
user_list
=
create
(
:operations_feature_flag_user_list
,
project:
project
,
name:
'My List'
,
user_xids:
'user1,user2'
)
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
iid:
new_version_flag
.
iid
,
operations_feature_flag:
{
strategies_attributes:
[{
name:
'gitlabUserList'
,
parameters:
{},
user_list_id:
user_list
.
id
}]
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'strategies'
]).
to
match
([
a_hash_including
({
'id'
=>
an_instance_of
(
Integer
),
'name'
=>
'gitlabUserList'
,
'parameters'
=>
{},
'user_list'
=>
{
'id'
=>
user_list
.
id
,
'iid'
=>
user_list
.
iid
,
'name'
=>
'My List'
,
'user_xids'
=>
'user1,user2'
},
'scopes'
=>
[]
})])
end
it
'supports switching the associated user list for an existing gitlabUserList strategy'
do
user_list
=
create
(
:operations_feature_flag_user_list
,
project:
project
,
name:
'My List'
,
user_xids:
'user1,user2'
)
strategy
=
create
(
:operations_strategy
,
feature_flag:
new_version_flag
,
name:
'gitlabUserList'
,
parameters:
{},
user_list:
user_list
)
other_user_list
=
create
(
:operations_feature_flag_user_list
,
project:
project
,
name:
'Other List'
,
user_xids:
'user3'
)
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
iid:
new_version_flag
.
iid
,
operations_feature_flag:
{
strategies_attributes:
[{
id:
strategy
.
id
,
user_list_id:
other_user_list
.
id
}]
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'strategies'
]).
to
eq
([{
'id'
=>
strategy
.
id
,
'name'
=>
'gitlabUserList'
,
'parameters'
=>
{},
'user_list'
=>
{
'id'
=>
other_user_list
.
id
,
'iid'
=>
other_user_list
.
iid
,
'name'
=>
'Other List'
,
'user_xids'
=>
'user3'
},
'scopes'
=>
[]
}])
end
it
'does not delete a user list when deleting a gitlabUserList strategy'
do
user_list
=
create
(
:operations_feature_flag_user_list
,
project:
project
,
name:
'My List'
,
user_xids:
'user1,user2'
)
strategy
=
create
(
:operations_strategy
,
feature_flag:
new_version_flag
,
name:
'gitlabUserList'
,
parameters:
{},
user_list:
user_list
)
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
iid:
new_version_flag
.
iid
,
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
([])
expect
(
::
Operations
::
FeatureFlags
::
Strategy
.
count
).
to
eq
(
0
)
expect
(
::
Operations
::
FeatureFlags
::
StrategyUserList
.
count
).
to
eq
(
0
)
expect
(
::
Operations
::
FeatureFlags
::
UserList
.
first
).
to
eq
(
user_list
)
end
it
'returns not found when trying to create a gitlabUserList strategy with an invalid user list id'
do
params
=
{
namespace_id:
project
.
namespace
,
project_id:
project
,
iid:
new_version_flag
.
iid
,
operations_feature_flag:
{
strategies_attributes:
[{
name:
'gitlabUserList'
,
parameters:
{},
user_list_id:
1
}]
}
}
put
(
:update
,
params:
params
,
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
it
'updates an existing strategy'
do
strategy
=
create
(
:operations_strategy
,
feature_flag:
new_version_flag
,
name:
'default'
,
parameters:
{})
params
=
{
...
...
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