Commit d8798c90 authored by Toon Claes's avatar Toon Claes

Allow query param scope for /issues API endpoint

parent 8bf89cb4
...@@ -35,8 +35,9 @@ GET /issues?assignee_id=5 ...@@ -35,8 +35,9 @@ GET /issues?assignee_id=5
| `state` | string | no | Return all issues or just those that are `opened` or `closed` | | `state` | string | no | Return all issues or just those that are `opened` or `closed` |
| `labels` | string | no | Comma-separated list of label names, issues must have all labels to be returned. `No+Label` lists all issues with no labels | | `labels` | string | no | Comma-separated list of label names, issues must have all labels to be returned. `No+Label` lists all issues with no labels |
| `milestone` | string | no | The milestone title | | `milestone` | string | no | The milestone title |
| `author_id` | integer | no | Returns issues created by the given user `id` (not limited to issues created by the authenticated user) | | `scope` | string | no | Return issues for the given scope: `created-by-me`, `assigned-to-me` or `all` |
| `assignee_id` | integer | no | Returns issues assigned to the given user `id` (not limited to issues created by the authenticated user) | | `author_id` | integer | no | Return issues created by the given user `id`. Combine with `scope=all` or `scope=assigned-to-me`. |
| `assignee_id` | integer | no | Return issues assigned to the given user `id` |
| `iids` | Array[integer] | no | Return only the issues having the given `iid` | | `iids` | Array[integer] | no | Return only the issues having the given `iid` |
| `order_by` | string | no | Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at` | | `order_by` | string | no | Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at` |
| `sort` | string | no | Return requests sorted in `asc` or `desc` order. Default is `desc` | | `sort` | string | no | Return requests sorted in `asc` or `desc` order. Default is `desc` |
...@@ -131,8 +132,9 @@ GET /groups/:id/issues?assignee_id=5 ...@@ -131,8 +132,9 @@ GET /groups/:id/issues?assignee_id=5
| `labels` | string | no | Comma-separated list of label names, issues must have all labels to be returned. `No+Label` lists all issues with no labels | | `labels` | string | no | Comma-separated list of label names, issues must have all labels to be returned. `No+Label` lists all issues with no labels |
| `iids` | Array[integer] | no | Return only the issues having the given `iid` | | `iids` | Array[integer] | no | Return only the issues having the given `iid` |
| `milestone` | string | no | The milestone title | | `milestone` | string | no | The milestone title |
| `author_id` | integer | no | Returns issues created by the given user `id` (not limited to issues created by the authenticated user) | | `scope` | string | no | Return issues for the given scope: `created-by-me`, `assigned-to-me` or `all` |
| `assignee_id` | integer | no | Returns issues assigned to the given user `id` (not limited to issues created by the authenticated user) | | `author_id` | integer | no | Return issues created by the given user `id`. Combine with `scope=all` or `scope=assigned-to-me`. |
| `assignee_id` | integer | no | Return issues assigned to the given user `id` |
| `order_by` | string | no | Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at` | | `order_by` | string | no | Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at` |
| `sort` | string | no | Return requests sorted in `asc` or `desc` order. Default is `desc` | | `sort` | string | no | Return requests sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Search group issues against their `title` and `description` | | `search` | string | no | Search group issues against their `title` and `description` |
...@@ -227,8 +229,9 @@ GET /projects/:id/issues?assignee_id=5 ...@@ -227,8 +229,9 @@ GET /projects/:id/issues?assignee_id=5
| `state` | string | no | Return all issues or just those that are `opened` or `closed` | | `state` | string | no | Return all issues or just those that are `opened` or `closed` |
| `labels` | string | no | Comma-separated list of label names, issues must have all labels to be returned. `No+Label` lists all issues with no labels | | `labels` | string | no | Comma-separated list of label names, issues must have all labels to be returned. `No+Label` lists all issues with no labels |
| `milestone` | string | no | The milestone title | | `milestone` | string | no | The milestone title |
| `author_id` | integer | no | Returns issues created by the given user `id` (not limited to issues created by the authenticated user) | | `scope` | string | no | Return issues for the given scope: `created-by-me`, `assigned-to-me` or `all` |
| `assignee_id` | integer | no | Returns issues assigned to the given user `id` (not limited to issues created by the authenticated user) | | `author_id` | integer | no | Return issues created by the given user `id`. Combine with `scope=all` or `scope=assigned-to-me`. |
| `assignee_id` | integer | no | Return issues assigned to the given user `id` |
| `order_by` | string | no | Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at` | | `order_by` | string | no | Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at` |
| `sort` | string | no | Return requests sorted in `asc` or `desc` order. Default is `desc` | | `sort` | string | no | Return requests sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Search project issues against their `title` and `description` | | `search` | string | no | Search project issues against their `title` and `description` |
......
...@@ -8,9 +8,6 @@ module API ...@@ -8,9 +8,6 @@ module API
def find_issues(args = {}) def find_issues(args = {})
args = params.merge(args) args = params.merge(args)
# Do not scope to "authored" when author or assignee id is given
args.delete(:scope) if args[:author_id] || args[:assignee_id]
args.delete(:id) args.delete(:id)
args[:milestone_title] = args.delete(:milestone) args[:milestone_title] = args.delete(:milestone)
args[:label_name] = args.delete(:labels) args[:label_name] = args.delete(:labels)
...@@ -34,6 +31,8 @@ module API ...@@ -34,6 +31,8 @@ module API
optional :created_before, type: DateTime, desc: 'Return issues created before the specified time' optional :created_before, type: DateTime, desc: 'Return issues created before the specified time'
optional :author_id, type: Integer, desc: 'Return issues which are authored by the user with the given ID' optional :author_id, type: Integer, desc: 'Return issues which are authored by the user with the given ID'
optional :assignee_id, type: Integer, desc: 'Return issues which are assigned to the user with the given ID' optional :assignee_id, type: Integer, desc: 'Return issues which are assigned to the user with the given ID'
optional :scope, type: String, values: %w[created-by-me assigned-to-me all],
desc: 'Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all`'
use :pagination use :pagination
end end
...@@ -60,9 +59,11 @@ module API ...@@ -60,9 +59,11 @@ module API
optional :state, type: String, values: %w[opened closed all], default: 'all', optional :state, type: String, values: %w[opened closed all], default: 'all',
desc: 'Return opened, closed, or all issues' desc: 'Return opened, closed, or all issues'
use :issues_params use :issues_params
optional :scope, type: String, values: %w[created-by-me assigned-to-me all], default: 'created-by-me',
desc: 'Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all`'
end end
get do get do
issues = find_issues(scope: 'authored') issues = find_issues
present paginate(issues), with: Entities::IssueBasic, current_user: current_user present paginate(issues), with: Entities::IssueBasic, current_user: current_user
end end
......
...@@ -71,7 +71,6 @@ describe API::Issues do ...@@ -71,7 +71,6 @@ describe API::Issues do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
context "when authenticated" do context "when authenticated" do
let(:first_issue) { json_response.first } let(:first_issue) { json_response.first }
...@@ -105,10 +104,19 @@ describe API::Issues do ...@@ -105,10 +104,19 @@ describe API::Issues do
expect(json_response.second['id']).to eq(closed_issue.id) expect(json_response.second['id']).to eq(closed_issue.id)
end end
it 'returns issues assigned to me' do
issue2 = create(:issue, assignees: [user2], project: project)
get api('/issues', user2), scope: 'assigned-to-me'
expect_paginated_array_response(size: 1)
expect(first_issue['id']).to eq(issue2.id)
end
it 'returns issues authored by the given author id' do it 'returns issues authored by the given author id' do
issue2 = create(:issue, author: user2, project: project) issue2 = create(:issue, author: user2, project: project)
get api('/issues', user), author_id: user2.id get api('/issues', user), author_id: user2.id, scope: 'all'
expect_paginated_array_response(size: 1) expect_paginated_array_response(size: 1)
expect(first_issue['id']).to eq(issue2.id) expect(first_issue['id']).to eq(issue2.id)
...@@ -117,7 +125,7 @@ describe API::Issues do ...@@ -117,7 +125,7 @@ describe API::Issues do
it 'returns issues assigned to the given assignee id' do it 'returns issues assigned to the given assignee id' do
issue2 = create(:issue, assignees: [user2], project: project) issue2 = create(:issue, assignees: [user2], project: project)
get api('/issues', user), assignee_id: user2.id get api('/issues', user), assignee_id: user2.id, scope: 'all'
expect_paginated_array_response(size: 1) expect_paginated_array_response(size: 1)
expect(first_issue['id']).to eq(issue2.id) expect(first_issue['id']).to eq(issue2.id)
...@@ -126,7 +134,7 @@ describe API::Issues do ...@@ -126,7 +134,7 @@ describe API::Issues do
it 'returns issues authored by the given author id and assigned to the given assignee id' do it 'returns issues authored by the given author id and assigned to the given assignee id' do
issue2 = create(:issue, author: user2, assignees: [user2], project: project) issue2 = create(:issue, author: user2, assignees: [user2], project: project)
get api('/issues', user), author_id: user2.id, assignee_id: user2.id get api('/issues', user), author_id: user2.id, assignee_id: user2.id, scope: 'all'
expect_paginated_array_response(size: 1) expect_paginated_array_response(size: 1)
expect(first_issue['id']).to eq(issue2.id) expect(first_issue['id']).to eq(issue2.id)
......
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