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
ab529cdd
Commit
ab529cdd
authored
Apr 13, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor group search out of global search
parent
aecaaa67
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
28 deletions
+64
-28
app/services/search/global_service.rb
app/services/search/global_service.rb
+4
-7
app/services/search/group_service.rb
app/services/search/group_service.rb
+18
-0
app/services/search_service.rb
app/services/search_service.rb
+2
-0
spec/services/search/global_service_spec.rb
spec/services/search/global_service_spec.rb
+0
-21
spec/services/search/group_service_spec.rb
spec/services/search/group_service_spec.rb
+40
-0
No files found.
app/services/search/global_service.rb
View file @
ab529cdd
...
...
@@ -7,14 +7,11 @@ module Search
end
def
execute
group
=
Group
.
find_by
(
id:
params
[
:group_id
])
if
params
[
:group_id
].
present?
projects
=
ProjectsFinder
.
new
(
current_user:
current_user
).
execute
if
group
projects
=
projects
.
inside_path
(
group
.
full_path
)
Gitlab
::
SearchResults
.
new
(
current_user
,
projects
,
params
[
:search
])
end
Gitlab
::
SearchResults
.
new
(
current_user
,
projects
,
params
[
:search
])
def
projects
@projects
||=
ProjectsFinder
.
new
(
current_user:
current_user
).
execute
end
def
scope
...
...
app/services/search/group_service.rb
0 → 100644
View file @
ab529cdd
module
Search
class
GroupService
<
Search
::
GlobalService
attr_accessor
:group
def
initialize
(
user
,
group
,
params
)
super
(
user
,
params
)
@group
=
group
end
def
projects
return
Project
.
none
unless
group
return
@projects
if
defined?
@projects
@projects
=
super
.
inside_path
(
group
.
full_path
)
end
end
end
app/services/search_service.rb
View file @
ab529cdd
...
...
@@ -54,6 +54,8 @@ class SearchService
Search
::
ProjectService
.
new
(
project
,
current_user
,
params
)
elsif
show_snippets?
Search
::
SnippetService
.
new
(
current_user
,
params
)
elsif
group
Search
::
GroupService
.
new
(
current_user
,
group
,
params
)
else
Search
::
GlobalService
.
new
(
current_user
,
params
)
end
...
...
spec/services/search/global_service_spec.rb
View file @
ab529cdd
...
...
@@ -40,27 +40,6 @@ describe Search::GlobalService, services: true do
expect
(
results
.
objects
(
'projects'
)).
to
match_array
[
found_project
]
end
context
'nested group'
do
let!
(
:nested_group
)
{
create
(
:group
,
:nested
)
}
let!
(
:project
)
{
create
(
:empty_project
,
namespace:
nested_group
)
}
before
do
project
.
add_master
(
user
)
end
it
'returns result from nested group'
do
results
=
Search
::
GlobalService
.
new
(
user
,
search:
project
.
path
).
execute
expect
(
results
.
objects
(
'projects'
)).
to
match_array
[
project
]
end
it
'returns result from descendants when search inside group'
do
results
=
Search
::
GlobalService
.
new
(
user
,
search:
project
.
path
,
group_id:
nested_group
.
parent
).
execute
expect
(
results
.
objects
(
'projects'
)).
to
match_array
[
project
]
end
end
end
end
end
spec/services/search/group_service_spec.rb
0 → 100644
View file @
ab529cdd
require
'spec_helper'
describe
Search
::
GroupService
,
services:
true
do
shared_examples_for
'group search'
do
context
'finding projects by name'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:term
)
{
"Project Name"
}
let
(
:nested_group
)
{
create
(
:group
,
:nested
)
}
# These projects shouldn't be found
let!
(
:outside_project
)
{
create
(
:empty_project
,
:public
,
name:
"Outside
#{
term
}
"
)
}
let!
(
:private_project
)
{
create
(
:empty_project
,
:private
,
namespace:
nested_group
,
name:
"Private
#{
term
}
"
)}
let!
(
:other_project
)
{
create
(
:empty_project
,
:public
,
namespace:
nested_group
,
name:
term
.
reverse
)
}
# These projects should be found
let!
(
:project1
)
{
create
(
:empty_project
,
:internal
,
namespace:
nested_group
,
name:
"Inner
#{
term
}
1"
)
}
let!
(
:project2
)
{
create
(
:empty_project
,
:internal
,
namespace:
nested_group
,
name:
"Inner
#{
term
}
2"
)
}
let!
(
:project3
)
{
create
(
:empty_project
,
:internal
,
namespace:
nested_group
.
parent
,
name:
"Outer
#{
term
}
"
)
}
let
(
:results
)
{
Search
::
GroupService
.
new
(
user
,
search_group
,
search:
term
).
execute
}
subject
{
results
.
objects
(
'projects'
)
}
context
'in parent group'
do
let
(
:search_group
)
{
nested_group
.
parent
}
it
{
is_expected
.
to
match_array
([
project1
,
project2
,
project3
])
}
end
context
'in subgroup'
do
let
(
:search_group
)
{
nested_group
}
it
{
is_expected
.
to
match_array
([
project1
,
project2
])
}
end
end
end
describe
'basic search'
do
include_examples
'group search'
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