Commit 0592233a authored by Alexis Reigel's avatar Alexis Reigel

add users search to search api

parent 5a45b54f
...@@ -17,7 +17,7 @@ GET /search ...@@ -17,7 +17,7 @@ GET /search
| `scope` | string | yes | The scope to search in | | `scope` | string | yes | The scope to search in |
| `search` | string | yes | The search query | | `search` | string | yes | The search query |
Search the expression within the specified scope. Currently these scopes are supported: projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs. Search the expression within the specified scope. Currently these scopes are supported: projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs, users.
The response depends on the requested scope. The response depends on the requested scope.
...@@ -281,6 +281,27 @@ Example response: ...@@ -281,6 +281,27 @@ Example response:
] ]
``` ```
### Scope: users
```bash
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/search?scope=users&search=doe
```
Example response:
```json
[
{
"id": 1,
"name": "John Doe1",
"username": "user1",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon",
"web_url": "http://localhost/user1"
}
]
```
## Group Search API ## Group Search API
Search within the specified group. Search within the specified group.
...@@ -297,7 +318,7 @@ GET /groups/:id/search ...@@ -297,7 +318,7 @@ GET /groups/:id/search
| `scope` | string | yes | The scope to search in | | `scope` | string | yes | The scope to search in |
| `search` | string | yes | The search query | | `search` | string | yes | The search query |
Search the expression within the specified scope. Currently these scopes are supported: projects, issues, merge_requests, milestones. Search the expression within the specified scope. Currently these scopes are supported: projects, issues, merge_requests, milestones, users.
The response depends on the requested scope. The response depends on the requested scope.
...@@ -499,6 +520,27 @@ Example response: ...@@ -499,6 +520,27 @@ Example response:
] ]
``` ```
### Scope: users
```bash
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/3/search?scope=users&search=doe
```
Example response:
```json
[
{
"id": 1,
"name": "John Doe1",
"username": "user1",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon",
"web_url": "http://localhost/user1"
}
]
```
## Project Search API ## Project Search API
Search within the specified project. Search within the specified project.
...@@ -515,7 +557,7 @@ GET /projects/:id/search ...@@ -515,7 +557,7 @@ GET /projects/:id/search
| `scope` | string | yes | The scope to search in | | `scope` | string | yes | The scope to search in |
| `search` | string | yes | The search query | | `search` | string | yes | The search query |
Search the expression within the specified scope. Currently these scopes are supported: issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs. Search the expression within the specified scope. Currently these scopes are supported: issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs, users.
The response depends on the requested scope. The response depends on the requested scope.
...@@ -828,4 +870,25 @@ Example response: ...@@ -828,4 +870,25 @@ Example response:
] ]
``` ```
### Scope: users
```bash
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/6/search?scope=users&search=doe
```
Example response:
```json
[
{
"id": 1,
"name": "John Doe1",
"username": "user1",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon",
"web_url": "http://localhost/user1"
}
]
```
[ce-41763]: https://gitlab.com/gitlab-org/gitlab-ce/issues/41763 [ce-41763]: https://gitlab.com/gitlab-org/gitlab-ce/issues/41763
...@@ -5,17 +5,17 @@ module API ...@@ -5,17 +5,17 @@ module API
module SearchHelpers module SearchHelpers
def self.global_search_scopes def self.global_search_scopes
# This is a separate method so that EE can redefine it. # This is a separate method so that EE can redefine it.
%w(projects issues merge_requests milestones snippet_titles snippet_blobs) %w(projects issues merge_requests milestones snippet_titles snippet_blobs users)
end end
def self.group_search_scopes def self.group_search_scopes
# This is a separate method so that EE can redefine it. # This is a separate method so that EE can redefine it.
%w(projects issues merge_requests milestones) %w(projects issues merge_requests milestones users)
end end
def self.project_search_scopes def self.project_search_scopes
# This is a separate method so that EE can redefine it. # This is a separate method so that EE can redefine it.
%w(issues merge_requests milestones notes wiki_blobs commits blobs) %w(issues merge_requests milestones notes wiki_blobs commits blobs users)
end end
end end
end end
......
...@@ -17,7 +17,8 @@ module API ...@@ -17,7 +17,8 @@ module API
blobs: Entities::Blob, blobs: Entities::Blob,
wiki_blobs: Entities::Blob, wiki_blobs: Entities::Blob,
snippet_titles: Entities::Snippet, snippet_titles: Entities::Snippet,
snippet_blobs: Entities::Snippet snippet_blobs: Entities::Snippet,
users: Entities::UserBasic
}.freeze }.freeze
def search(additional_params = {}) def search(additional_params = {})
......
...@@ -77,6 +77,16 @@ describe API::Search do ...@@ -77,6 +77,16 @@ describe API::Search do
it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' it_behaves_like 'response is correct', schema: 'public_api/v4/milestones'
end end
context 'for users scope' do
before do
create(:user, name: 'billy')
get api('/search', user), scope: 'users', search: 'billy'
end
it_behaves_like 'response is correct', schema: 'public_api/v4/user/basics'
end
context 'for snippet_titles scope' do context 'for snippet_titles scope' do
before do before do
create(:snippet, :public, title: 'awesome snippet', content: 'snippet content') create(:snippet, :public, title: 'awesome snippet', content: 'snippet content')
...@@ -192,6 +202,28 @@ describe API::Search do ...@@ -192,6 +202,28 @@ describe API::Search do
it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' it_behaves_like 'response is correct', schema: 'public_api/v4/milestones'
end end
context 'for user scope' do
before do
user = create(:user, name: 'billy')
create(:group_member, :developer, user: user, group: group)
get api("/groups/#{group.id}/search", user), scope: 'users', search: 'billy'
end
it_behaves_like 'response is correct', schema: 'public_api/v4/user/basics'
end
context 'for users scope with group path as id' do
before do
user1 = create(:user, name: 'billy')
create(:group_member, :developer, user: user1, group: group)
get api("/groups/#{CGI.escape(group.full_path)}/search", user), scope: 'users', search: 'billy'
end
it_behaves_like 'response is correct', schema: 'public_api/v4/user/basics'
end
end end
end end
...@@ -269,6 +301,17 @@ describe API::Search do ...@@ -269,6 +301,17 @@ describe API::Search do
it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' it_behaves_like 'response is correct', schema: 'public_api/v4/milestones'
end end
context 'for users scope' do
before do
user1 = create(:user, name: 'billy')
create(:project_member, :developer, user: user1, project: project)
get api("/projects/#{project.id}/search", user), scope: 'users', search: 'billy'
end
it_behaves_like 'response is correct', schema: 'public_api/v4/user/basics'
end
context 'for notes scope' do context 'for notes scope' do
before do before do
create(:note_on_merge_request, project: project, note: 'awesome note') create(:note_on_merge_request, project: project, note: 'awesome note')
......
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