diff --git a/app/controllers/dashboard/snippets_controller.rb b/app/controllers/dashboard/snippets_controller.rb index 3632deb7d3c99412ccf9309dcfe3a7bce175ce1d..6c1ae6565a00ab8e74288710f1665f3624cb6826 100644 --- a/app/controllers/dashboard/snippets_controller.rb +++ b/app/controllers/dashboard/snippets_controller.rb @@ -14,7 +14,8 @@ def index .new(current_user, author: current_user) .execute - @snippets = SnippetsFinder.new(current_user, author: current_user, scope: params[:scope], sort: sort_param) + @snippets = SnippetsFinder.new(current_user, organization_id: Current.organization.id, author: current_user, + scope: params[:scope], sort: sort_param) .execute .page(pagination_params[:page]) .inc_author diff --git a/app/controllers/explore/snippets_controller.rb b/app/controllers/explore/snippets_controller.rb index c788909ab498e8952b175ec181d3d952ea0475ac..86cdcfe8f2dad6855ef310ebe2a2108ec503eee9 100644 --- a/app/controllers/explore/snippets_controller.rb +++ b/app/controllers/explore/snippets_controller.rb @@ -6,7 +6,7 @@ class Explore::SnippetsController < Explore::ApplicationController feature_category :source_code_management def index - @snippets = SnippetsFinder.new(current_user, explore: true) + @snippets = SnippetsFinder.new(current_user, organization_id: Current.organization.id, explore: true) .execute .page(pagination_params[:page]) .without_count diff --git a/app/controllers/projects/snippets_controller.rb b/app/controllers/projects/snippets_controller.rb index 76e2da6eb57d030c4ea16a8b80dcb7f61824a39a..f77b69081eb99bbccbc509b238fb928f9425f1fb 100644 --- a/app/controllers/projects/snippets_controller.rb +++ b/app/controllers/projects/snippets_controller.rb @@ -21,7 +21,8 @@ def index .new(current_user, project: @project) .execute - @snippets = SnippetsFinder.new(current_user, project: @project, scope: params[:scope], sort: sort_param) + @snippets = SnippetsFinder.new(current_user, organization_id: Current.organization.id, project: @project, + scope: params[:scope], sort: sort_param) .execute .page(params[:page]) .inc_author diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 38de86416be16a44454b8e1c1d793d8b354cd03a..cdcd1404b24023ce65a061c45a1aecee00d78494 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -305,7 +305,8 @@ def load_groups end def load_snippets - @snippets = SnippetsFinder.new(current_user, author: user, scope: params[:scope]) + @snippets = SnippetsFinder.new(current_user, organization_id: Current.organization.id, author: user, + scope: params[:scope]) .execute .page(params[:page]) .inc_author diff --git a/app/finders/snippets_finder.rb b/app/finders/snippets_finder.rb index 6e46d67ed3f51dd351f05980697408caa96b6009..b67ba3cd1b0c73669a94d3d07d34f378eee36642 100644 --- a/app/finders/snippets_finder.rb +++ b/app/finders/snippets_finder.rb @@ -224,7 +224,7 @@ def by_ids(snippets) def by_organization(snippets) return snippets unless should_apply_organization_filter? - snippets.for_user_organization(organization_id) + snippets.in_organization(organization_id) end def should_apply_organization_filter? diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 9f193f47cfac0bcb8ccfc73649c3097ebacb6836..696ca2ccb6e7b4d13520621aac9ee9e2b72658bd 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -82,7 +82,7 @@ def content_html_invalidated? scope :with_repository_storage_moves, -> { joins(:repository_storage_moves) } scope :inc_projects_namespace_route, -> { includes(project: [:route, :namespace]) } - scope :for_user_organization, ->(organization_id) do + scope :in_organization, ->(organization_id) do where.not(project_id: nil).or(where(project_id: nil, organization_id: organization_id)) end diff --git a/ee/spec/features/search/elastic/snippet_search_spec.rb b/ee/spec/features/search/elastic/snippet_search_spec.rb index 6a7302e1a3219780382ae9cb5320a2845c531232..e4fc321d61ba375f588c32706c0fb02e3fc9a99a 100644 --- a/ee/spec/features/search/elastic/snippet_search_spec.rb +++ b/ee/spec/features/search/elastic/snippet_search_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe 'Snippet elastic search', :js, :elastic_delete_by_query, :aggregate_failures, feature_category: :global_search do +RSpec.describe 'Snippet elastic search', :js, :elastic_delete_by_query, :aggregate_failures, :with_current_organization, feature_category: :global_search do let_it_be(:public_project) { create(:project, :public) } let_it_be(:regular_user) { create(:user) } let_it_be(:authorized_user) { create(:user) } diff --git a/spec/controllers/explore/snippets_controller_spec.rb b/spec/controllers/explore/snippets_controller_spec.rb index e93e8502dfcc34a2d9f50e9580d913916dcde840..d1577bc7fb4bdfd86ea6b19a589ce6e4abd96ca2 100644 --- a/spec/controllers/explore/snippets_controller_spec.rb +++ b/spec/controllers/explore/snippets_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Explore::SnippetsController do +RSpec.describe Explore::SnippetsController, :with_current_organization, feature_category: :source_code_management do describe 'GET #index' do let!(:project_snippet) { create_list(:project_snippet, 3, :public) } let!(:personal_snippet) { create_list(:personal_snippet, 3, :public) } diff --git a/spec/controllers/projects/snippets_controller_spec.rb b/spec/controllers/projects/snippets_controller_spec.rb index 3b52f4dcf8ad62cd4b40823c5cec62a489d4aa9f..6f2afa27f660bf0fb6c404ee61629a995c2ec0c0 100644 --- a/spec/controllers/projects/snippets_controller_spec.rb +++ b/spec/controllers/projects/snippets_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::SnippetsController do +RSpec.describe Projects::SnippetsController, :with_current_organization, feature_category: :source_code_management do include Gitlab::Routing let_it_be(:user) { create(:user) } diff --git a/spec/features/dashboard/shortcuts_spec.rb b/spec/features/dashboard/shortcuts_spec.rb index 6066bd57d0180697d2959beb0a87bf4ecc98e291..a9fc319c1234ec35ee255ba656c5dcd3045fd765 100644 --- a/spec/features/dashboard/shortcuts_spec.rb +++ b/spec/features/dashboard/shortcuts_spec.rb @@ -58,7 +58,7 @@ end end - context 'logged out' do + context 'logged out', :with_current_organization do before do visit explore_root_path end diff --git a/spec/features/snippets/explore_spec.rb b/spec/features/snippets/explore_spec.rb index 139866b5b0b04f686d5c5acd30a805074193c228..a38641c9c671d16584389525a7de6bcc0fcd5f0c 100644 --- a/spec/features/snippets/explore_spec.rb +++ b/spec/features/snippets/explore_spec.rb @@ -58,7 +58,7 @@ end end - context 'when user is not authenticated' do + context 'when user is not authenticated', :with_current_organization do before do visit explore_snippets_path end diff --git a/spec/features/users/snippets_spec.rb b/spec/features/users/snippets_spec.rb index 7f73027ede364e0be5ca73384b7054861aed5e69..67a093cae2a5348ce068829e983a908ff451fd18 100644 --- a/spec/features/users/snippets_spec.rb +++ b/spec/features/users/snippets_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe 'Snippets tab on a user profile', :js, feature_category: :source_code_management do +RSpec.describe 'Snippets tab on a user profile', :with_current_organization, :js, feature_category: :source_code_management do context 'when the user has snippets' do let(:user) { create(:user) } diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 48d0a15e17a54d9980c61997cafae2472ea2890f..543890c79a79ffd0d0227162fda4be3e825ebcae 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -42,7 +42,7 @@ end end - describe '.for_user_organization' do + describe '.in_organization' do let_it_be(:organization) { create(:organization) } let_it_be(:other_organization) { create(:organization) } let_it_be(:project) { create(:project, organization: organization) } @@ -56,7 +56,7 @@ let_it_be(:project_snippet) { create(:project_snippet, project: project) } let_it_be(:project_snippet_other_org) { create(:project_snippet, project: other_project) } - subject { described_class.for_user_organization(organization.id) } + subject { described_class.in_organization(organization.id) } it 'returns personal snippets for the specified organization' do expect(subject).to include(personal_snippet_in_org)