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
5a8c65b5
Commit
5a8c65b5
authored
Dec 12, 2015
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API support for looking up a user by username
Needed to support Huboard
parent
1a23af48
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
5 deletions
+29
-5
CHANGELOG
CHANGELOG
+1
-0
doc/api/users.md
doc/api/users.md
+11
-1
lib/api/users.rb
lib/api/users.rb
+10
-4
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+7
-0
No files found.
CHANGELOG
View file @
5a8c65b5
...
...
@@ -4,6 +4,7 @@ v 8.4.0 (unreleased)
- Fix Error 500 when doing a search in dashboard before visiting any project (Stan Hu)
- Implement new UI for group page
- Implement search inside emoji picker
- Add API support for looking up a user by username (Stan Hu)
- Add project permissions to all project API endpoints (Stan Hu)
v 8.3.1 (unreleased)
...
...
doc/api/users.md
View file @
5a8c65b5
...
...
@@ -90,7 +90,17 @@ GET /users
You can search for users by email or username with:
`/users?search=John`
Also see
`def search query`
in
`app/models/user.rb`
.
In addition, you can lookup users by username:
```
GET /users?username=:username
```
For example:
```
GET /users?username=jack_smith
```
## Single user
...
...
lib/api/users.rb
View file @
5a8c65b5
...
...
@@ -8,11 +8,17 @@ module API
#
# Example Request:
# GET /users
# GET /users?search=Admin
# GET /users?username=root
get
do
@users
=
User
.
all
@users
=
@users
.
active
if
params
[
:active
].
present?
@users
=
@users
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@users
=
paginate
@users
if
params
[
:username
].
present?
@users
=
User
.
where
(
username:
params
[
:username
])
else
@users
=
User
.
all
@users
=
@users
.
active
if
params
[
:active
].
present?
@users
=
@users
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@users
=
paginate
@users
end
if
current_user
.
is_admin?
present
@users
,
with:
Entities
::
UserFull
...
...
spec/requests/api/users_spec.rb
View file @
5a8c65b5
...
...
@@ -27,6 +27,13 @@ describe API::API, api: true do
user
[
'username'
]
==
username
end
[
'username'
]).
to
eq
(
username
)
end
it
"should return one user"
do
get
api
(
"/users?username=
#{
omniauth_user
.
username
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'username'
]).
to
eq
(
omniauth_user
.
username
)
end
end
context
"when admin"
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