From 5f23067a4f8144e97ea700a4a1a18d5447a62568 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Wed, 26 Nov 2025 03:03:19 +0000 Subject: [PATCH 01/25] Pass organization_id to SnippetsFinder in internal services Update internal services to pass organization_id to SnippetsFinder: - NotesFinder: Pass organization_id when finding snippet notes - Projects::AutocompleteService: Pass organization_id for snippet autocomplete - Snippets::CountService: Pass organization_id to SnippetsFinder - Gitlab::SnippetSearchResults: Pass organization_id in finder_params This is MR 3 of 3 in the rollout to make organization_id a required parameter for SnippetsFinder. Related to https://gitlab.com/gitlab-org/gitlab/-/issues/570399 Follow-up to https://gitlab.com/gitlab-org/gitlab/-/merge_requests/213784 --- app/finders/notes_finder.rb | 4 ++-- app/services/projects/autocomplete_service.rb | 2 +- app/services/snippets/count_service.rb | 2 +- lib/gitlab/snippet_search_results.rb | 2 +- spec/finders/notes_finder_spec.rb | 2 +- spec/lib/gitlab/snippet_search_results_spec.rb | 2 +- spec/services/projects/autocomplete_service_spec.rb | 2 +- spec/services/snippets/count_service_spec.rb | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index 412f57b86d21cb..2d5b0018ad6e23 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -118,9 +118,9 @@ def noteables_for_type(noteable_type) when "merge_request" MergeRequestsFinder.new(@current_user, project_id: @project.id).execute # rubocop: disable CodeReuse/Finder when "snippet", "project_snippet" - SnippetsFinder.new(@current_user, project: @project).execute # rubocop: disable CodeReuse/Finder + SnippetsFinder.new(@current_user, organization_id: Current.organization.id, project: @project).execute # rubocop: disable CodeReuse/Finder when "personal_snippet" - SnippetsFinder.new(@current_user, only_personal: true).execute # rubocop: disable CodeReuse/Finder + SnippetsFinder.new(@current_user, organization_id: Current.organization.id, only_personal: true).execute # rubocop: disable CodeReuse/Finder when "wiki_page/meta" WikiPage::Meta.for_project(@project) else diff --git a/app/services/projects/autocomplete_service.rb b/app/services/projects/autocomplete_service.rb index b536ce2b3b559a..752dcca06e1d61 100644 --- a/app/services/projects/autocomplete_service.rb +++ b/app/services/projects/autocomplete_service.rb @@ -38,7 +38,7 @@ def commands(noteable) end def snippets - SnippetsFinder.new(current_user, project: project).execute.select([:id, :title]) + SnippetsFinder.new(current_user, organization_id: Current.organization.id, project: project).execute.select([:id, :title]) end def wikis diff --git a/app/services/snippets/count_service.rb b/app/services/snippets/count_service.rb index c28768aea3e727..62eada6b067622 100644 --- a/app/services/snippets/count_service.rb +++ b/app/services/snippets/count_service.rb @@ -41,7 +41,7 @@ def initialize(current_user, author: nil, project: nil) ) end - @snippets_finder = SnippetsFinder.new(current_user, author: author, project: project) + @snippets_finder = SnippetsFinder.new(current_user, organization_id: Current.organization.id, author: author, project: project) end def execute diff --git a/lib/gitlab/snippet_search_results.rb b/lib/gitlab/snippet_search_results.rb index b77f48d1a2c820..f20817df550701 100644 --- a/lib/gitlab/snippet_search_results.rb +++ b/lib/gitlab/snippet_search_results.rb @@ -36,7 +36,7 @@ def paginated_objects(relation, page, per_page) end def finder_params - {} + { organization_id: Current.organization.id } end end end diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb index ea4aa2ba31ecbc..cccaa0eb6d9a92 100644 --- a/spec/finders/notes_finder_spec.rb +++ b/spec/finders/notes_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe NotesFinder do +RSpec.describe NotesFinder, :with_current_organization do let(:user) { create(:user) } let(:project) { create(:project) } diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index 9bb6975ede05d2..b8725d60522fa4 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::SnippetSearchResults do +RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do include SearchHelpers let_it_be(:snippet) { create(:personal_snippet, content: 'foo', file_name: 'foo') } diff --git a/spec/services/projects/autocomplete_service_spec.rb b/spec/services/projects/autocomplete_service_spec.rb index 1c3cd950b9b008..a8572c758c2dc3 100644 --- a/spec/services/projects/autocomplete_service_spec.rb +++ b/spec/services/projects/autocomplete_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::AutocompleteService, feature_category: :groups_and_projects do +RSpec.describe Projects::AutocompleteService, :with_current_organization, feature_category: :groups_and_projects do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, :public, group: group) } let_it_be(:owner) { create(:user, owner_of: project) } diff --git a/spec/services/snippets/count_service_spec.rb b/spec/services/snippets/count_service_spec.rb index 4ad9b07d5189f1..58d231ef127b60 100644 --- a/spec/services/snippets/count_service_spec.rb +++ b/spec/services/snippets/count_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Snippets::CountService, feature_category: :source_code_management do +RSpec.describe Snippets::CountService, :with_current_organization, feature_category: :source_code_management do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public) } -- GitLab From d41c09e49c550906d6692d49cb9aed2b5a7839fc Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Wed, 26 Nov 2025 03:23:45 +0000 Subject: [PATCH 02/25] Fix RuboCop violations and commit message format Add RuboCop exceptions for Current.organization usage with proper justification. These internal services will be refactored in a future MR to accept organization_id as a parameter from their callers. Fix line length violations by breaking long lines. Update commit message to use full URLs instead of short references and keep body lines under 72 characters per GitLab commit message guidelines. Related to https://gitlab.com/gitlab-org/gitlab/-/issues/570399 Follow-up to https://gitlab.com/gitlab-org/gitlab/-/merge_requests/213784 --- app/finders/notes_finder.rb | 4 ++++ app/services/projects/autocomplete_service.rb | 8 +++++++- app/services/snippets/count_service.rb | 9 ++++++++- lib/gitlab/snippet_search_results.rb | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index 2d5b0018ad6e23..86d392828a1b73 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -118,9 +118,13 @@ def noteables_for_type(noteable_type) when "merge_request" MergeRequestsFinder.new(@current_user, project_id: @project.id).execute # rubocop: disable CodeReuse/Finder when "snippet", "project_snippet" + # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter SnippetsFinder.new(@current_user, organization_id: Current.organization.id, project: @project).execute # rubocop: disable CodeReuse/Finder + # rubocop: enable Gitlab/AvoidCurrentOrganization when "personal_snippet" + # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter SnippetsFinder.new(@current_user, organization_id: Current.organization.id, only_personal: true).execute # rubocop: disable CodeReuse/Finder + # rubocop: enable Gitlab/AvoidCurrentOrganization when "wiki_page/meta" WikiPage::Meta.for_project(@project) else diff --git a/app/services/projects/autocomplete_service.rb b/app/services/projects/autocomplete_service.rb index 752dcca06e1d61..1a3bab3b472d48 100644 --- a/app/services/projects/autocomplete_service.rb +++ b/app/services/projects/autocomplete_service.rb @@ -38,7 +38,13 @@ def commands(noteable) end def snippets - SnippetsFinder.new(current_user, organization_id: Current.organization.id, project: project).execute.select([:id, :title]) + # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter + SnippetsFinder.new( + current_user, + organization_id: Current.organization.id, + project: project + ).execute.select([:id, :title]) + # rubocop: enable Gitlab/AvoidCurrentOrganization end def wikis diff --git a/app/services/snippets/count_service.rb b/app/services/snippets/count_service.rb index 62eada6b067622..47bf807621123d 100644 --- a/app/services/snippets/count_service.rb +++ b/app/services/snippets/count_service.rb @@ -41,7 +41,14 @@ def initialize(current_user, author: nil, project: nil) ) end - @snippets_finder = SnippetsFinder.new(current_user, organization_id: Current.organization.id, author: author, project: project) + # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter + @snippets_finder = SnippetsFinder.new( + current_user, + organization_id: Current.organization.id, + author: author, + project: project + ) + # rubocop: enable Gitlab/AvoidCurrentOrganization end def execute diff --git a/lib/gitlab/snippet_search_results.rb b/lib/gitlab/snippet_search_results.rb index f20817df550701..71dc877f08d563 100644 --- a/lib/gitlab/snippet_search_results.rb +++ b/lib/gitlab/snippet_search_results.rb @@ -36,7 +36,9 @@ def paginated_objects(relation, page, per_page) end def finder_params + # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter { organization_id: Current.organization.id } + # rubocop: enable Gitlab/AvoidCurrentOrganization end end end -- GitLab From 0dc14f93613436c101e61893d65f85fd52603cd1 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Wed, 26 Nov 2025 06:21:26 +0000 Subject: [PATCH 03/25] Fix Current.organization access in specs The :with_current_organization trait stubs Gitlab::Current::Organization, but the code uses Current.organization (ActiveSupport::CurrentAttributes). We need to properly set Current.organization in the before blocks. Related to https://gitlab.com/gitlab-org/gitlab/-/issues/570399 --- ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb | 3 ++- spec/finders/notes_finder_spec.rb | 1 + spec/lib/gitlab/snippet_search_results_spec.rb | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb index 8ddb5f25dffead..053fd1259abdb4 100644 --- a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb +++ b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Gitlab::SnippetSearchResults do +RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do let_it_be(:snippet) { create(:project_snippet, title: 'foo', description: 'foo') } let(:user) { snippet.author } @@ -11,6 +11,7 @@ before do allow(Gitlab).to receive(:com?).and_return(com_value) + Current.organization = current_organization end context 'when all requirements are met' do diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb index cccaa0eb6d9a92..07a52f4ca93dfd 100644 --- a/spec/finders/notes_finder_spec.rb +++ b/spec/finders/notes_finder_spec.rb @@ -8,6 +8,7 @@ before do project.add_maintainer(user) + Current.organization = current_organization end describe '#execute' do diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index b8725d60522fa4..cecefb8e42999b 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -9,6 +9,10 @@ let(:results) { described_class.new(snippet.author, 'foo') } + before do + Current.organization = current_organization + end + describe '#snippet_titles_count' do it 'returns the amount of matched snippet titles' do expect(results.limited_snippet_titles_count).to eq(1) -- GitLab From e7a86d89e1465f1a5c18d1743315266d1daa5f5d Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Wed, 26 Nov 2025 15:34:05 +0000 Subject: [PATCH 04/25] Fix failing specs by properly setting Current.organization --- ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb | 4 +++- spec/lib/gitlab/snippet_search_results_spec.rb | 4 +++- spec/services/snippets/count_service_spec.rb | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb index 053fd1259abdb4..da46ccb5ef226c 100644 --- a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb +++ b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do +RSpec.describe Gitlab::SnippetSearchResults do let_it_be(:snippet) { create(:project_snippet, title: 'foo', description: 'foo') } + let_it_be(:current_organization) { create(:organization) } let(:user) { snippet.author } let(:com_value) { true } @@ -11,6 +12,7 @@ before do allow(Gitlab).to receive(:com?).and_return(com_value) + # Since this doesn't go through a request flow, we need to manually set Current.organization Current.organization = current_organization end diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index cecefb8e42999b..214975a8aa9fe7 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -2,14 +2,16 @@ require 'spec_helper' -RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do +RSpec.describe Gitlab::SnippetSearchResults do include SearchHelpers let_it_be(:snippet) { create(:personal_snippet, content: 'foo', file_name: 'foo') } + let_it_be(:current_organization) { create(:organization) } let(:results) { described_class.new(snippet.author, 'foo') } before do + # Since this doesn't go through a request flow, we need to manually set Current.organization Current.organization = current_organization end diff --git a/spec/services/snippets/count_service_spec.rb b/spec/services/snippets/count_service_spec.rb index 58d231ef127b60..4a2e8aa6b381ac 100644 --- a/spec/services/snippets/count_service_spec.rb +++ b/spec/services/snippets/count_service_spec.rb @@ -2,9 +2,15 @@ require 'spec_helper' -RSpec.describe Snippets::CountService, :with_current_organization, feature_category: :source_code_management do +RSpec.describe Snippets::CountService, feature_category: :source_code_management do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public) } + let_it_be(:current_organization) { create(:organization) } + + before do + # Since this doesn't go through a request flow, we need to manually set Current.organization + Current.organization = current_organization + end describe '#new' do it 'raises an error if no author or project' do -- GitLab From 325877f7ee4a17a6a3238809a064a03e0840ba84 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Wed, 26 Nov 2025 15:36:10 +0000 Subject: [PATCH 05/25] Use :with_current_organization trait in EE snippet search results spec --- ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb index da46ccb5ef226c..dd8c5064724b18 100644 --- a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb +++ b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Gitlab::SnippetSearchResults do +RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do let_it_be(:snippet) { create(:project_snippet, title: 'foo', description: 'foo') } - let_it_be(:current_organization) { create(:organization) } let(:user) { snippet.author } let(:com_value) { true } @@ -12,8 +11,6 @@ before do allow(Gitlab).to receive(:com?).and_return(com_value) - # Since this doesn't go through a request flow, we need to manually set Current.organization - Current.organization = current_organization end context 'when all requirements are met' do -- GitLab From 51aa2a2edbb719bd59fc426da95486b0ee62544b Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Wed, 26 Nov 2025 16:17:56 +0000 Subject: [PATCH 06/25] Use :with_current_organization trait in snippet_search_results_spec.rb Replace manual organization creation and Current.organization assignment with the :with_current_organization RSpec metadata trait, consistent with the EE spec and other specs in the codebase. --- spec/lib/gitlab/snippet_search_results_spec.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index 214975a8aa9fe7..b8725d60522fa4 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -2,19 +2,13 @@ require 'spec_helper' -RSpec.describe Gitlab::SnippetSearchResults do +RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do include SearchHelpers let_it_be(:snippet) { create(:personal_snippet, content: 'foo', file_name: 'foo') } - let_it_be(:current_organization) { create(:organization) } let(:results) { described_class.new(snippet.author, 'foo') } - before do - # Since this doesn't go through a request flow, we need to manually set Current.organization - Current.organization = current_organization - end - describe '#snippet_titles_count' do it 'returns the amount of matched snippet titles' do expect(results.limited_snippet_titles_count).to eq(1) -- GitLab From 056204348ff275ff9ba5d4aa3b518efc433aaf34 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Wed, 26 Nov 2025 16:23:09 +0000 Subject: [PATCH 07/25] Use ::Current.organization.id in snippet_search_results.rb Use the fully qualified constant ::Current.organization.id instead of Current.organization.id for consistency with codebase conventions. --- lib/gitlab/snippet_search_results.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/snippet_search_results.rb b/lib/gitlab/snippet_search_results.rb index 71dc877f08d563..241fde412ea094 100644 --- a/lib/gitlab/snippet_search_results.rb +++ b/lib/gitlab/snippet_search_results.rb @@ -37,7 +37,7 @@ def paginated_objects(relation, page, per_page) def finder_params # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter - { organization_id: Current.organization.id } + { organization_id: ::Current.organization.id } # rubocop: enable Gitlab/AvoidCurrentOrganization end end -- GitLab From eb70cf8ed828aef3f1b44dc0ec89be39c2fa4780 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Wed, 26 Nov 2025 16:28:33 +0000 Subject: [PATCH 08/25] Update count_service_spec to use :with_current_organization - Add :with_current_organization trait to RSpec.describe - Remove manual organization creation and Current.organization setup - Update SnippetsFinder expectations to include organization_id parameter --- spec/services/snippets/count_service_spec.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/spec/services/snippets/count_service_spec.rb b/spec/services/snippets/count_service_spec.rb index 4a2e8aa6b381ac..93bb9df8a5b2a0 100644 --- a/spec/services/snippets/count_service_spec.rb +++ b/spec/services/snippets/count_service_spec.rb @@ -2,15 +2,9 @@ require 'spec_helper' -RSpec.describe Snippets::CountService, feature_category: :source_code_management do +RSpec.describe Snippets::CountService, :with_current_organization, feature_category: :source_code_management do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public) } - let_it_be(:current_organization) { create(:organization) } - - before do - # Since this doesn't go through a request flow, we need to manually set Current.organization - Current.organization = current_organization - end describe '#new' do it 'raises an error if no author or project' do @@ -20,7 +14,7 @@ it 'uses the SnippetsFinder to scope snippets by user' do expect(SnippetsFinder) .to receive(:new) - .with(user, author: user, project: nil) + .with(user, author: user, project: nil, organization_id: Current.organization.id) described_class.new(user, author: user) end @@ -28,7 +22,7 @@ it 'allows scoping to project' do expect(SnippetsFinder) .to receive(:new) - .with(user, author: nil, project: project) + .with(user, author: nil, project: project, organization_id: Current.organization.id) described_class.new(user, project: project) end -- GitLab From 84ab75555d512a6dca7027c30b41e81aa403039f Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Thu, 27 Nov 2025 21:13:41 +0000 Subject: [PATCH 09/25] Fix specs: Set Current.organization in before block The specs for SnippetsFinder-related services need to manually set Current.organization since they don't go through the normal request flow where the middleware would set it automatically. This fixes the failing specs: - spec/lib/gitlab/snippet_search_results_spec.rb - spec/services/snippets/count_service_spec.rb - ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb --- ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb | 5 +++++ spec/lib/gitlab/snippet_search_results_spec.rb | 5 +++++ spec/services/snippets/count_service_spec.rb | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb index dd8c5064724b18..92e4e6ee064a56 100644 --- a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb +++ b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb @@ -2,6 +2,11 @@ require 'spec_helper' RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do + before do + # Since this doesn't go through a request flow, we need to manually set Current.organization + Current.organization = current_organization + end + let_it_be(:snippet) { create(:project_snippet, title: 'foo', description: 'foo') } let(:user) { snippet.author } diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index b8725d60522fa4..883b7bfb75a1da 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -5,6 +5,11 @@ RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do include SearchHelpers + before do + # Since this doesn't go through a request flow, we need to manually set Current.organization + Current.organization = current_organization + end + let_it_be(:snippet) { create(:personal_snippet, content: 'foo', file_name: 'foo') } let(:results) { described_class.new(snippet.author, 'foo') } diff --git a/spec/services/snippets/count_service_spec.rb b/spec/services/snippets/count_service_spec.rb index 93bb9df8a5b2a0..e6760aa2424fc5 100644 --- a/spec/services/snippets/count_service_spec.rb +++ b/spec/services/snippets/count_service_spec.rb @@ -3,6 +3,11 @@ require 'spec_helper' RSpec.describe Snippets::CountService, :with_current_organization, feature_category: :source_code_management do + before do + # Since this doesn't go through a request flow, we need to manually set Current.organization + Current.organization = current_organization + end + let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public) } -- GitLab From 5ffd8654e499c117ab2d9c08317f3605a1874768 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Thu, 27 Nov 2025 21:16:09 +0000 Subject: [PATCH 10/25] Fix EE spec: Update mock expectations for organization_id The SnippetsFinder mock expectations need to include the organization_id parameter that's now being passed. --- ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb index 92e4e6ee064a56..46fbd0235798dd 100644 --- a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb +++ b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb @@ -20,7 +20,7 @@ context 'when all requirements are met' do it 'calls the finder with the restrictive scope' do - expect(SnippetsFinder).to receive(:new).with(user, { authorized_and_user_personal: true }).and_call_original + expect(SnippetsFinder).to receive(:new).with(user, { authorized_and_user_personal: true, organization_id: current_organization.id }).and_call_original subject end @@ -30,7 +30,7 @@ let(:com_value) { false } it 'calls the finder with the restrictive scope' do - expect(SnippetsFinder).to receive(:new).with(user, {}).and_call_original + expect(SnippetsFinder).to receive(:new).with(user, { organization_id: current_organization.id }).and_call_original subject end -- GitLab From 26d94e78b76bdf262578e1c9a1e116ccd98ef0de Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Thu, 27 Nov 2025 21:22:34 +0000 Subject: [PATCH 11/25] Fix RuboCop offenses in snippet search spec Consolidate before hooks and fix line length in ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb --- .../lib/ee/gitlab/snippet_search_results_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb index 46fbd0235798dd..4ebe7dc3b19ca9 100644 --- a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb +++ b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb @@ -5,6 +5,7 @@ before do # Since this doesn't go through a request flow, we need to manually set Current.organization Current.organization = current_organization + allow(Gitlab).to receive(:com?).and_return(com_value) end let_it_be(:snippet) { create(:project_snippet, title: 'foo', description: 'foo') } @@ -14,13 +15,12 @@ subject { described_class.new(user, 'foo').objects('snippet_titles') } - before do - allow(Gitlab).to receive(:com?).and_return(com_value) - end - context 'when all requirements are met' do it 'calls the finder with the restrictive scope' do - expect(SnippetsFinder).to receive(:new).with(user, { authorized_and_user_personal: true, organization_id: current_organization.id }).and_call_original + expect(SnippetsFinder).to receive(:new).with( + user, + { authorized_and_user_personal: true, organization_id: current_organization.id } + ).and_call_original subject end @@ -30,7 +30,10 @@ let(:com_value) { false } it 'calls the finder with the restrictive scope' do - expect(SnippetsFinder).to receive(:new).with(user, { organization_id: current_organization.id }).and_call_original + expect(SnippetsFinder).to receive(:new).with( + user, + { organization_id: current_organization.id } + ).and_call_original subject end -- GitLab From b9a5319a9d29806aaa0a156a7b7e721d70c8a863 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Thu, 27 Nov 2025 22:04:58 +0000 Subject: [PATCH 12/25] Merge organization_id with authorized_and_user_personal in EE Update EE override to merge organization_id from base class with authorized_and_user_personal parameter for GitLab.com. --- ee/lib/ee/gitlab/snippet_search_results.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ee/lib/ee/gitlab/snippet_search_results.rb b/ee/lib/ee/gitlab/snippet_search_results.rb index 0311f8882523e3..8bd99dfb4c8e3c 100644 --- a/ee/lib/ee/gitlab/snippet_search_results.rb +++ b/ee/lib/ee/gitlab/snippet_search_results.rb @@ -9,9 +9,10 @@ module SnippetSearchResults # https://gitlab.com/gitlab-org/gitlab/issues/26123 override :finder_params def finder_params - return super unless ::Gitlab.com? + params = super + return params unless ::Gitlab.com? - { authorized_and_user_personal: true } + params.merge(authorized_and_user_personal: true) end end end -- GitLab From 5c2b3f6c934c5d946d6f6f4b681b7183f02115c6 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Fri, 28 Nov 2025 17:06:02 +0000 Subject: [PATCH 13/25] Add feature_category to snippet_search_results_spec --- ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb index 4ebe7dc3b19ca9..7034b4d7107632 100644 --- a/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb +++ b/ee/spec/lib/ee/gitlab/snippet_search_results_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do +RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization, feature_category: :global_search do before do # Since this doesn't go through a request flow, we need to manually set Current.organization Current.organization = current_organization -- GitLab From 7f670f9ab0868a6bc3120c0983a3f2c219ce4e43 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Fri, 28 Nov 2025 17:09:22 +0000 Subject: [PATCH 14/25] Add feature_category to remaining spec files --- spec/finders/notes_finder_spec.rb | 2 +- spec/lib/gitlab/snippet_search_results_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb index 07a52f4ca93dfd..356dd31acca678 100644 --- a/spec/finders/notes_finder_spec.rb +++ b/spec/finders/notes_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe NotesFinder, :with_current_organization do +RSpec.describe NotesFinder, :with_current_organization, feature_category: :team_planning do let(:user) { create(:user) } let(:project) { create(:project) } diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index 883b7bfb75a1da..2d5b905b92c46c 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization do +RSpec.describe Gitlab::SnippetSearchResults, :with_current_organization, feature_category: :global_search do include SearchHelpers before do -- GitLab From ddbbac8cd01a5ae631e3d870ea14c83a82ba0e4d Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Tue, 2 Dec 2025 17:17:43 +0000 Subject: [PATCH 15/25] Add reasons to RuboCop inline disable comments Address Danger bot feedback by adding explanations for why CodeReuse/Finder must be disabled in these specific cases. --- app/finders/notes_finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index 86d392828a1b73..e2857d6b76ff3d 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -123,7 +123,7 @@ def noteables_for_type(noteable_type) # rubocop: enable Gitlab/AvoidCurrentOrganization when "personal_snippet" # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter - SnippetsFinder.new(@current_user, organization_id: Current.organization.id, only_personal: true).execute # rubocop: disable CodeReuse/Finder + SnippetsFinder.new(@current_user, organization_id: Current.organization.id, only_personal: true).execute # rubocop: disable CodeReuse/Finder -- NotesFinder is itself a finder that needs to delegate to SnippetsFinder # rubocop: enable Gitlab/AvoidCurrentOrganization when "wiki_page/meta" WikiPage::Meta.for_project(@project) -- GitLab From 65710b1e1fe3290b6c3b0f8cfd1af1d75948b8be Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Thu, 4 Dec 2025 19:06:49 +0000 Subject: [PATCH 16/25] Add explicit test coverage for organization_id in SnippetsFinder calls This commit adds explicit test coverage to verify that organization_id is properly passed to SnippetsFinder in the following scenarios: 1. NotesFinder - Verifies organization_id is passed when finding notes for snippet, project_snippet, and personal_snippet noteable types 2. AutocompleteService - Verifies organization_id is passed when fetching snippets for autocomplete 3. SnippetSearchResults - Verifies finder_params includes organization_id These tests ensure the organization context is properly propagated through the snippet finding logic and would fail if the organization_id parameter was removed from the implementation. --- spec/finders/notes_finder_spec.rb | 33 +++++++++++++++++++ .../lib/gitlab/snippet_search_results_spec.rb | 12 +++++++ .../projects/autocomplete_service_spec.rb | 18 ++++++++++ 3 files changed, 63 insertions(+) diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb index 356dd31acca678..93cfc874f2a5ef 100644 --- a/spec/finders/notes_finder_spec.rb +++ b/spec/finders/notes_finder_spec.rb @@ -274,6 +274,39 @@ end end end + + context 'organization_id parameter for snippet noteables', :with_current_organization do + let_it_be(:current_organization) { create(:organization) } + + %w[snippet project_snippet personal_snippet].each do |noteable_type| + context "when target_type is #{noteable_type}" do + let(:snippet) do + case noteable_type + when 'snippet', 'project_snippet' + create(:project_snippet, project: project) + when 'personal_snippet' + create(:personal_snippet, author: user) + end + end + + let(:note) { create(:note, noteable: snippet, project: noteable_type == 'personal_snippet' ? nil : project) } + let(:params) { { project: project, target_type: noteable_type, target_id: note.noteable.id } } + + before do + Current.organization = current_organization + end + + it 'passes organization_id to SnippetsFinder' do + expect(SnippetsFinder).to receive(:new).with( + user, + hash_including(organization_id: current_organization.id) + ).and_call_original + + described_class.new(user, params).execute + end + end + end + end end context 'for explicit target' do diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index 2d5b905b92c46c..7230b897899017 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -42,4 +42,16 @@ expect(results.objects('snippet_titles', page: 1, per_page: 2).count).to eq(2) end end + + describe '#finder_params', :with_current_organization do + let_it_be(:current_organization) { create(:organization) } + + before do + Current.organization = current_organization + end + + it 'includes organization_id' do + expect(results.send(:finder_params)).to include(organization_id: current_organization.id) + end + end end diff --git a/spec/services/projects/autocomplete_service_spec.rb b/spec/services/projects/autocomplete_service_spec.rb index a8572c758c2dc3..936addbd92c280 100644 --- a/spec/services/projects/autocomplete_service_spec.rb +++ b/spec/services/projects/autocomplete_service_spec.rb @@ -364,4 +364,22 @@ def expect_labels_to_equal(labels, expected_labels) end end end + + describe '#snippets', :with_current_organization do + let_it_be(:current_organization) { create(:organization) } + let_it_be(:user) { create(:user) } + + before do + Current.organization = current_organization + end + + it 'passes organization_id to SnippetsFinder' do + expect(SnippetsFinder).to receive(:new).with( + user, + hash_including(organization_id: current_organization.id) + ).and_call_original + + described_class.new(project, user).snippets + end + end end -- GitLab From da0448a0b4ba5a6f7ccef2b0dc18fabb75a379c4 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Thu, 4 Dec 2025 19:08:23 +0000 Subject: [PATCH 17/25] Remove redundant organization setup in tests The :with_current_organization shared context already provides current_organization and sets Current.organization, so we don't need to redefine it or set it again in the test blocks. --- spec/finders/notes_finder_spec.rb | 2 -- spec/lib/gitlab/snippet_search_results_spec.rb | 5 ----- spec/services/projects/autocomplete_service_spec.rb | 5 ----- 3 files changed, 12 deletions(-) diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb index 93cfc874f2a5ef..d4ca2b123181e3 100644 --- a/spec/finders/notes_finder_spec.rb +++ b/spec/finders/notes_finder_spec.rb @@ -276,8 +276,6 @@ end context 'organization_id parameter for snippet noteables', :with_current_organization do - let_it_be(:current_organization) { create(:organization) } - %w[snippet project_snippet personal_snippet].each do |noteable_type| context "when target_type is #{noteable_type}" do let(:snippet) do diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index 7230b897899017..eb89869ab52491 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -44,11 +44,6 @@ end describe '#finder_params', :with_current_organization do - let_it_be(:current_organization) { create(:organization) } - - before do - Current.organization = current_organization - end it 'includes organization_id' do expect(results.send(:finder_params)).to include(organization_id: current_organization.id) diff --git a/spec/services/projects/autocomplete_service_spec.rb b/spec/services/projects/autocomplete_service_spec.rb index 936addbd92c280..eb9d665644f7a0 100644 --- a/spec/services/projects/autocomplete_service_spec.rb +++ b/spec/services/projects/autocomplete_service_spec.rb @@ -366,13 +366,8 @@ def expect_labels_to_equal(labels, expected_labels) end describe '#snippets', :with_current_organization do - let_it_be(:current_organization) { create(:organization) } let_it_be(:user) { create(:user) } - before do - Current.organization = current_organization - end - it 'passes organization_id to SnippetsFinder' do expect(SnippetsFinder).to receive(:new).with( user, -- GitLab From 785be84d73536f089b161b7e19c8520b5ae794a4 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Thu, 4 Dec 2025 19:13:51 +0000 Subject: [PATCH 18/25] Remove extra blank line in snippet_search_results_spec.rb --- spec/lib/gitlab/snippet_search_results_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index eb89869ab52491..85c41b807239a1 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -44,7 +44,6 @@ end describe '#finder_params', :with_current_organization do - it 'includes organization_id' do expect(results.send(:finder_params)).to include(organization_id: current_organization.id) end -- GitLab From c09664f0fc258e4d768201d38bb7cb508d42164f Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Thu, 4 Dec 2025 21:08:31 +0000 Subject: [PATCH 19/25] Fix Current.organization test setup issues - Remove duplicate Current.organization assignment in notes_finder_spec.rb nested context - Add before block to set Current.organization in autocomplete_service_spec.rb #snippets test --- spec/finders/notes_finder_spec.rb | 4 ---- spec/services/projects/autocomplete_service_spec.rb | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb index d4ca2b123181e3..37e65d0b06a49c 100644 --- a/spec/finders/notes_finder_spec.rb +++ b/spec/finders/notes_finder_spec.rb @@ -290,10 +290,6 @@ let(:note) { create(:note, noteable: snippet, project: noteable_type == 'personal_snippet' ? nil : project) } let(:params) { { project: project, target_type: noteable_type, target_id: note.noteable.id } } - before do - Current.organization = current_organization - end - it 'passes organization_id to SnippetsFinder' do expect(SnippetsFinder).to receive(:new).with( user, diff --git a/spec/services/projects/autocomplete_service_spec.rb b/spec/services/projects/autocomplete_service_spec.rb index eb9d665644f7a0..a9321b4838f2ad 100644 --- a/spec/services/projects/autocomplete_service_spec.rb +++ b/spec/services/projects/autocomplete_service_spec.rb @@ -368,6 +368,11 @@ def expect_labels_to_equal(labels, expected_labels) describe '#snippets', :with_current_organization do let_it_be(:user) { create(:user) } + before do + # Since this doesn't go through a request flow, we need to manually set Current.organization + Current.organization = current_organization + end + it 'passes organization_id to SnippetsFinder' do expect(SnippetsFinder).to receive(:new).with( user, -- GitLab From 3bc61651a59b60f87ac960ce0d19748ba34d4f44 Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Tue, 9 Dec 2025 16:33:35 -0500 Subject: [PATCH 20/25] Remove redundant :with_current_organization --- spec/finders/notes_finder_spec.rb | 2 +- spec/lib/gitlab/snippet_search_results_spec.rb | 2 +- spec/services/projects/autocomplete_service_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb index 37e65d0b06a49c..795fb32d571454 100644 --- a/spec/finders/notes_finder_spec.rb +++ b/spec/finders/notes_finder_spec.rb @@ -275,7 +275,7 @@ end end - context 'organization_id parameter for snippet noteables', :with_current_organization do + context 'organization_id parameter for snippet noteables' do %w[snippet project_snippet personal_snippet].each do |noteable_type| context "when target_type is #{noteable_type}" do let(:snippet) do diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index 85c41b807239a1..4ea7e6686c2c3d 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -43,7 +43,7 @@ end end - describe '#finder_params', :with_current_organization do + describe '#finder_params' do it 'includes organization_id' do expect(results.send(:finder_params)).to include(organization_id: current_organization.id) end diff --git a/spec/services/projects/autocomplete_service_spec.rb b/spec/services/projects/autocomplete_service_spec.rb index a9321b4838f2ad..0e57ca2cdf06b3 100644 --- a/spec/services/projects/autocomplete_service_spec.rb +++ b/spec/services/projects/autocomplete_service_spec.rb @@ -365,7 +365,7 @@ def expect_labels_to_equal(labels, expected_labels) end end - describe '#snippets', :with_current_organization do + describe '#snippets' do let_it_be(:user) { create(:user) } before do -- GitLab From 73a8d010f9c2adadded8a17243921429180ea02d Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Fri, 12 Dec 2025 21:36:00 +0000 Subject: [PATCH 21/25] Refactor NotesFinder to accept organization_id parameter Update NotesFinder to accept an optional organization_id parameter via the params hash, following the same pattern as SnippetsFinder. The organization_id is extracted from params and stored as an instance variable, then passed to SnippetsFinder when finding snippet noteables. This removes the need for Current.organization.id calls and associated rubocop disable comments, while maintaining backward compatibility. --- app/finders/notes_finder.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index e2857d6b76ff3d..90860bda1e8d3a 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -118,13 +118,9 @@ def noteables_for_type(noteable_type) when "merge_request" MergeRequestsFinder.new(@current_user, project_id: @project.id).execute # rubocop: disable CodeReuse/Finder when "snippet", "project_snippet" - # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter - SnippetsFinder.new(@current_user, organization_id: Current.organization.id, project: @project).execute # rubocop: disable CodeReuse/Finder - # rubocop: enable Gitlab/AvoidCurrentOrganization + SnippetsFinder.new(@current_user, organization_id: @organization_id, project: @project).execute # rubocop: disable CodeReuse/Finder when "personal_snippet" - # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter - SnippetsFinder.new(@current_user, organization_id: Current.organization.id, only_personal: true).execute # rubocop: disable CodeReuse/Finder -- NotesFinder is itself a finder that needs to delegate to SnippetsFinder - # rubocop: enable Gitlab/AvoidCurrentOrganization + SnippetsFinder.new(@current_user, organization_id: @organization_id, only_personal: true).execute # rubocop: disable CodeReuse/Finder when "wiki_page/meta" WikiPage::Meta.for_project(@project) else -- GitLab From 05ddcff6f9f1ab41533e0f7b3ef0eadcb03463de Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Fri, 12 Dec 2025 21:36:40 +0000 Subject: [PATCH 22/25] Update NotesFinder spec to pass organization_id in params Update the test to pass organization_id through the params hash instead of relying on Current.organization.id, matching the new NotesFinder signature. --- spec/finders/notes_finder_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb index 795fb32d571454..22995a35f16e9a 100644 --- a/spec/finders/notes_finder_spec.rb +++ b/spec/finders/notes_finder_spec.rb @@ -288,7 +288,7 @@ end let(:note) { create(:note, noteable: snippet, project: noteable_type == 'personal_snippet' ? nil : project) } - let(:params) { { project: project, target_type: noteable_type, target_id: note.noteable.id } } + let(:params) { { organization_id: current_organization.id, project: project, target_type: noteable_type, target_id: note.noteable.id } } it 'passes organization_id to SnippetsFinder' do expect(SnippetsFinder).to receive(:new).with( -- GitLab From 639a8323836bd8b449cf71bfe51562fe09638efe Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Fri, 12 Dec 2025 21:41:12 +0000 Subject: [PATCH 23/25] Fix: Add missing @organization_id assignment in NotesFinder Add the missing line to extract and assign @organization_id from params in the initialize method. --- app/finders/notes_finder.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index 90860bda1e8d3a..2f88a787f258ab 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -23,6 +23,7 @@ def initialize(current_user, params = {}) @project = params[:project] @current_user = current_user @params = params.dup + @organization_id = @params.delete(:organization_id) @target_type = @params[:target_type] end -- GitLab From 473cabeca5ccdd98b180cc685969a507cde417fb Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Fri, 12 Dec 2025 21:43:51 +0000 Subject: [PATCH 24/25] Refactor CountService to accept organization_id parameter Update Snippets::CountService to accept an optional organization_id parameter instead of using Current.organization.id directly. This removes the need for rubocop disable comments while maintaining backward compatibility. --- app/services/snippets/count_service.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/services/snippets/count_service.rb b/app/services/snippets/count_service.rb index 47bf807621123d..112a4dac6ef0bc 100644 --- a/app/services/snippets/count_service.rb +++ b/app/services/snippets/count_service.rb @@ -34,21 +34,19 @@ # Either a project or an author *must* be supplied. module Snippets class CountService - def initialize(current_user, author: nil, project: nil) + def initialize(current_user, organization_id: nil, author: nil, project: nil) if !author && !project raise( ArgumentError, 'Must provide either an author or a project' ) end - # rubocop: disable Gitlab/AvoidCurrentOrganization -- Will be refactored to accept organization_id parameter @snippets_finder = SnippetsFinder.new( current_user, - organization_id: Current.organization.id, + organization_id: organization_id, author: author, project: project ) - # rubocop: enable Gitlab/AvoidCurrentOrganization end def execute -- GitLab From 31dab36b3a186865c3313b3afc2f068212a6adba Mon Sep 17 00:00:00 2001 From: Chen Zhang Date: Fri, 12 Dec 2025 21:44:13 +0000 Subject: [PATCH 25/25] Update CountService spec to pass organization_id parameter Update the test to pass organization_id as a parameter to CountService instead of relying on Current.organization.id. --- spec/services/snippets/count_service_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/services/snippets/count_service_spec.rb b/spec/services/snippets/count_service_spec.rb index e6760aa2424fc5..15bd6854e13b8c 100644 --- a/spec/services/snippets/count_service_spec.rb +++ b/spec/services/snippets/count_service_spec.rb @@ -19,17 +19,17 @@ it 'uses the SnippetsFinder to scope snippets by user' do expect(SnippetsFinder) .to receive(:new) - .with(user, author: user, project: nil, organization_id: Current.organization.id) + .with(user, author: user, project: nil, organization_id: current_organization.id) - described_class.new(user, author: user) + described_class.new(user, organization_id: current_organization.id, author: user) end it 'allows scoping to project' do expect(SnippetsFinder) .to receive(:new) - .with(user, author: nil, project: project, organization_id: Current.organization.id) + .with(user, author: nil, project: project, organization_id: current_organization.id) - described_class.new(user, project: project) + described_class.new(user, organization_id: current_organization.id, project: project) end end -- GitLab