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
3cbfd0be
Commit
3cbfd0be
authored
Aug 31, 2019
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add projects parameter to IssuableFinder
parent
866465f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
5 deletions
+88
-5
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+19
-4
spec/finders/issues_finder_spec.rb
spec/finders/issues_finder_spec.rb
+50
-0
spec/finders/merge_requests_finder_spec.rb
spec/finders/merge_requests_finder_spec.rb
+19
-1
No files found.
app/finders/issuable_finder.rb
View file @
3cbfd0be
...
@@ -193,15 +193,30 @@ class IssuableFinder
...
@@ -193,15 +193,30 @@ class IssuableFinder
projects
=
projects
=
if
current_user
&&
params
[
:authorized_only
].
presence
&&
!
current_user_related?
if
current_user
&&
params
[
:authorized_only
].
presence
&&
!
current_user_related?
current_user
.
authorized_projects
(
min_access_level
)
current_user
.
authorized_projects
(
min_access_level
)
elsif
group
find_group_projects
else
else
Project
.
public_or_visible_to_user
(
current_user
,
min_access_level
)
projects_public_or_visible_to_user
end
end
@projects
=
projects
.
with_feature_available_for_user
(
klass
,
current_user
).
reorder
(
nil
)
# rubocop: disable CodeReuse/ActiveRecord
@projects
=
projects
.
with_feature_available_for_user
(
klass
,
current_user
).
reorder
(
nil
)
# rubocop: disable CodeReuse/ActiveRecord
end
end
def
projects_public_or_visible_to_user
projects
=
if
group
if
params
[
:projects
]
find_group_projects
.
id_in
(
params
[
:projects
])
else
find_group_projects
end
elsif
params
[
:projects
]
Project
.
id_in
(
params
[
:projects
])
else
Project
end
projects
.
public_or_visible_to_user
(
current_user
,
min_access_level
)
end
def
find_group_projects
def
find_group_projects
return
Project
.
none
unless
group
return
Project
.
none
unless
group
...
@@ -209,7 +224,7 @@ class IssuableFinder
...
@@ -209,7 +224,7 @@ class IssuableFinder
Project
.
where
(
namespace_id:
group
.
self_and_descendants
)
# rubocop: disable CodeReuse/ActiveRecord
Project
.
where
(
namespace_id:
group
.
self_and_descendants
)
# rubocop: disable CodeReuse/ActiveRecord
else
else
group
.
projects
group
.
projects
end
.
public_or_visible_to_user
(
current_user
,
min_access_level
)
end
end
end
def
search
def
search
...
...
spec/finders/issues_finder_spec.rb
View file @
3cbfd0be
...
@@ -42,6 +42,24 @@ describe IssuesFinder do
...
@@ -42,6 +42,24 @@ describe IssuesFinder do
end
end
end
end
context
'filtering by projects'
do
context
'when projects are passed in a list of ids'
do
let
(
:params
)
{
{
projects:
[
project1
.
id
]
}
}
it
'returns the issue belonging to the projects'
do
expect
(
issues
).
to
contain_exactly
(
issue1
)
end
end
context
'when projects are passed in a subquery'
do
let
(
:params
)
{
{
projects:
Project
.
id_in
(
project1
.
id
)
}
}
it
'returns the issue belonging to the projects'
do
expect
(
issues
).
to
contain_exactly
(
issue1
)
end
end
end
context
'filtering by group_id'
do
context
'filtering by group_id'
do
let
(
:params
)
{
{
group_id:
group
.
id
}
}
let
(
:params
)
{
{
group_id:
group
.
id
}
}
...
@@ -49,6 +67,30 @@ describe IssuesFinder do
...
@@ -49,6 +67,30 @@ describe IssuesFinder do
it
'returns all group issues'
do
it
'returns all group issues'
do
expect
(
issues
).
to
contain_exactly
(
issue1
)
expect
(
issues
).
to
contain_exactly
(
issue1
)
end
end
context
'when projects outside the group are passed'
do
let
(
:params
)
{
{
group_id:
group
.
id
,
projects:
[
project2
.
id
]
}
}
it
'returns no issues'
do
expect
(
issues
).
to
be_empty
end
end
context
'when projects of the group are passed'
do
let
(
:params
)
{
{
group_id:
group
.
id
,
projects:
[
project1
.
id
]
}
}
it
'returns the issue within the group and projects'
do
expect
(
issues
).
to
contain_exactly
(
issue1
)
end
end
context
'when projects of the group are passed as a subquery'
do
let
(
:params
)
{
{
group_id:
group
.
id
,
projects:
Project
.
id_in
(
project1
.
id
)
}
}
it
'returns the issue within the group and projects'
do
expect
(
issues
).
to
contain_exactly
(
issue1
)
end
end
end
end
context
'when include_subgroup param is true'
do
context
'when include_subgroup param is true'
do
...
@@ -59,6 +101,14 @@ describe IssuesFinder do
...
@@ -59,6 +101,14 @@ describe IssuesFinder do
it
'returns all group and subgroup issues'
do
it
'returns all group and subgroup issues'
do
expect
(
issues
).
to
contain_exactly
(
issue1
,
issue4
)
expect
(
issues
).
to
contain_exactly
(
issue1
,
issue4
)
end
end
context
'when mixed projects are passed'
do
let
(
:params
)
{
{
group_id:
group
.
id
,
projects:
[
project2
.
id
,
project3
.
id
]
}
}
it
'returns the issue within the group and projects'
do
expect
(
issues
).
to
contain_exactly
(
issue4
)
end
end
end
end
end
end
...
...
spec/finders/merge_requests_finder_spec.rb
View file @
3cbfd0be
...
@@ -13,7 +13,7 @@ describe MergeRequestsFinder do
...
@@ -13,7 +13,7 @@ describe MergeRequestsFinder do
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request4
,
merge_request5
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request4
,
merge_request5
)
end
end
it
'filters by project'
do
it
'filters by project
_id
'
do
params
=
{
project_id:
project1
.
id
,
scope:
'authored'
,
state:
'opened'
}
params
=
{
project_id:
project1
.
id
,
scope:
'authored'
,
state:
'opened'
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
...
@@ -21,6 +21,14 @@ describe MergeRequestsFinder do
...
@@ -21,6 +21,14 @@ describe MergeRequestsFinder do
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
)
end
end
it
'filters by projects'
do
params
=
{
projects:
[
project2
.
id
,
project3
.
id
]
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
).
to
contain_exactly
(
merge_request3
,
merge_request4
)
end
it
'filters by commit sha'
do
it
'filters by commit sha'
do
merge_requests
=
described_class
.
new
(
merge_requests
=
described_class
.
new
(
user
,
user
,
...
@@ -49,6 +57,16 @@ describe MergeRequestsFinder do
...
@@ -49,6 +57,16 @@ describe MergeRequestsFinder do
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request5
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request5
)
end
end
it
'filters by group projects including subgroups'
do
# project3 is not in the group, so it should not return merge_request4
projects
=
[
project3
.
id
,
project4
.
id
]
params
=
{
group_id:
group
.
id
,
include_subgroups:
true
,
projects:
projects
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
).
to
contain_exactly
(
merge_request5
)
end
end
end
it
'filters by non_archived'
do
it
'filters by non_archived'
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