Commit 13ffceb2 authored by Mario Celi's avatar Mario Celi

Add negated weight issue filter on API

- Refactor issue query param definition on API
- Add negated weight to supported ee query params
- Add issue filtering spec with and without vue_issuables_list
parent 71cef819
---
title: Add negated weight issue filtering on API
merge_request: 54867
author:
type: changed
......@@ -14,7 +14,7 @@ module EE
mutually_exclusive :epic_id, :epic_iid
end
params :negatable_issue_filter_params_ee do
params :common_negatable_optional_params_ee do
optional :iteration_id, types: [Integer, String],
integer_or_custom_value: ::Iteration::Predefined::ALL.map { |iteration| iteration.name.downcase },
desc: 'Return issues which are assigned to the iteration with the given ID'
......@@ -23,6 +23,10 @@ module EE
mutually_exclusive :iteration_id, :iteration_title
end
params :negatable_issue_filter_params_ee do
optional :weight, type: Integer, desc: 'Return issues without the specified weight'
end
params :optional_issues_params_ee do
optional :weight, types: [Integer, String], integer_none_any: true, desc: 'The weight of the issue'
optional :epic_id, types: [Integer, String], integer_none_any: true, desc: 'The ID of an epic associated with the issues'
......
......@@ -9,6 +9,14 @@ RSpec.describe 'Filter issues weight', :js do
let!(:user) { create(:user, name: 'administrator', username: 'root') }
let(:js_dropdown_weight) { '#js-dropdown-weight' }
shared_examples 'filters by negated weight' do
it 'excludes issues with specified weight' do
input_filtered_search(search)
expect_issues_list_count(1)
end
end
def expect_issues_list_count(open_count, closed_count = 0)
all_count = open_count + closed_count
......@@ -46,6 +54,20 @@ RSpec.describe 'Filter issues weight', :js do
end
end
describe 'negated weight only' do
let(:search) { 'weight:!=2' }
it_behaves_like 'filters by negated weight'
context 'when vue_issuables_list is disabled' do
before do
stub_feature_flags(vue_issuables_list: false)
end
it_behaves_like 'filters by negated weight'
end
end
describe 'weight with other filters' do
it 'filters issues by searched weight and text' do
search = "weight:=2 bug"
......
......@@ -162,6 +162,12 @@ RSpec.describe API::Issues, :mailer do
expect_paginated_array_response([issue3.id, issue2.id, issue1.id])
end
it 'returns issues without specific weight' do
get api('/issues', user), params: { scope: 'all', not: { weight: 5 } }
expect_paginated_array_response([issue3.id, issue1.id, issue.id])
end
end
context 'filtering by assignee_username' do
......
......@@ -5,6 +5,9 @@ module API
module IssuesHelpers
extend Grape::API::Helpers
params :common_negatable_optional_params_ee do
end
params :negatable_issue_filter_params_ee do
end
......
......@@ -11,7 +11,7 @@ module API
feature_category :issue_tracking
helpers do
params :negatable_issue_filter_params do
params :common_negatable_optional_params do
optional :labels, type: Array[String], coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce, desc: 'Comma-separated list of label names'
optional :milestone, type: String, desc: 'Milestone title'
optional :iids, type: Array[Integer], coerce_with: ::API::Validations::Types::CommaSeparatedToIntegerArray.coerce, desc: 'The IID array of issues'
......@@ -27,28 +27,32 @@ module API
optional :assignee_username, type: Array[String], check_assignees_count: true,
coerce_with: Validations::Validators::CheckAssigneesCount.coerce,
desc: 'Return issues which are assigned to the user with the given username'
use :common_negatable_optional_params_ee
mutually_exclusive :assignee_id, :assignee_username
end
params :negatable_issue_filter_params do
optional :not, type: Hash do
use :common_negatable_optional_params
use :negatable_issue_filter_params_ee
end
end
params :issues_stats_params do
use :common_negatable_optional_params
use :optional_issues_params_ee
use :negatable_issue_filter_params
optional :created_after, type: DateTime, desc: 'Return issues created after the specified time'
optional :created_before, type: DateTime, desc: 'Return issues created before the specified time'
optional :updated_after, type: DateTime, desc: 'Return issues updated after the specified time'
optional :updated_before, type: DateTime, desc: 'Return issues updated before the specified time'
optional :not, type: Hash do
use :negatable_issue_filter_params
end
optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all],
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'
optional :confidential, type: Boolean, desc: 'Filter confidential or public issues'
use :optional_issues_params_ee
end
params :issues_params 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