Commit d459edf2 authored by James Fargher's avatar James Fargher

Merge branch '328240-add-negated-issue-type-filter' into 'master'

Allow BoardListType.issues to filter by negated issueType in GraphQL

See merge request gitlab-org/gitlab!70554
parents f509f166 9debb183
......@@ -91,6 +91,12 @@ class IssuesFinder < IssuableFinder
by_issue_types(issues)
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)
return items if params[:confidential].nil?
......@@ -122,6 +128,13 @@ class IssuesFinder < IssuableFinder
items.with_issue_type(params[:issue_types])
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
IssuesFinder.prepend_mod_with('IssuesFinder')
......@@ -127,6 +127,7 @@ class Issue < ApplicationRecord
project: [:route, { namespace: :route }])
}
scope :with_issue_type, ->(types) { where(issue_type: types) }
scope :without_issue_type, ->(types) { where.not(issue_type: types) }
scope :public_only, -> {
without_hidden.where(confidential: false)
......
......@@ -57,6 +57,13 @@ RSpec.describe Resolvers::BoardListIssuesResolver do
expect(result).to match_array([issue1])
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
expect do
resolve_board_list_issues(args: { filters: { assignee_username: ['username'], assignee_wildcard_id: 'NONE' } })
......
......@@ -56,12 +56,23 @@ RSpec.describe Boards::Issues::ListService do
it_behaves_like 'issues list service'
end
context 'when filtering by type' do
it 'only returns the specified type' do
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' }
context 'when filtering' do
let_it_be(:incident) { create(:labeled_issue, project: project, milestone: m1, labels: [development, p1], issue_type: '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
......
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