Commit 72e987f1 authored by Sean McGivern's avatar Sean McGivern

Merge branch '7927-filter-none-any-weight-issues-api' into 'master'

Allow filtering by weight in issues API

Closes #7927

See merge request gitlab-org/gitlab-ee!8140
parents c52b1d48 191193ed
......@@ -42,6 +42,7 @@ GET /issues?my_reaction_emoji=star
| `author_id` | integer | no | Return issues created by the given user `id`. Combine with `scope=all` or `scope=assigned_to_me`. _([Introduced][ce-13004] in GitLab 9.5)_ |
| `assignee_id` | integer | no | Return issues assigned to the given user `id`. `None` returns unassigned issues. `Any` returns issues with an assignee. _([Introduced][ce-13004] in GitLab 9.5)_ |
| `my_reaction_emoji` | string | no | Return issues reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
| `weight` | integer | no | Return issues with the specified `weight`. `None` returns issues with no weight assigned. `Any` returns issues with a weight assigned. |
| `iids[]` | Array[integer] | no | Return only the issues having the given `iid` |
| `order_by` | string | no | Return issues ordered by `created_at` or `updated_at` fields. Default is `created_at` |
| `sort` | string | no | Return issues sorted in `asc` or `desc` order. Default is `desc` |
......@@ -157,6 +158,7 @@ GET /groups/:id/issues?my_reaction_emoji=star
| `author_id` | integer | no | Return issues created by the given user `id` _([Introduced][ce-13004] in GitLab 9.5)_ |
| `assignee_id` | integer | no | Return issues assigned to the given user `id`. `None` returns unassigned issues. `Any` returns issues with an assignee. _([Introduced][ce-13004] in GitLab 9.5)_ |
| `my_reaction_emoji` | string | no | Return issues reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
| `weight` | integer | no | Return issues with the specified `weight`. `None` returns issues with no weight assigned. `Any` returns issues with a weight assigned. |
| `order_by` | string | no | Return issues ordered by `created_at` or `updated_at` fields. Default is `created_at` |
| `sort` | string | no | Return issues sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Search group issues against their `title` and `description` |
......@@ -272,6 +274,7 @@ GET /projects/:id/issues?my_reaction_emoji=star
| `author_id` | integer | no | Return issues created by the given user `id` _([Introduced][ce-13004] in GitLab 9.5)_ |
| `assignee_id` | integer | no | Return issues assigned to the given user `id`. `None` returns unassigned issues. `Any` returns issues with an assignee. _([Introduced][ce-13004] in GitLab 9.5)_ |
| `my_reaction_emoji` | string | no | Return issues reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
| `weight` | integer | no | Return issues with the specified `weight`. `None` returns issues with no weight assigned. `Any` returns issues with a weight assigned. |
| `order_by` | string | no | Return issues ordered by `created_at` or `updated_at` fields. Default is `created_at` |
| `sort` | string | no | Return issues sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Search project issues against their `title` and `description` |
......
......@@ -39,11 +39,11 @@ module EE
end
def filter_by_no_weight?
params[:weight] == ::Issue::WEIGHT_NONE
params[:weight].to_s.downcase == ::IssuesFinder::FILTER_NONE
end
def filter_by_any_weight?
params[:weight] == ::Issue::WEIGHT_ANY
params[:weight].to_s.downcase == ::IssuesFinder::FILTER_ANY
end
override :by_assignee
......
---
title: Allow filtering by weight in issues API
merge_request: 8140
author: Heinrich Lee Yu
type: added
module EE
module API
module Issues
extend ActiveSupport::Concern
prepended do
helpers do
params :issues_params_ee do
optional :weight, types: [Integer, String], integer_none_any: true, desc: 'The weight of the issue'
end
params :issue_params_ee do
optional :weight, type: Integer, desc: 'The weight of the issue'
end
end
end
end
end
end
......@@ -36,6 +36,35 @@ describe API::Issues, :mailer do
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/issues', dir: 'ee')
end
describe "filtering by weight" do
before do
create(:issue, author: user2, project: project, weight: 1)
create(:issue, author: user2, project: project, weight: 3)
end
let!(:issue2) { create(:issue, author: user2, project: project, weight: 5) }
it 'returns issues with specific weight' do
get api('/issues', user), weight: 5, scope: 'all'
expect_paginated_array_response(size: 1)
expect(json_response.first['id']).to eq(issue2.id)
end
it 'returns issues with no weight' do
get api('/issues', user), weight: 'None', scope: 'all'
expect_paginated_array_response(size: 1)
expect(json_response.first['id']).to eq(issue.id)
end
it 'returns issues with any weight' do
get api('/issues', user), weight: 'Any', scope: 'all'
expect_paginated_array_response(size: 3)
end
end
end
end
......
......@@ -8,6 +8,17 @@ module API
helpers ::Gitlab::IssuableMetadata
# EE::API::Issues would override the following helpers
helpers do
params :issues_params_ee do
end
params :issue_params_ee do
end
end
prepend EE::API::Issues
helpers do
# rubocop: disable CodeReuse/ActiveRecord
def find_issues(args = {})
......@@ -46,9 +57,11 @@ module API
desc: 'Return issues for the given scope: `created_by_me`, `assigned_to_me` or `all`'
optional :my_reaction_emoji, type: String, desc: 'Return issues reacted by the authenticated user by the given emoji'
use :pagination
use :issues_params_ee
end
params :issue_params_ce do
params :issue_params do
optional :description, type: String, desc: 'The description of an issue'
optional :assignee_ids, type: Array[Integer], desc: 'The array of user IDs to assign issue'
optional :assignee_id, type: Integer, desc: '[Deprecated] The ID of a user to assign issue'
......@@ -57,14 +70,7 @@ module API
optional :due_date, type: String, desc: 'Date string in the format YEAR-MONTH-DAY'
optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential'
optional :discussion_locked, type: Boolean, desc: " Boolean parameter indicating if the issue's discussion is locked"
end
params :issue_params_ee do
optional :weight, type: Integer, desc: 'The weight of the issue'
end
params :issue_params do
use :issue_params_ce
use :issue_params_ee
end
end
......
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