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
99e01a0f
Commit
99e01a0f
authored
Jun 29, 2020
by
Jason Goodman
Committed by
Shinya Maeda
Jun 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve specs for feature flag issues controller
Improve permissions checks
parent
8e1be747
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
7 deletions
+113
-7
ee/app/services/feature_flag_issues/create_service.rb
ee/app/services/feature_flag_issues/create_service.rb
+1
-1
ee/app/views/projects/feature_flags/edit.html.haml
ee/app/views/projects/feature_flags/edit.html.haml
+1
-1
ee/spec/controllers/projects/feature_flag_issues_controller_spec.rb
...ntrollers/projects/feature_flag_issues_controller_spec.rb
+98
-5
ee/spec/features/projects/feature_flags/feature_flag_issues_spec.rb
...atures/projects/feature_flags/feature_flag_issues_spec.rb
+13
-0
No files found.
ee/app/services/feature_flag_issues/create_service.rb
View file @
99e01a0f
...
...
@@ -7,7 +7,7 @@ module FeatureFlagIssues
end
def
linkable_issuables
(
issues
)
issues
issues
.
select
{
|
issue
|
can?
(
current_user
,
:read_issue
,
issue
)
}
end
def
relate_issuables
(
referenced_issue
)
...
...
ee/app/views/projects/feature_flags/edit.html.haml
View file @
99e01a0f
...
...
@@ -8,4 +8,4 @@
project_id:
@project
.
id
,
feature_flags_path:
project_feature_flags_path
(
@project
),
environments_endpoint:
search_project_environments_path
(
@project
,
format: :json
),
feature_flag_issues_endpoint:
Feature
.
enabled?
(
:feature_flags_issue_links
,
@project
)
?
project_feature_flag_issues_path
(
@project
,
@feature_flag
)
:
''
}
}
feature_flag_issues_endpoint:
Feature
.
enabled?
(
:feature_flags_issue_links
,
@project
)
&&
can?
(
current_user
,
:read_issue_link
,
@project
)
?
project_feature_flag_issues_path
(
@project
,
@feature_flag
)
:
''
}
}
ee/spec/controllers/projects/feature_flag_issues_controller_spec.rb
View file @
99e01a0f
...
...
@@ -172,6 +172,16 @@ RSpec.describe Projects::FeatureFlagIssuesController do
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
it
'returns not found when related issues feature is unavailable'
do
stub_licensed_features
(
related_issues:
false
)
feature_flag
,
_issue
=
setup
sign_in
(
developer
)
get_request
(
project
,
feature_flag
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
context
'when feature flags are unlicensed'
do
before
do
stub_licensed_features
(
feature_flags:
false
)
...
...
@@ -201,7 +211,7 @@ RSpec.describe Projects::FeatureFlagIssuesController do
namespace_id:
project
.
namespace
,
project_id:
project
,
feature_flag_iid:
feature_flag
,
issuable_references:
[
issue
.
to_reference
],
issuable_references:
[
issue
.
to_reference
(
full:
true
)
],
link_type:
'relates_to'
}
...
...
@@ -241,6 +251,40 @@ RSpec.describe Projects::FeatureFlagIssuesController do
}))
end
it
'creates a cross project link for a project in the same namespace'
do
other_project
=
create
(
:project
,
namespace:
project
.
namespace
)
other_project
.
add_developer
(
developer
)
feature_flag
=
create
(
:operations_feature_flag
,
project:
project
)
issue
=
create
(
:issue
,
project:
other_project
)
sign_in
(
developer
)
post_request
(
project
,
feature_flag
,
issue
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
match
(
a_hash_including
({
'issuables'
=>
[
a_hash_including
({
'id'
=>
issue
.
id
})]
}))
end
it
'creates a cross project link for a project in another namespace'
do
other_project
=
create
(
:project
)
other_project
.
add_developer
(
developer
)
feature_flag
=
create
(
:operations_feature_flag
,
project:
project
)
issue
=
create
(
:issue
,
project:
other_project
)
sign_in
(
developer
)
post_request
(
project
,
feature_flag
,
issue
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
match
(
a_hash_including
({
'issuables'
=>
[
a_hash_including
({
'id'
=>
issue
.
id
})]
}))
end
it
'does not create a link for a reporter'
do
feature_flag
,
issue
=
setup
sign_in
(
reporter
)
...
...
@@ -248,18 +292,55 @@ RSpec.describe Projects::FeatureFlagIssuesController do
post_request
(
project
,
feature_flag
,
issue
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
::
FeatureFlagIssue
.
count
).
to
eq
(
0
)
end
it
'does not create a cross project link'
do
other_project
=
create
(
:project
)
other_project
.
add_developer
(
developer
)
it
"does not create a cross project link when the user is not a member of the issue's project"
do
other_project
=
create
(
:project
,
namespace:
project
.
namespace
)
feature_flag
=
create
(
:operations_feature_flag
,
project:
project
)
issue
=
create
(
:issue
,
project:
other_project
)
issue
=
create
(
:issue
,
project:
other_project
,
confidential:
true
)
sign_in
(
developer
)
post_request
(
project
,
feature_flag
,
issue
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
::
FeatureFlagIssue
.
count
).
to
eq
(
0
)
end
it
"does not create a cross project link when the user is a guest of the issue's project"
do
other_project
=
create
(
:project
,
namespace:
project
.
namespace
)
other_project
.
add_guest
(
developer
)
feature_flag
=
create
(
:operations_feature_flag
,
project:
project
)
issue
=
create
(
:issue
,
project:
other_project
,
confidential:
true
)
sign_in
(
developer
)
post_request
(
project
,
feature_flag
,
issue
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
::
FeatureFlagIssue
.
count
).
to
eq
(
0
)
end
it
'does not create a link when the user cannot read the issue'
do
feature_flag
,
issue
=
setup
sign_in
(
developer
)
allow
(
Ability
).
to
receive
(
:allowed?
).
and_call_original
allow
(
Ability
).
to
receive
(
:allowed?
).
with
(
developer
,
:read_issue
,
issue
).
and_return
(
false
)
post_request
(
project
,
feature_flag
,
issue
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
::
FeatureFlagIssue
.
count
).
to
eq
(
0
)
end
it
'does not create a link when the related issues feature is unavailable'
do
stub_licensed_features
(
related_issues:
false
)
feature_flag
,
issue
=
setup
sign_in
(
developer
)
post_request
(
project
,
feature_flag
,
issue
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
::
FeatureFlagIssue
.
count
).
to
eq
(
0
)
end
context
'when feature flags are unlicensed'
do
...
...
@@ -274,6 +355,7 @@ RSpec.describe Projects::FeatureFlagIssuesController do
post_request
(
project
,
feature_flag
,
issue
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
::
FeatureFlagIssue
.
count
).
to
eq
(
0
)
end
end
end
...
...
@@ -317,5 +399,16 @@ RSpec.describe Projects::FeatureFlagIssuesController do
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
feature_flag
.
reload
.
issues
).
to
eq
([
issue
])
end
it
'does not unlink the issue when the related issues feature is unavailable'
do
stub_licensed_features
(
related_issues:
false
)
feature_flag
,
issue
,
link
=
setup
sign_in
(
developer
)
delete_request
(
project
,
feature_flag
,
link
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
feature_flag
.
reload
.
issues
).
to
eq
([
issue
])
end
end
end
ee/spec/features/projects/feature_flags/feature_flag_issues_spec.rb
View file @
99e01a0f
...
...
@@ -72,6 +72,19 @@ RSpec.describe 'Feature flag issue links', :js do
expect
(
page
).
not_to
have_selector
'#related-issues'
end
end
context
'when the related issues feature is unavailable'
do
before
do
stub_licensed_features
(
related_issues:
false
,
feature_flags:
true
)
end
it
'does not show the related issues widget'
do
visit
(
edit_project_feature_flag_path
(
project
,
feature_flag
))
expect
(
page
).
to
have_text
'Strategies'
expect
(
page
).
not_to
have_selector
'#related-issues'
end
end
end
describe
'unlinking a feature flag from an issue'
do
...
...
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