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
ea4e17e2
Commit
ea4e17e2
authored
Sep 14, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Search subgroups on dashboard and explore views
parent
3a4dc55f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
5 deletions
+31
-5
app/controllers/concerns/group_tree.rb
app/controllers/concerns/group_tree.rb
+8
-3
spec/controllers/concerns/group_tree_spec.rb
spec/controllers/concerns/group_tree_spec.rb
+23
-1
spec/controllers/explore/groups_controller_spec.rb
spec/controllers/explore/groups_controller_spec.rb
+0
-1
No files found.
app/controllers/concerns/group_tree.rb
View file @
ea4e17e2
module
GroupTree
module
GroupTree
def
render_group_tree
(
groups
)
def
render_group_tree
(
groups
)
# Only show root groups if no parent-id is given
if
params
[
:filter
].
present?
@groups
=
groups
.
where
(
parent_id:
params
[
:parent_id
])
@groups
=
Gitlab
::
GroupHierarchy
.
new
(
groups
).
all_groups
@groups
=
@groups
.
search
(
params
[
:filter
])
if
params
[
:filter
].
present?
@groups
=
@groups
.
search
(
params
[
:filter
])
else
# Only show root groups if no parent-id is given
@groups
=
groups
.
where
(
parent_id:
params
[
:parent_id
])
end
@groups
=
@groups
.
includes
(
:route
)
@groups
=
@groups
.
includes
(
:route
)
@groups
=
@groups
.
sort
(
@sort
=
params
[
:sort
])
@groups
=
@groups
.
sort
(
@sort
=
params
[
:sort
])
@groups
=
@groups
.
page
(
params
[
:page
])
@groups
=
@groups
.
page
(
params
[
:page
])
...
@@ -12,6 +16,7 @@ module GroupTree
...
@@ -12,6 +16,7 @@ module GroupTree
format
.
json
do
format
.
json
do
serializer
=
GroupChildSerializer
.
new
(
current_user:
current_user
)
serializer
=
GroupChildSerializer
.
new
(
current_user:
current_user
)
.
with_pagination
(
request
,
response
)
.
with_pagination
(
request
,
response
)
serializer
.
expand_hierarchy
if
params
[
:filter
].
present?
render
json:
serializer
.
represent
(
@groups
)
render
json:
serializer
.
represent
(
@groups
)
end
end
end
end
...
...
spec/controllers/concerns/group_tree_spec.rb
View file @
ea4e17e2
...
@@ -5,7 +5,8 @@ describe GroupTree do
...
@@ -5,7 +5,8 @@ describe GroupTree do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
controller
(
ApplicationController
)
do
controller
(
ApplicationController
)
do
include
GroupTree
# rubocop:disable Rspec/DescribedClass
# `described_class` is not available in this context
include
GroupTree
# rubocop:disable RSpec/DescribedClass
def
index
def
index
render_group_tree
Group
.
all
render_group_tree
Group
.
all
...
@@ -43,6 +44,14 @@ describe GroupTree do
...
@@ -43,6 +44,14 @@ describe GroupTree do
expect
(
assigns
(
:groups
)).
to
contain_exactly
(
subgroup
)
expect
(
assigns
(
:groups
)).
to
contain_exactly
(
subgroup
)
end
end
it
'allows filtering for subgroups'
do
subgroup
=
create
(
:group
,
:public
,
parent:
group
,
name:
'filter'
)
get
:index
,
filter:
'filt'
,
format: :json
expect
(
assigns
(
:groups
)).
to
contain_exactly
(
subgroup
)
end
end
end
context
'json content'
do
context
'json content'
do
...
@@ -51,6 +60,19 @@ describe GroupTree do
...
@@ -51,6 +60,19 @@ describe GroupTree do
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
group
.
id
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
group
.
id
)
end
end
context
'nested groups'
,
:nested_groups
do
it
'expands the tree when filtering'
do
subgroup
=
create
(
:group
,
:public
,
parent:
group
,
name:
'filter'
)
get
:index
,
filter:
'filt'
,
format: :json
children_response
=
json_response
.
first
[
'children'
]
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
group
.
id
)
expect
(
children_response
.
first
[
'id'
]).
to
eq
(
subgroup
.
id
)
end
end
end
end
end
end
end
end
spec/controllers/explore/groups_controller_spec.rb
View file @
ea4e17e2
...
@@ -20,5 +20,4 @@ describe Explore::GroupsController do
...
@@ -20,5 +20,4 @@ describe Explore::GroupsController do
expect
(
assigns
(
:groups
)).
to
contain_exactly
(
member_of_group
,
public_group
)
expect
(
assigns
(
:groups
)).
to
contain_exactly
(
member_of_group
,
public_group
)
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