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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
9f3995a0
Commit
9f3995a0
authored
Sep 06, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Find all children matching a query
parent
28c44004
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
7 deletions
+48
-7
app/finders/group_children_finder.rb
app/finders/group_children_finder.rb
+34
-7
spec/finders/group_children_finder_spec.rb
spec/finders/group_children_finder_spec.rb
+14
-0
No files found.
app/finders/group_children_finder.rb
View file @
9f3995a0
...
@@ -41,25 +41,52 @@ class GroupChildrenFinder
...
@@ -41,25 +41,52 @@ class GroupChildrenFinder
@children
||=
subgroups
+
projects
@children
||=
subgroups
+
projects
end
end
def
base_groups
GroupsFinder
.
new
(
current_user
,
parent:
parent_group
,
all_available:
true
).
execute
end
def
all_subgroups
Gitlab
::
GroupHierarchy
.
new
(
Group
.
where
(
id:
parent_group
)).
all_groups
end
def
subgroups_matching_filter
all_subgroups
.
search
(
params
[
:filter
])
end
def
subgroups
def
subgroups
return
Group
.
none
unless
Group
.
supports_nested_groups?
return
Group
.
none
unless
Group
.
supports_nested_groups?
return
Group
.
none
unless
can?
(
current_user
,
:read_group
,
parent_group
)
return
Group
.
none
unless
can?
(
current_user
,
:read_group
,
parent_group
)
groups
=
GroupsFinder
.
new
(
current_user
,
groups
=
if
params
[
:filter
]
parent:
parent_group
,
subgroups_matching_filter
all_available:
true
).
execut
e
els
e
base_groups
groups
=
groups
.
search
(
params
[
:filter
])
if
params
[
:filter
].
present?
end
groups
=
groups
.
includes
(
:route
).
includes
(
:children
)
groups
=
groups
.
includes
(
:route
).
includes
(
:children
)
groups
.
sort
(
params
[
:sort
])
groups
.
sort
(
params
[
:sort
])
end
end
def
base_projects
GroupProjectsFinder
.
new
(
group:
parent_group
,
params:
params
,
current_user:
current_user
).
execute
end
def
projects_matching_filter
ProjectsFinder
.
new
(
current_user:
current_user
).
execute
.
search
(
params
[
:filter
])
.
where
(
namespace:
all_subgroups
)
end
def
projects
def
projects
return
Project
.
none
unless
can?
(
current_user
,
:read_group
,
parent_group
)
return
Project
.
none
unless
can?
(
current_user
,
:read_group
,
parent_group
)
projects
=
GroupProjectsFinder
.
new
(
group:
parent_group
,
params:
params
,
current_user:
current_user
).
execute
projects
=
if
params
[
:filter
]
projects_matching_filter
else
base_projects
end
projects
=
projects
.
includes
(
:route
)
projects
=
projects
.
includes
(
:route
)
projects
=
projects
.
search
(
params
[
:filter
])
if
params
[
:filter
].
present?
projects
.
sort
(
params
[
:sort
])
projects
.
sort
(
params
[
:sort
])
end
end
end
end
spec/finders/group_children_finder_spec.rb
View file @
9f3995a0
...
@@ -47,6 +47,20 @@ describe GroupChildrenFinder do
...
@@ -47,6 +47,20 @@ describe GroupChildrenFinder do
expect
(
finder
.
execute
).
to
contain_exactly
(
matching_subgroup
,
matching_project
)
expect
(
finder
.
execute
).
to
contain_exactly
(
matching_subgroup
,
matching_project
)
end
end
context
'with matching children'
do
it
'includes a group that has a subgroup matching the query'
do
matching_subgroup
=
create
(
:group
,
name:
'testgroup'
,
parent:
subgroup
)
expect
(
finder
.
execute
).
to
contain_exactly
(
matching_subgroup
)
end
it
'includes a group that has a project matching the query'
do
matching_project
=
create
(
:project
,
namespace:
subgroup
,
name:
'Testproject'
)
expect
(
finder
.
execute
).
to
contain_exactly
(
matching_project
)
end
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