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
Tatuya Kamada
gitlab-ce
Commits
26053c87
Commit
26053c87
authored
9 years ago
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add autocomplete controller
parent
dfb4fcb6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
0 deletions
+86
-0
app/controllers/autocomplete_controller.rb
app/controllers/autocomplete_controller.rb
+30
-0
config/routes.rb
config/routes.rb
+5
-0
spec/controllers/autocomplete_controller_spec.rb
spec/controllers/autocomplete_controller_spec.rb
+51
-0
No files found.
app/controllers/autocomplete_controller.rb
0 → 100644
View file @
26053c87
class
AutocompleteController
<
ApplicationController
def
users
@users
=
if
params
[
:project_id
].
present?
project
=
Project
.
find
(
params
[
:project_id
])
if
can?
(
current_user
,
:read_project
,
project
)
project
.
team
.
users
end
elsif
params
[
:group_id
]
group
=
Group
.
find
(
params
[
:group_id
])
if
can?
(
current_user
,
:read_group
,
group
)
group
.
users
end
else
User
.
all
end
@users
=
@users
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@users
=
@users
.
active
@users
=
@users
.
page
(
params
[
:page
]).
per
(
PER_PAGE
)
render
json:
@users
,
only:
[
:name
,
:username
,
:id
],
methods:
[
:avatar_url
]
end
def
user
@user
=
User
.
find
(
params
[
:id
])
render
json:
@user
,
only:
[
:name
,
:username
,
:id
],
methods:
[
:avatar_url
]
end
end
This diff is collapsed.
Click to expand it.
config/routes.rb
View file @
26053c87
...
@@ -8,6 +8,11 @@ Gitlab::Application.routes.draw do
...
@@ -8,6 +8,11 @@ Gitlab::Application.routes.draw do
authorizations:
'oauth/authorizations'
authorizations:
'oauth/authorizations'
end
end
# Autocomplete
get
'/autocomplete/users'
=>
'autocomplete#users'
get
'/autocomplete/users/:id'
=>
'autocomplete#user'
# Search
# Search
get
'search'
=>
'search#show'
get
'search'
=>
'search#show'
get
'search/autocomplete'
=>
'search#autocomplete'
,
as: :search_autocomplete
get
'search/autocomplete'
=>
'search#autocomplete'
,
as: :search_autocomplete
...
...
This diff is collapsed.
Click to expand it.
spec/controllers/autocomplete_controller_spec.rb
0 → 100644
View file @
26053c87
require
'spec_helper'
describe
AutocompleteController
do
let!
(
:project
)
{
create
(
:project
)
}
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:user2
)
{
create
(
:user
)
}
context
'project members'
do
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:master
]
get
(
:users
,
project_id:
project
.
id
)
end
let
(
:body
)
{
JSON
.
parse
(
response
.
body
)
}
it
{
body
.
should
be_kind_of
(
Array
)
}
it
{
body
.
size
.
should
eq
(
1
)
}
it
{
body
.
first
[
"username"
].
should
==
user
.
username
}
end
context
'group members'
do
let
(
:group
)
{
create
(
:group
)
}
before
do
sign_in
(
user
)
group
.
add_owner
(
user
)
get
(
:users
,
group_id:
group
.
id
)
end
let
(
:body
)
{
JSON
.
parse
(
response
.
body
)
}
it
{
body
.
should
be_kind_of
(
Array
)
}
it
{
body
.
size
.
should
eq
(
1
)
}
it
{
body
.
first
[
"username"
].
should
==
user
.
username
}
end
context
'all users'
do
before
do
sign_in
(
user
)
get
(
:users
)
end
let
(
:body
)
{
JSON
.
parse
(
response
.
body
)
}
it
{
body
.
should
be_kind_of
(
Array
)
}
it
{
body
.
size
.
should
eq
(
User
.
count
)
}
end
end
This diff is collapsed.
Click to expand it.
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