Commit 626a915a authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '212579-not-operator-not-functional-when-searching-epics' into 'master'

Add negated params filter to epics search

See merge request gitlab-org/gitlab!32296
parents 2e8d297b a6b63f17
...@@ -55,16 +55,8 @@ class EpicsFinder < IssuableFinder ...@@ -55,16 +55,8 @@ class EpicsFinder < IssuableFinder
return Epic.none unless Ability.allowed?(current_user, :read_epic, group) return Epic.none unless Ability.allowed?(current_user, :read_epic, group)
items = init_collection items = init_collection
items = by_created_at(items) items = filter_items(items)
items = by_updated_at(items) items = filter_negated_items(items)
items = by_author(items)
items = by_timeframe(items)
items = by_state(items)
items = by_label(items)
items = by_parent(items)
items = by_iids(items)
items = starts_with_iid(items)
items = by_my_reaction_emoji(items)
# This has to be last as we use a CTE as an optimization fence # This has to be last as we use a CTE as an optimization fence
# for counts by passing the force_cte param and enabling the # for counts by passing the force_cte param and enabling the
...@@ -95,6 +87,30 @@ class EpicsFinder < IssuableFinder ...@@ -95,6 +87,30 @@ class EpicsFinder < IssuableFinder
private private
def filter_items(items)
items = by_created_at(items)
items = by_updated_at(items)
items = by_author(items)
items = by_timeframe(items)
items = by_state(items)
items = by_label(items)
items = by_parent(items)
items = by_iids(items)
items = by_my_reaction_emoji(items)
starts_with_iid(items)
end
def filter_negated_items(items)
return items unless Feature.enabled?(:not_issuable_queries, group, default_enabled: true)
# API endpoints send in `nil` values so we test if there are any non-nil
return items unless not_params&.values&.any?
items = by_negated_label(items)
by_negated_author(items)
end
def group def group
return unless params[:group_id] return unless params[:group_id]
return @group if defined?(@group) return @group if defined?(@group)
......
---
title: Add negated params filter to epics search
merge_request: 32296
author:
type: fixed
...@@ -355,6 +355,56 @@ describe EpicsFinder do ...@@ -355,6 +355,56 @@ describe EpicsFinder do
end end
end end
end end
context 'with negated labels' do
let_it_be(:label) { create(:label) }
let_it_be(:label2) { create(:label) }
let_it_be(:negated_epic) { create(:labeled_epic, group: group, labels: [label]) }
let_it_be(:negated_epic2) { create(:labeled_epic, group: group, labels: [label2]) }
let_it_be(:params) { { not: { label_name: [label.title, label2.title].join(',') } } }
it 'returns all epics if no negated labels are present' do
expect(epics).to contain_exactly(negated_epic, negated_epic2, epic1, epic2, epic3)
end
it 'returns all epics without negated label' do
expect(epics(params)).to contain_exactly(epic1, epic2, epic3)
end
context 'when not_issuable_queries is disabled' do
before do
stub_feature_flags(not_issuable_queries: false)
end
it 'returns epics that include negated params' do
expect(epics(params)).to contain_exactly(negated_epic, negated_epic2, epic1, epic2, epic3)
end
end
end
context 'with negated author' do
let_it_be(:author) { create(:user) }
let_it_be(:authored_epic) { create(:epic, group: group, author: author) }
let_it_be(:params) { { not: { author_id: author.id } } }
it 'returns all epics if no negated author is present' do
expect(epics).to contain_exactly(authored_epic, epic1, epic2, epic3)
end
it 'returns all epics without given author' do
expect(epics(params)).to contain_exactly(epic1, epic2, epic3)
end
context 'when not_issuable_queries is disabled' do
before do
stub_feature_flags(not_issuable_queries: false)
end
it 'returns epics that include negated params' do
expect(epics(params)).to contain_exactly(authored_epic, epic1, epic2, epic3)
end
end
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