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
Léo-Paul Géneau
gitlab-ce
Commits
ed43c6f1
Commit
ed43c6f1
authored
Sep 03, 2017
by
Mark Fletcher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide admin link from default search results for non-admins
parent
81002745
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
4 deletions
+32
-4
app/helpers/search_helper.rb
app/helpers/search_helper.rb
+9
-2
changelogs/unreleased/19650-remove-admin-section-from-search-results-if-user-doesnt-have-access.yml
...ection-from-search-results-if-user-doesnt-have-access.yml
+5
-0
spec/helpers/search_helper_spec.rb
spec/helpers/search_helper_spec.rb
+18
-2
No files found.
app/helpers/search_helper.rb
View file @
ed43c6f1
...
@@ -10,6 +10,7 @@ module SearchHelper
...
@@ -10,6 +10,7 @@ module SearchHelper
search_pattern
=
Regexp
.
new
(
Regexp
.
escape
(
term
),
"i"
)
search_pattern
=
Regexp
.
new
(
Regexp
.
escape
(
term
),
"i"
)
generic_results
=
project_autocomplete
+
default_autocomplete
+
help_autocomplete
generic_results
=
project_autocomplete
+
default_autocomplete
+
help_autocomplete
generic_results
.
concat
(
default_autocomplete_admin
)
if
current_user
.
admin?
generic_results
.
select!
{
|
result
|
result
[
:label
]
=~
search_pattern
}
generic_results
.
select!
{
|
result
|
result
[
:label
]
=~
search_pattern
}
[
[
...
@@ -41,8 +42,14 @@ module SearchHelper
...
@@ -41,8 +42,14 @@ module SearchHelper
[
[
{
category:
"Settings"
,
label:
"User settings"
,
url:
profile_path
},
{
category:
"Settings"
,
label:
"User settings"
,
url:
profile_path
},
{
category:
"Settings"
,
label:
"SSH Keys"
,
url:
profile_keys_path
},
{
category:
"Settings"
,
label:
"SSH Keys"
,
url:
profile_keys_path
},
{
category:
"Settings"
,
label:
"Dashboard"
,
url:
root_path
},
{
category:
"Settings"
,
label:
"Dashboard"
,
url:
root_path
}
{
category:
"Settings"
,
label:
"Admin Section"
,
url:
admin_root_path
}
]
end
# Autocomplete results for settings pages, for admins
def
default_autocomplete_admin
[
{
category:
"Settings"
,
label:
"Admin Section"
,
url:
admin_root_path
}
]
]
end
end
...
...
changelogs/unreleased/19650-remove-admin-section-from-search-results-if-user-doesnt-have-access.yml
0 → 100644
View file @
ed43c6f1
---
title
:
Hide admin link from default search results for non-admins
merge_request
:
14015
author
:
type
:
fixed
spec/helpers/search_helper_spec.rb
View file @
ed43c6f1
...
@@ -17,7 +17,7 @@ describe SearchHelper do
...
@@ -17,7 +17,7 @@ describe SearchHelper do
end
end
end
end
context
"with a user"
do
context
"with a
standard
user"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
before
do
...
@@ -29,7 +29,11 @@ describe SearchHelper do
...
@@ -29,7 +29,11 @@ describe SearchHelper do
end
end
it
"includes default sections"
do
it
"includes default sections"
do
expect
(
search_autocomplete_opts
(
"adm"
).
size
).
to
eq
(
1
)
expect
(
search_autocomplete_opts
(
"dash"
).
size
).
to
eq
(
1
)
end
it
"does not include admin sections"
do
expect
(
search_autocomplete_opts
(
"admin"
).
size
).
to
eq
(
0
)
end
end
it
"does not allow regular expression in search term"
do
it
"does not allow regular expression in search term"
do
...
@@ -67,6 +71,18 @@ describe SearchHelper do
...
@@ -67,6 +71,18 @@ describe SearchHelper do
end
end
end
end
end
end
context
'with an admin user'
do
let
(
:admin
)
{
create
(
:admin
)
}
before
do
allow
(
self
).
to
receive
(
:current_user
).
and_return
(
admin
)
end
it
"includes admin sections"
do
expect
(
search_autocomplete_opts
(
"admin"
).
size
).
to
eq
(
1
)
end
end
end
end
describe
'search_filter_input_options'
do
describe
'search_filter_input_options'
do
...
...
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