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
Jérome Perrin
gitlab-ce
Commits
f8f76fdb
Commit
f8f76fdb
authored
Jan 09, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5427 from karlhungus/feature_search_code_in_public_repos
Allow public repo searching
parents
a10c08c4
b89d8497
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
10 deletions
+35
-10
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+17
-10
spec/controllers/search_controller_spec.rb
spec/controllers/search_controller_spec.rb
+18
-0
No files found.
app/controllers/search_controller.rb
View file @
f8f76fdb
...
...
@@ -3,16 +3,7 @@ class SearchController < ApplicationController
project_id
=
params
[
:project_id
]
group_id
=
params
[
:group_id
]
project_ids
=
current_user
.
authorized_projects
.
map
(
&
:id
)
if
group_id
.
present?
@group
=
Group
.
find
(
group_id
)
group_project_ids
=
@group
.
projects
.
map
(
&
:id
)
project_ids
.
select!
{
|
id
|
group_project_ids
.
include?
(
id
)}
elsif
project_id
.
present?
@project
=
Project
.
find
(
params
[
:project_id
])
project_ids
.
select!
{
|
id
|
id
==
project_id
.
to_i
}
end
project_ids
=
find_project_ids
(
group_id
,
project_id
)
result
=
SearchContext
.
new
(
project_ids
,
current_user
,
params
).
execute
...
...
@@ -23,4 +14,20 @@ class SearchController < ApplicationController
@blobs
=
Kaminari
.
paginate_array
(
result
[
:blobs
]).
page
(
params
[
:page
]).
per
(
20
)
@total_results
=
@projects
.
count
+
@merge_requests
.
count
+
@issues
.
count
+
@wiki_pages
.
count
+
@blobs
.
total_count
end
private
def
find_project_ids
(
group_id
,
project_id
)
project_ids
=
current_user
.
authorized_projects
.
map
(
&
:id
)
if
group_id
.
present?
@group
=
Group
.
find
(
group_id
)
group_project_ids
=
@group
.
projects
.
map
(
&
:id
)
project_ids
.
select!
{
|
id
|
group_project_ids
.
include?
(
id
)
}
elsif
project_id
.
present?
@project
=
Project
.
find
(
project_id
)
project_ids
=
@project
.
public
?
[
@project
.
id
]
:
project_ids
.
select
{
|
id
|
id
==
project_id
.
to_i
}
end
project_ids
end
end
spec/controllers/search_controller_spec.rb
0 → 100644
View file @
f8f76fdb
require
'spec_helper'
describe
SearchController
do
let
(
:project
)
{
create
(
:project
,
public:
true
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
user
)
end
describe
'#find_project_ids'
do
it
'should include public projects ids when searching within a single project'
do
project_ids
=
controller
.
send
(
:find_project_ids
,
nil
,
project
.
id
)
project_ids
.
size
.
should
==
1
project_ids
[
0
].
should
==
project
.
id
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