diff --git a/app/finders/issues_finder.rb b/app/finders/issues_finder.rb index 9c262561ba0c271c96f2c4a9cfd40c23b6c065a4..cf7fe3e3f91225d1ab88abd21e232f93cd627508 100644 --- a/app/finders/issues_finder.rb +++ b/app/finders/issues_finder.rb @@ -67,28 +67,6 @@ def filter_by_full_text_search(items) super.with_projects_matching_search_data end - override :use_full_text_search? - def use_full_text_search? - return false if include_namespace_level_work_items? - - super - end - - override :by_parent - def by_parent(items) - return super unless include_namespace_level_work_items? - - relations = [group_namespaces, project_namespaces].compact - - namespaces = if relations.one? - relations.first - else - Namespace.from_union(relations) - end - - items.in_namespaces(namespaces) - end - def group_namespaces return if params[:project_id] || params[:projects] @@ -146,10 +124,6 @@ def by_negated_issue_types(items) items.without_issue_type(issue_type_params) end - - def include_namespace_level_work_items? - params.group? && Feature.enabled?(:namespace_level_work_items, params.group) - end end IssuesFinder.prepend_mod_with('IssuesFinder') diff --git a/app/finders/work_items/work_items_finder.rb b/app/finders/work_items/work_items_finder.rb index 8d07c54f0fd12f4a287d760b4cd7d646aff3ae4b..407af0f49046318ab1623d3d21ec0b3422803190 100644 --- a/app/finders/work_items/work_items_finder.rb +++ b/app/finders/work_items/work_items_finder.rb @@ -39,5 +39,31 @@ def widget_filter_for(widget_class) rescue NameError nil end + + override :use_full_text_search? + def use_full_text_search? + return false if include_namespace_level_work_items? + + super + end + + override :by_parent + def by_parent(items) + return super unless include_namespace_level_work_items? + + relations = [group_namespaces, project_namespaces].compact + + namespaces = if relations.one? + relations.first + else + Namespace.from_union(relations) + end + + items.in_namespaces(namespaces) + end + + def include_namespace_level_work_items? + params.group? && Feature.enabled?(:namespace_level_work_items, params.group) + end end end diff --git a/ee/spec/finders/issues_finder_spec.rb b/ee/spec/finders/issues_finder_spec.rb index a1a8d4c72364f84e8b688949453c7ef4c5f2fc4d..c2fcdf310bfa9d2bba33def0664309afadd603b2 100644 --- a/ee/spec/finders/issues_finder_spec.rb +++ b/ee/spec/finders/issues_finder_spec.rb @@ -2,10 +2,10 @@ require 'spec_helper' -RSpec.describe IssuesFinder do +RSpec.describe IssuesFinder, feature_category: :team_planning do describe '#execute' do - include_context 'IssuesFinder context' - include_context 'IssuesFinder#execute context' + include_context 'Issues or WorkItems Finder context', :issue + include_context '{Issues|WorkItems}Finder#execute context', :issue context 'scope: all' do let(:scope) { 'all' } @@ -132,7 +132,7 @@ end end - context 'filer issues by negated weight' do + context 'filter issues by negated weight' do let(:params) { { not: { weight: 1 } } } it 'filters out issues with the specified weight' do @@ -279,7 +279,7 @@ let(:params) { { group_id: group, not: { iteration_id: ::Iteration::Predefined::Current.title } } } it 'returns filtered issues' do - expect(items).to contain_exactly(item1, item5, group_level_item, iteration_1_issue, iteration_2_issue) + expect(items).to contain_exactly(item1, item5, iteration_1_issue, iteration_2_issue) end end end diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index 43d66d285fa2029ae69d5e7ff2aed48e191c0522..f17d728b0b5ca76a35b1a91dde14516a8784d9b7 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe IssuesFinder, feature_category: :team_planning do - include_context 'IssuesFinder context' + include_context 'Issues or WorkItems Finder context', :issue - it_behaves_like 'issues or work items finder', :issue, 'IssuesFinder#execute context' + it_behaves_like 'issues or work items finder', :issue, '{Issues|WorkItems}Finder#execute context' end diff --git a/spec/finders/work_items/work_items_finder_spec.rb b/spec/finders/work_items/work_items_finder_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..24dba57b7a9fd6eaabb3d66d238d4a9ae1095239 --- /dev/null +++ b/spec/finders/work_items/work_items_finder_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe WorkItems::WorkItemsFinder, feature_category: :team_planning do + include_context 'Issues or WorkItems Finder context', :work_item + + it_behaves_like 'issues or work items finder', :work_item, '{Issues|WorkItems}Finder#execute context' + + context 'when group parameter is present' do + include_context '{Issues|WorkItems}Finder#execute context', :work_item + + let_it_be(:group_level_item) { create(:work_item, :group_level, namespace: group, author: user) } + let_it_be(:group_level_confidential_item) do + create(:work_item, :confidential, :group_level, namespace: group, author: user2) + end + + let(:params) { { group_id: group } } + let(:scope) { 'all' } + + it 'returns group level work items' do + expect(items).to contain_exactly(item1, item5, group_level_item) + end + + context 'when namespace_level_work_items is disabled' do + before do + stub_feature_flags(namespace_level_work_items: false) + end + + it 'does not return group level work items' do + expect(items).to contain_exactly(item1, item5) + end + end + + context 'when user has access to confidential items' do + before do + group.add_reporter(user) + end + + it 'includes confidential group-level items' do + expect(items).to contain_exactly(item1, item5, group_level_item, group_level_confidential_item) + end + + context 'when namespace_level_work_items is disabled' do + before do + stub_feature_flags(namespace_level_work_items: false) + end + + it 'only returns project-level items' do + expect(items).to contain_exactly(item1, item5) + end + end + end + end +end diff --git a/spec/requests/api/graphql/group/issues_spec.rb b/spec/requests/api/graphql/group/issues_spec.rb index 93ecaee03acd1773e7a8c65cda23415f60ab3bc9..95aeed32558cbe8b21f1dccecba54ee6d9e641af 100644 --- a/spec/requests/api/graphql/group/issues_spec.rb +++ b/spec/requests/api/graphql/group/issues_spec.rb @@ -142,42 +142,6 @@ end end - context 'when querying epic types' do - let_it_be(:group_level_issue) { create(:issue, :epic, :group_level, namespace: group1) } - - let(:query) do - graphql_query_for( - 'group', - { 'fullPath' => group1.full_path }, - "issues(types: [EPIC]) { #{fields} }" - ) - end - - before_all do - group1.add_developer(current_user) - end - - it 'returns group-level epics' do - post_graphql(query, current_user: current_user) - - expect_graphql_errors_to_be_empty - expect(issues_ids).to contain_exactly(group_level_issue.to_global_id.to_s) - end - - context 'when namespace_level_work_items is disabled' do - before do - stub_feature_flags(namespace_level_work_items: false) - end - - it 'returns no epics' do - post_graphql(query, current_user: current_user) - - expect_graphql_errors_to_be_empty - expect(issues_ids).to be_empty - end - end - end - def issues_ids graphql_dig_at(issues_data, :node, :id) end diff --git a/spec/services/quick_actions/target_service_spec.rb b/spec/services/quick_actions/target_service_spec.rb index 311f2680379ca9ac4a3bfe70e42137e9fa94ff12..47ec433753b5a080d71b8ac7d6c0b2490cbec023 100644 --- a/spec/services/quick_actions/target_service_spec.rb +++ b/spec/services/quick_actions/target_service_spec.rb @@ -43,15 +43,6 @@ it_behaves_like 'find target' it_behaves_like 'build target', type_iid: nil it_behaves_like 'build target', type_iid: -1 - - context 'when issue belongs to a group' do - let(:container) { group } - let(:target) { create(:issue, :group_level, namespace: group) } - - it_behaves_like 'find target' - it_behaves_like 'build target', type_iid: nil - it_behaves_like 'build target', type_iid: -1 - end end context 'for work item' do diff --git a/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb b/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb index 4e3fada649fed003adb9c947cdebb5e39344c128..8b73001a97d241dca4080c0cbefec91ddcc8c7f3 100644 --- a/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb +++ b/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.shared_context 'IssuesFinder context' do +RSpec.shared_context 'Issues or WorkItems Finder context' do |factory| let_it_be(:user) { create(:user) } let_it_be(:user2) { create(:user) } let_it_be(:group) { create(:group) } @@ -14,7 +14,7 @@ let_it_be(:label2) { create(:label, project: project2) } let_it_be_with_reload(:item1) do create( - :issue, + factory, author: user, assignees: [user], project: project1, @@ -27,7 +27,7 @@ let_it_be_with_reload(:item2) do create( - :issue, + factory, author: user, assignees: [user], project: project2, @@ -39,7 +39,7 @@ let_it_be_with_reload(:item3) do create( - :issue, + factory, author: user2, assignees: [user2], project: project2, @@ -50,10 +50,10 @@ ) end - let_it_be_with_reload(:item4) { create(:issue, project: project3) } + let_it_be_with_reload(:item4) { create(factory, project: project3) } let_it_be_with_reload(:item5) do create( - :issue, + factory, author: user, assignees: [user], project: project1, @@ -63,20 +63,15 @@ ) end - let_it_be(:group_level_item) { create(:issue, :group_level, namespace: group, author: user) } - let_it_be(:group_level_confidential_item) do - create(:issue, :confidential, :group_level, namespace: group, author: user2) - end - let_it_be(:award_emoji1) { create(:award_emoji, name: 'thumbsup', user: user, awardable: item1) } let_it_be(:award_emoji2) { create(:award_emoji, name: 'thumbsup', user: user2, awardable: item2) } let_it_be(:award_emoji3) { create(:award_emoji, name: 'thumbsdown', user: user, awardable: item3) } - let(:items_model) { Issue } + let(:items_model) { factory.to_s.camelize.constantize } end -RSpec.shared_context 'IssuesFinder#execute context' do - let!(:closed_item) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') } +RSpec.shared_context '{Issues|WorkItems}Finder#execute context' do |factory| + let!(:closed_item) { create(factory, author: user2, assignees: [user2], project: project2, state: 'closed') } let!(:label_link) { create(:label_link, label: label, target: item2) } let!(:label_link2) { create(:label_link, label: label2, target: item3) } let(:search_user) { user } diff --git a/spec/support/shared_examples/finders/issues_finder_shared_examples.rb b/spec/support/shared_examples/finders/issues_finder_shared_examples.rb index bc3d38bb42382c4192eacb97e87b13f3112bf7ba..c4dfb4b6836e18cc3a66acf05573e275ecf7cf5f 100644 --- a/spec/support/shared_examples/finders/issues_finder_shared_examples.rb +++ b/spec/support/shared_examples/finders/issues_finder_shared_examples.rb @@ -4,7 +4,7 @@ RSpec.shared_examples 'issues or work items finder' do |factory, execute_context| describe '#execute' do - include_context execute_context + include_context execute_context, factory context 'scope: all' do let(:scope) { 'all' } @@ -208,7 +208,7 @@ context 'when include_subgroup param not set' do it 'returns all group items' do - expect(items).to contain_exactly(item1, item5, group_level_item) + expect(items).to contain_exactly(item1, item5) end context 'when projects outside the group are passed' do @@ -239,7 +239,7 @@ let(:params) { { group_id: group.id, release_tag: 'dne-release-tag' } } it 'ignores the release_tag parameter' do - expect(items).to contain_exactly(item1, item5, group_level_item) + expect(items).to contain_exactly(item1, item5) end end end @@ -250,7 +250,7 @@ end it 'returns all group and subgroup items' do - expect(items).to contain_exactly(item1, item4, item5, group_level_item) + expect(items).to contain_exactly(item1, item4, item5) end context 'when mixed projects are passed' do @@ -261,26 +261,6 @@ end end end - - context 'when user has access to confidential items' do - before do - group.add_reporter(user) - end - - it 'includes confidential group-level items' do - expect(items).to contain_exactly(item1, item5, group_level_item, group_level_confidential_item) - end - end - - context 'when namespace_level_work_items is disabled' do - before do - stub_feature_flags(namespace_level_work_items: false) - end - - it 'only returns project-level items' do - expect(items).to contain_exactly(item1, item5) - end - end end context 'filtering by author' do