Commit 9debb183 authored by Mario Celi's avatar Mario Celi

Allow BoardListType.issues to filter by negated issueType in GraphQL

BoardListType.issues had the input argument to filter issues by negated
issueType but it had no effect if provided

Changelog: fixed
parent 37d45e06
...@@ -90,6 +90,12 @@ class IssuesFinder < IssuableFinder ...@@ -90,6 +90,12 @@ class IssuesFinder < IssuableFinder
by_issue_types(issues) by_issue_types(issues)
end end
# Negates all params found in `negatable_params`
def filter_negated_items(items)
issues = super
by_negated_issue_types(issues)
end
def by_confidential(items) def by_confidential(items)
return items if params[:confidential].nil? return items if params[:confidential].nil?
...@@ -121,6 +127,13 @@ class IssuesFinder < IssuableFinder ...@@ -121,6 +127,13 @@ class IssuesFinder < IssuableFinder
items.with_issue_type(params[:issue_types]) items.with_issue_type(params[:issue_types])
end end
def by_negated_issue_types(items)
issue_type_params = Array(not_params[:issue_types]).map(&:to_s) & WorkItem::Type.base_types.keys
return items if issue_type_params.blank?
items.without_issue_type(issue_type_params)
end
end end
IssuesFinder.prepend_mod_with('IssuesFinder') IssuesFinder.prepend_mod_with('IssuesFinder')
...@@ -127,6 +127,7 @@ class Issue < ApplicationRecord ...@@ -127,6 +127,7 @@ class Issue < ApplicationRecord
project: [:route, { namespace: :route }]) project: [:route, { namespace: :route }])
} }
scope :with_issue_type, ->(types) { where(issue_type: types) } scope :with_issue_type, ->(types) { where(issue_type: types) }
scope :without_issue_type, ->(types) { where.not(issue_type: types) }
scope :public_only, -> { where(confidential: false) } scope :public_only, -> { where(confidential: false) }
scope :confidential_only, -> { where(confidential: true) } scope :confidential_only, -> { where(confidential: true) }
......
...@@ -57,6 +57,13 @@ RSpec.describe Resolvers::BoardListIssuesResolver do ...@@ -57,6 +57,13 @@ RSpec.describe Resolvers::BoardListIssuesResolver do
expect(result).to match_array([issue1]) expect(result).to match_array([issue1])
end end
it 'filters issues by negated issue type' do
incident = create(:incident, project: project, labels: [label], relative_position: 15)
result = resolve_board_list_issues(args: { filters: { not: { types: ['issue'] } } })
expect(result).to contain_exactly(incident)
end
it 'raises an exception if both assignee_username and assignee_wildcard_id are present' do it 'raises an exception if both assignee_username and assignee_wildcard_id are present' do
expect do expect do
resolve_board_list_issues(args: { filters: { assignee_username: ['username'], assignee_wildcard_id: 'NONE' } }) resolve_board_list_issues(args: { filters: { assignee_username: ['username'], assignee_wildcard_id: 'NONE' } })
......
...@@ -56,12 +56,23 @@ RSpec.describe Boards::Issues::ListService do ...@@ -56,12 +56,23 @@ RSpec.describe Boards::Issues::ListService do
it_behaves_like 'issues list service' it_behaves_like 'issues list service'
end end
context 'when filtering by type' do context 'when filtering' do
it 'only returns the specified type' do let_it_be(:incident) { create(:labeled_issue, project: project, milestone: m1, labels: [development, p1], issue_type: 'incident') }
issue = create(:labeled_issue, project: project, milestone: m1, labels: [development, p1], issue_type: 'incident')
params = { board_id: board.id, id: list1.id, issue_types: 'incident' }
expect(described_class.new(parent, user, params).execute).to eq [issue] context 'when filtering by type' do
it 'only returns the specified type' do
params = { board_id: board.id, id: list1.id, issue_types: 'incident' }
expect(described_class.new(parent, user, params).execute).to eq [incident]
end
end
context 'when filtering by negated type' do
it 'only returns the specified type' do
params = { board_id: board.id, id: list1.id, not: { issue_types: ['issue'] } }
expect(described_class.new(parent, user, params).execute).to contain_exactly(incident)
end
end end
end end
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