Merge branch 'support-api-lookup-by-username' into 'master'
Add API support for looking up a user by username Needed to support Huboard See merge request !2089
This commit is contained in:
commit
92bc703847
4 changed files with 29 additions and 5 deletions
|
@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
|
||||||
v 8.4.0 (unreleased)
|
v 8.4.0 (unreleased)
|
||||||
- Implement new UI for group page
|
- Implement new UI for group page
|
||||||
- Implement search inside emoji picker
|
- 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)
|
- Add project permissions to all project API endpoints (Stan Hu)
|
||||||
- Expose Git's version in the admin area
|
- Expose Git's version in the admin area
|
||||||
- Add "Frequently used" category to emoji picker
|
- Add "Frequently used" category to emoji picker
|
||||||
|
|
|
@ -90,7 +90,17 @@ GET /users
|
||||||
|
|
||||||
You can search for users by email or username with: `/users?search=John`
|
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
|
## Single user
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,17 @@ module API
|
||||||
#
|
#
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# GET /users
|
# GET /users
|
||||||
|
# GET /users?search=Admin
|
||||||
|
# GET /users?username=root
|
||||||
get do
|
get do
|
||||||
@users = User.all
|
if params[:username].present?
|
||||||
@users = @users.active if params[:active].present?
|
@users = User.where(username: params[:username])
|
||||||
@users = @users.search(params[:search]) if params[:search].present?
|
else
|
||||||
@users = paginate @users
|
@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?
|
if current_user.is_admin?
|
||||||
present @users, with: Entities::UserFull
|
present @users, with: Entities::UserFull
|
||||||
|
|
|
@ -27,6 +27,13 @@ describe API::API, api: true do
|
||||||
user['username'] == username
|
user['username'] == username
|
||||||
end['username']).to eq(username)
|
end['username']).to eq(username)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "when admin" do
|
context "when admin" do
|
||||||
|
|
Loading…
Reference in a new issue