Commit 5a8c65b5 authored by Stan Hu's avatar Stan Hu

Add API support for looking up a user by username

Needed to support Huboard
parent 1a23af48
...@@ -4,6 +4,7 @@ v 8.4.0 (unreleased) ...@@ -4,6 +4,7 @@ v 8.4.0 (unreleased)
- Fix Error 500 when doing a search in dashboard before visiting any project (Stan Hu) - Fix Error 500 when doing a search in dashboard before visiting any project (Stan Hu)
- 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)
v 8.3.1 (unreleased) v 8.3.1 (unreleased)
......
...@@ -90,7 +90,17 @@ GET /users ...@@ -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 ...@@ -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 ...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment