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
7b78c0a7
Commit
7b78c0a7
authored
Jun 29, 2020
by
Jason Goodman
Committed by
Shinya Maeda
Jun 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not allow a user list to be deleted if associated with a strategy
Return an error message in the api
parent
f0805a8b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
2 deletions
+60
-2
ee/app/models/operations/feature_flags/user_list.rb
ee/app/models/operations/feature_flags/user_list.rb
+13
-0
ee/changelogs/unreleased/disallow-delete-assoced-userlists.yml
...angelogs/unreleased/disallow-delete-assoced-userlists.yml
+5
-0
ee/lib/api/feature_flags_user_lists.rb
ee/lib/api/feature_flags_user_lists.rb
+3
-1
ee/spec/models/operations/feature_flags/user_list_spec.rb
ee/spec/models/operations/feature_flags/user_list_spec.rb
+25
-0
ee/spec/requests/api/feature_flags_user_lists_spec.rb
ee/spec/requests/api/feature_flags_user_lists_spec.rb
+14
-1
No files found.
ee/app/models/operations/feature_flags/user_list.rb
View file @
7b78c0a7
...
@@ -9,6 +9,8 @@ module Operations
...
@@ -9,6 +9,8 @@ module Operations
self
.
table_name
=
'operations_user_lists'
self
.
table_name
=
'operations_user_lists'
belongs_to
:project
belongs_to
:project
has_many
:strategy_user_lists
has_many
:strategies
,
through: :strategy_user_lists
has_internal_id
:iid
,
scope: :project
,
init:
->
(
s
)
{
s
&
.
project
&
.
operations_feature_flags_user_lists
&
.
maximum
(
:iid
)
},
presence:
true
has_internal_id
:iid
,
scope: :project
,
init:
->
(
s
)
{
s
&
.
project
&
.
operations_feature_flags_user_lists
&
.
maximum
(
:iid
)
},
presence:
true
...
@@ -18,6 +20,17 @@ module Operations
...
@@ -18,6 +20,17 @@ module Operations
uniqueness:
{
scope: :project_id
},
uniqueness:
{
scope: :project_id
},
length:
1
..
255
length:
1
..
255
validates
:user_xids
,
feature_flag_user_xids:
true
validates
:user_xids
,
feature_flag_user_xids:
true
before_destroy
:ensure_no_associated_strategies
private
def
ensure_no_associated_strategies
if
strategies
.
present?
errors
.
add
(
:base
,
'User list is associated with a strategy'
)
throw
:abort
# rubocop: disable Cop/BanCatchThrow
end
end
end
end
end
end
end
end
ee/changelogs/unreleased/disallow-delete-assoced-userlists.yml
0 → 100644
View file @
7b78c0a7
---
title
:
Forbid deleting a feature flag user list associated with a strategy
merge_request
:
35275
author
:
type
:
fixed
ee/lib/api/feature_flags_user_lists.rb
View file @
7b78c0a7
...
@@ -84,7 +84,9 @@ module API
...
@@ -84,7 +84,9 @@ module API
end
end
delete
do
delete
do
list
=
user_project
.
operations_feature_flags_user_lists
.
find_by_iid!
(
params
[
:iid
])
list
=
user_project
.
operations_feature_flags_user_lists
.
find_by_iid!
(
params
[
:iid
])
list
.
destroy
unless
list
.
destroy
render_api_error!
(
list
.
errors
.
full_messages
,
:conflict
)
end
end
end
end
end
end
end
...
...
ee/spec/models/operations/feature_flags/user_list_spec.rb
View file @
7b78c0a7
...
@@ -67,6 +67,31 @@ RSpec.describe Operations::FeatureFlags::UserList do
...
@@ -67,6 +67,31 @@ RSpec.describe Operations::FeatureFlags::UserList do
end
end
end
end
describe
'#destroy'
do
it
'deletes the model if it is not associated with any feature flag strategies'
do
project
=
create
(
:project
)
user_list
=
described_class
.
create
(
project:
project
,
name:
'My User List'
,
user_xids:
'user1,user2'
)
user_list
.
destroy
expect
(
described_class
.
count
).
to
eq
(
0
)
end
it
'does not delete the model if it is associated with a feature flag strategy'
do
project
=
create
(
:project
)
user_list
=
described_class
.
create
(
project:
project
,
name:
'My User List'
,
user_xids:
'user1,user2'
)
feature_flag
=
create
(
:operations_feature_flag
,
:new_version_flag
,
project:
project
)
strategy
=
create
(
:operations_strategy
,
feature_flag:
feature_flag
,
name:
'gitlabUserList'
,
user_list:
user_list
)
user_list
.
destroy
expect
(
described_class
.
count
).
to
eq
(
1
)
expect
(
::
Operations
::
FeatureFlags
::
StrategyUserList
.
count
).
to
eq
(
1
)
expect
(
strategy
.
reload
.
user_list
).
to
eq
(
user_list
)
expect
(
strategy
.
valid?
).
to
eq
(
true
)
end
end
it_behaves_like
'AtomicInternalId'
do
it_behaves_like
'AtomicInternalId'
do
let
(
:internal_id_attribute
)
{
:iid
}
let
(
:internal_id_attribute
)
{
:iid
}
let
(
:instance
)
{
build
(
:operations_feature_flag_user_list
)
}
let
(
:instance
)
{
build
(
:operations_feature_flag_user_list
)
}
...
...
ee/spec/requests/api/feature_flags_user_lists_spec.rb
View file @
7b78c0a7
...
@@ -343,8 +343,21 @@ RSpec.describe API::FeatureFlagsUserLists do
...
@@ -343,8 +343,21 @@ RSpec.describe API::FeatureFlagsUserLists do
delete
api
(
"/projects/
#{
project
.
id
}
/feature_flags_user_lists/
#{
list
.
iid
}
"
,
developer
)
delete
api
(
"/projects/
#{
project
.
id
}
/feature_flags_user_lists/
#{
list
.
iid
}
"
,
developer
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:no_content
)
expect
(
response
.
body
).
to
be_blank
expect
(
project
.
operations_feature_flags_user_lists
.
count
).
to
eq
(
0
)
expect
(
project
.
operations_feature_flags_user_lists
.
count
).
to
eq
(
0
)
end
end
it
'does not delete the list if it is associated with a strategy'
do
list
=
create_list
feature_flag
=
create
(
:operations_feature_flag
,
:new_version_flag
,
project:
project
)
create
(
:operations_strategy
,
feature_flag:
feature_flag
,
name:
'gitlabUserList'
,
user_list:
list
)
delete
api
(
"/projects/
#{
project
.
id
}
/feature_flags_user_lists/
#{
list
.
iid
}
"
,
developer
)
expect
(
response
).
to
have_gitlab_http_status
(
:conflict
)
expect
(
json_response
).
to
eq
({
'message'
=>
[
'User list is associated with a strategy'
]
})
expect
(
list
.
reload
).
to
be_persisted
end
end
end
end
end
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