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
d2ca426b
Commit
d2ca426b
authored
May 24, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Elasticsearch search for wiki: guest should be able to search through wikis
parent
814d79d4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
8 deletions
+29
-8
app/helpers/search_helper.rb
app/helpers/search_helper.rb
+6
-0
app/views/search/_category.html.haml
app/views/search/_category.html.haml
+1
-1
lib/gitlab/elastic/search_results.rb
lib/gitlab/elastic/search_results.rb
+6
-4
spec/elastic_integration/global_search_spec.rb
spec/elastic_integration/global_search_spec.rb
+6
-1
spec/lib/gitlab/elastic/project_search_results_spec.rb
spec/lib/gitlab/elastic/project_search_results_spec.rb
+1
-1
spec/lib/gitlab/elastic/search_results_spec.rb
spec/lib/gitlab/elastic/search_results_spec.rb
+8
-0
spec/services/search_service_spec.rb
spec/services/search_service_spec.rb
+1
-1
No files found.
app/helpers/search_helper.rb
View file @
d2ca426b
...
@@ -41,6 +41,12 @@ module SearchHelper
...
@@ -41,6 +41,12 @@ module SearchHelper
def
find_project_for_blob
(
blob
)
def
find_project_for_blob
(
blob
)
Project
.
find
(
blob
[
'_parent'
])
Project
.
find
(
blob
[
'_parent'
])
end
end
def
show_notes_tab?
[
:read_merge_request
,
:download_code
,
:read_issue
,
:read_project_snippet
].
any?
do
|
ability
|
can?
(
current_user
,
:read_merge_request
,
@project
)
end
end
private
private
...
...
app/views/search/_category.html.haml
View file @
d2ca426b
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
Milestones
Milestones
%span
.badge
%span
.badge
=
@search_results
.
milestones_count
=
@search_results
.
milestones_count
-
if
can?
(
current_user
,
:read_merge_request
,
@project
)
||
can?
(
current_user
,
:read_issue
,
@project
)
-
if
show_notes_tab?
%li
{
class:
active_when
(
@scope
==
'notes'
)
}
%li
{
class:
active_when
(
@scope
==
'notes'
)
}
=
link_to
search_filter_path
(
scope:
'notes'
)
do
=
link_to
search_filter_path
(
scope:
'notes'
)
do
Comments
Comments
...
...
lib/gitlab/elastic/search_results.rb
View file @
d2ca426b
...
@@ -187,19 +187,21 @@ module Gitlab
...
@@ -187,19 +187,21 @@ module Gitlab
end
end
def
wiki_filter
def
wiki_filter
blob_filter
(
:wiki_access_level
)
blob_filter
(
:wiki_access_level
,
visible_for_guests:
true
)
end
end
def
repository_filter
def
repository_filter
blob_filter
(
:repository_access_level
)
blob_filter
(
:repository_access_level
)
end
end
def
blob_filter
(
project_feature_name
)
def
blob_filter
(
project_feature_name
,
visible_for_guests:
false
)
project_ids
=
visible_for_guests
?
limit_project_ids
:
non_guest_project_ids
conditions
=
conditions
=
if
non_guest_
project_ids
==
:any
if
project_ids
==
:any
[{
exists:
{
field:
"id"
}
}]
[{
exists:
{
field:
"id"
}
}]
else
else
[{
terms:
{
id:
non_guest_
project_ids
}
}]
[{
terms:
{
id:
project_ids
}
}]
end
end
if
public_and_internal_projects
if
public_and_internal_projects
...
...
spec/elastic_integration/global_search_spec.rb
View file @
d2ca426b
require
'spec_helper'
require
'spec_helper'
describe
'GlobalSearch'
do
describe
'GlobalSearch'
do
let
(
:features
)
{
%i(issues merge_requests repository builds)
}
let
(
:features
)
{
%i(issues merge_requests repository builds
wiki
)
}
let
(
:admin
)
{
create
:user
,
admin:
true
}
let
(
:admin
)
{
create
:user
,
admin:
true
}
let
(
:auditor
)
{
create
:user
,
auditor:
true
}
let
(
:auditor
)
{
create
:user
,
auditor:
true
}
let
(
:non_member
)
{
create
:user
}
let
(
:non_member
)
{
create
:user
}
...
@@ -130,11 +130,13 @@ describe 'GlobalSearch' do
...
@@ -130,11 +130,13 @@ describe 'GlobalSearch' do
Sidekiq
::
Testing
.
inline!
do
Sidekiq
::
Testing
.
inline!
do
create
:issue
,
title:
'term'
,
project:
project
create
:issue
,
title:
'term'
,
project:
project
create
:merge_request
,
title:
'term'
,
target_project:
project
,
source_project:
project
create
:merge_request
,
title:
'term'
,
target_project:
project
,
source_project:
project
project
.
wiki
.
create_page
(
'index_page'
,
'term'
)
project
.
project_feature
.
update!
(
feature_settings
)
if
feature_settings
project
.
project_feature
.
update!
(
feature_settings
)
if
feature_settings
project
.
repository
.
index_blobs
project
.
repository
.
index_blobs
project
.
repository
.
index_commits
project
.
repository
.
index_commits
project
.
wiki
.
index_blobs
Gitlab
::
Elastic
::
Helper
.
refresh_index
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
end
...
@@ -149,6 +151,7 @@ describe 'GlobalSearch' do
...
@@ -149,6 +151,7 @@ describe 'GlobalSearch' do
results
=
search
(
user
,
'term'
)
results
=
search
(
user
,
'term'
)
expect
(
results
.
issues_count
).
to
eq
(
0
)
expect
(
results
.
issues_count
).
to
eq
(
0
)
expect
(
results
.
merge_requests_count
).
to
eq
(
0
)
expect
(
results
.
merge_requests_count
).
to
eq
(
0
)
expect
(
results
.
wiki_blobs_count
).
to
eq
(
0
)
expect
(
search
(
user
,
'def'
).
blobs_count
).
to
eq
(
0
)
expect
(
search
(
user
,
'def'
).
blobs_count
).
to
eq
(
0
)
expect
(
search
(
user
,
'add'
).
commits_count
).
to
eq
(
0
)
expect
(
search
(
user
,
'add'
).
commits_count
).
to
eq
(
0
)
end
end
...
@@ -157,6 +160,7 @@ describe 'GlobalSearch' do
...
@@ -157,6 +160,7 @@ describe 'GlobalSearch' do
results
=
search
(
user
,
'term'
)
results
=
search
(
user
,
'term'
)
expect
(
results
.
issues_count
).
not_to
eq
(
0
)
expect
(
results
.
issues_count
).
not_to
eq
(
0
)
expect
(
results
.
merge_requests_count
).
not_to
eq
(
0
)
expect
(
results
.
merge_requests_count
).
not_to
eq
(
0
)
expect
(
results
.
wiki_blobs_count
).
not_to
eq
(
0
)
expect
(
search
(
user
,
'def'
).
blobs_count
).
not_to
eq
(
0
)
expect
(
search
(
user
,
'def'
).
blobs_count
).
not_to
eq
(
0
)
expect
(
search
(
user
,
'add'
).
commits_count
).
not_to
eq
(
0
)
expect
(
search
(
user
,
'add'
).
commits_count
).
not_to
eq
(
0
)
end
end
...
@@ -164,6 +168,7 @@ describe 'GlobalSearch' do
...
@@ -164,6 +168,7 @@ describe 'GlobalSearch' do
def
expect_non_code_items_to_be_found
(
user
)
def
expect_non_code_items_to_be_found
(
user
)
results
=
search
(
guest
,
'term'
)
results
=
search
(
guest
,
'term'
)
expect
(
results
.
issues_count
).
not_to
eq
(
0
)
expect
(
results
.
issues_count
).
not_to
eq
(
0
)
expect
(
results
.
wiki_blobs_count
).
not_to
eq
(
0
)
expect
(
results
.
merge_requests_count
).
to
eq
(
0
)
expect
(
results
.
merge_requests_count
).
to
eq
(
0
)
expect
(
search
(
guest
,
'def'
).
blobs_count
).
to
eq
(
0
)
expect
(
search
(
guest
,
'def'
).
blobs_count
).
to
eq
(
0
)
expect
(
search
(
guest
,
'add'
).
commits_count
).
to
eq
(
0
)
expect
(
search
(
guest
,
'add'
).
commits_count
).
to
eq
(
0
)
...
...
spec/lib/gitlab/elastic/project_search_results_spec.rb
View file @
d2ca426b
...
@@ -66,7 +66,7 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do
...
@@ -66,7 +66,7 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do
it
'shows wiki for guests'
do
it
'shows wiki for guests'
do
project
=
create
:empty_project
,
:public
project
=
create
:empty_project
,
:public
guest
=
create
:user
guest
=
create
:user
project
.
team
<<
[
guest
,
:guest
]
project
.
add_guest
(
guest
)
# Wiki
# Wiki
project
.
wiki
.
create_page
(
'index_page'
,
'term'
)
project
.
wiki
.
create_page
(
'index_page'
,
'term'
)
...
...
spec/lib/gitlab/elastic/search_results_spec.rb
View file @
d2ca426b
...
@@ -419,6 +419,14 @@ describe Gitlab::Elastic::SearchResults, lib: true do
...
@@ -419,6 +419,14 @@ describe Gitlab::Elastic::SearchResults, lib: true do
expect
(
results
.
wiki_blobs_count
).
to
eq
1
expect
(
results
.
wiki_blobs_count
).
to
eq
1
end
end
it
'finds wiki blobs for guest'
do
project_1
.
add_guest
(
user
)
blobs
=
results
.
objects
(
'wiki_blobs'
)
expect
(
blobs
.
first
[
"_source"
][
"blob"
][
"content"
]).
to
include
(
"term"
)
expect
(
results
.
wiki_blobs_count
).
to
eq
1
end
it
'finds wiki blobs from public projects only'
do
it
'finds wiki blobs from public projects only'
do
project_2
=
create
:project
,
:private
project_2
=
create
:project
,
:private
project_2
.
wiki
.
create_page
(
'index_page'
,
'term'
)
project_2
.
wiki
.
create_page
(
'index_page'
,
'term'
)
...
...
spec/services/search_service_spec.rb
View file @
d2ca426b
...
@@ -29,7 +29,7 @@ describe SearchService, services: true do
...
@@ -29,7 +29,7 @@ describe SearchService, services: true do
it
'returns the project for guests'
do
it
'returns the project for guests'
do
search_project
=
create
:empty_project
search_project
=
create
:empty_project
search_project
.
team
<<
[
user
,
:guest
]
search_project
.
add_guest
(
user
)
project
=
SearchService
.
new
(
user
,
project_id:
search_project
.
id
).
project
project
=
SearchService
.
new
(
user
,
project_id:
search_project
.
id
).
project
...
...
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