From a8c410f8a115b82a614b81cfd1036498838a5a5b Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 26 May 2023 15:08:09 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- .rubocop_todo/layout/line_length.yml | 2 +- .rubocop_todo/layout/space_inside_parens.yml | 2 +- .../lint/ambiguous_operator_precedence.yml | 2 +- .rubocop_todo/rspec/context_wording.yml | 2 +- .../rspec/missing_feature_category.yml | 2 +- .rubocop_todo/style/guard_clause.yml | 2 +- .../development/openai_moderation.yml | 8 -- .../carrierwave_performance_patch.rb | 47 ++++++++++ ...arrierwave_s3_encryption_headers_patch.rb} | 0 .../carrierwave_performance_patch_spec.rb | 87 +++++++++++++++++++ ...rwave_s3_encryption_headers_patch_spec.rb} | 2 +- 11 files changed, 141 insertions(+), 15 deletions(-) delete mode 100644 config/feature_flags/development/openai_moderation.yml create mode 100644 config/initializers/carrierwave_performance_patch.rb rename config/initializers/{carrierwave_patch.rb => carrierwave_s3_encryption_headers_patch.rb} (100%) create mode 100644 spec/initializers/carrierwave_performance_patch_spec.rb rename spec/initializers/{carrierwave_patch_spec.rb => carrierwave_s3_encryption_headers_patch_spec.rb} (97%) diff --git a/.rubocop_todo/layout/line_length.yml b/.rubocop_todo/layout/line_length.yml index 221b5cc0f1e..91c47aad503 100644 --- a/.rubocop_todo/layout/line_length.yml +++ b/.rubocop_todo/layout/line_length.yml @@ -710,7 +710,7 @@ Layout/LineLength: - 'config/initializers/active_record_force_reconnects.rb' - 'config/initializers/active_record_keyset_pagination.rb' - 'config/initializers/active_record_schema_versions.rb' - - 'config/initializers/carrierwave_patch.rb' + - 'config/initializers/carrierwave_s3_encryption_headers_patch.rb' - 'config/initializers/deprecations.rb' - 'config/initializers/devise_dynamic_password_length_validation.rb' - 'config/initializers/direct_upload_support.rb' diff --git a/.rubocop_todo/layout/space_inside_parens.yml b/.rubocop_todo/layout/space_inside_parens.yml index b27fae0c6be..8468c214a78 100644 --- a/.rubocop_todo/layout/space_inside_parens.yml +++ b/.rubocop_todo/layout/space_inside_parens.yml @@ -101,7 +101,7 @@ Layout/SpaceInsideParens: - 'spec/helpers/gitlab_routing_helper_spec.rb' - 'spec/helpers/gitlab_script_tag_helper_spec.rb' - 'spec/helpers/tab_helper_spec.rb' - - 'spec/initializers/carrierwave_patch_spec.rb' + - 'spec/initializers/carrierwave_s3_encryption_headers_patch_spec.rb' - 'spec/initializers/rdoc_segfault_patch_spec.rb' - 'spec/lib/api/entities/snippet_spec.rb' - 'spec/lib/banzai/filter/references/alert_reference_filter_spec.rb' diff --git a/.rubocop_todo/lint/ambiguous_operator_precedence.yml b/.rubocop_todo/lint/ambiguous_operator_precedence.yml index a890c6af6d0..971130ec2ad 100644 --- a/.rubocop_todo/lint/ambiguous_operator_precedence.yml +++ b/.rubocop_todo/lint/ambiguous_operator_precedence.yml @@ -31,7 +31,7 @@ Lint/AmbiguousOperatorPrecedence: - 'app/services/issues/relative_position_rebalancing_service.rb' - 'app/services/jira/requests/base.rb' - 'config/initializers/1_settings.rb' - - 'config/initializers/carrierwave_patch.rb' + - 'config/initializers/carrierwave_s3_encryption_headers_patch.rb' - 'config/initializers/kaminari_active_record_relation_methods_with_limit.rb' - 'danger/roulette/Dangerfile' - 'ee/app/models/ee/integrations/jira.rb' diff --git a/.rubocop_todo/rspec/context_wording.yml b/.rubocop_todo/rspec/context_wording.yml index 3355be60b49..515ac988cc2 100644 --- a/.rubocop_todo/rspec/context_wording.yml +++ b/.rubocop_todo/rspec/context_wording.yml @@ -1508,7 +1508,7 @@ RSpec/ContextWording: - 'spec/helpers/wiki_helper_spec.rb' - 'spec/initializers/00_rails_disable_joins_spec.rb' - 'spec/initializers/1_acts_as_taggable_spec.rb' - - 'spec/initializers/carrierwave_patch_spec.rb' + - 'spec/initializers/carrierwave_s3_encryption_headers_patch_spec.rb' - 'spec/initializers/enumerator_next_patch_spec.rb' - 'spec/initializers/mail_encoding_patch_spec.rb' - 'spec/initializers/rack_multipart_patch_spec.rb' diff --git a/.rubocop_todo/rspec/missing_feature_category.yml b/.rubocop_todo/rspec/missing_feature_category.yml index 7a60575ebf2..992295c1bcb 100644 --- a/.rubocop_todo/rspec/missing_feature_category.yml +++ b/.rubocop_todo/rspec/missing_feature_category.yml @@ -2645,7 +2645,7 @@ RSpec/MissingFeatureCategory: - 'spec/initializers/action_mailer_hooks_spec.rb' - 'spec/initializers/active_record_locking_spec.rb' - 'spec/initializers/asset_proxy_setting_spec.rb' - - 'spec/initializers/carrierwave_patch_spec.rb' + - 'spec/initializers/carrierwave_s3_encryption_headers_patch_spec.rb' - 'spec/initializers/cookies_serializer_spec.rb' - 'spec/initializers/database_config_spec.rb' - 'spec/initializers/direct_upload_support_spec.rb' diff --git a/.rubocop_todo/style/guard_clause.yml b/.rubocop_todo/style/guard_clause.yml index 18075377acb..10d4a22876a 100644 --- a/.rubocop_todo/style/guard_clause.yml +++ b/.rubocop_todo/style/guard_clause.yml @@ -255,7 +255,7 @@ Style/GuardClause: - 'app/workers/repository_update_remote_mirror_worker.rb' - 'app/workers/terraform/states/destroy_worker.rb' - 'config/initializers/0_inject_enterprise_edition_module.rb' - - 'config/initializers/carrierwave_patch.rb' + - 'config/initializers/carrierwave_s3_encryption_headers_patch.rb' - 'config/initializers/devise_dynamic_password_length_validation.rb' - 'config/initializers/postgresql_cte.rb' - 'config/object_store_settings.rb' diff --git a/config/feature_flags/development/openai_moderation.yml b/config/feature_flags/development/openai_moderation.yml deleted file mode 100644 index 97915ceac41..00000000000 --- a/config/feature_flags/development/openai_moderation.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: openai_moderation -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119050 -rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/409452 -milestone: '16.0' -type: development -group: group::ai-enablement -default_enabled: false diff --git a/config/initializers/carrierwave_performance_patch.rb b/config/initializers/carrierwave_performance_patch.rb new file mode 100644 index 00000000000..a7b56cdb5ba --- /dev/null +++ b/config/initializers/carrierwave_performance_patch.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require "carrierwave/uploader/url" + +if Gem::Version.create(CarrierWave::VERSION) >= Gem::Version.create('2.0') + raise ScriptError, + "CarrierWave was upgraded to #{CarrierWave::VERSION} and this patch is not required anymore" +end + +# rubocop: disable Style/GuardClause +module CarrierWave + module Uploader + module Url + ## + # === Parameters + # + # [Hash] optional, the query params (only AWS) + # + # === Returns + # + # [String] the location where this file is accessible via a url + # + def url(options = {}) + if file.respond_to?(:url) + tmp_url = file.method(:url).arity == 0 ? file.url : file.url(options) + + return tmp_url if tmp_url.present? + end + + if file.respond_to?(:path) + path = encode_path(file.path.sub(File.expand_path(root), '')) + + if host = asset_host + if host.respond_to? :call + "#{host.call(file)}#{path}" + else + "#{host}#{path}" + end + else + (base_path || "") + path + end + end + end + end + end +end +# rubocop: enable Style/GuardClause diff --git a/config/initializers/carrierwave_patch.rb b/config/initializers/carrierwave_s3_encryption_headers_patch.rb similarity index 100% rename from config/initializers/carrierwave_patch.rb rename to config/initializers/carrierwave_s3_encryption_headers_patch.rb diff --git a/spec/initializers/carrierwave_performance_patch_spec.rb b/spec/initializers/carrierwave_performance_patch_spec.rb new file mode 100644 index 00000000000..58adfc15668 --- /dev/null +++ b/spec/initializers/carrierwave_performance_patch_spec.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe "CarrierWave::Uploader::Url", feature_category: :shared do + let(:uploader) { MyCoolUploader.new } + + subject(:url) { uploader.url } + + before do + stub_const("MyCoolUploader", Class.new(CarrierWave::Uploader::Base)) + end + + describe "#url" do + let(:file) { Class.new.new } + + before do + allow(uploader).to receive(:file).and_return(file) + end + + context "when file responds to url" do + it "returns nil when the file.url is empty" do + file.define_singleton_method(:url) { nil } + + expect(url).to be_nil + end + + it "returns the given file url" do + file.define_singleton_method(:url) { "url" } + + expect(url).to eq("url") + end + + it "passes any given options to the file url method" do + file.define_singleton_method(:url) { |x = true| x } + expect(file).to receive(:url).once.and_call_original + + options = { options: true } + expect(uploader.url(options)).to eq(options) + end + end + + context "when file responds to path" do + before do + file.define_singleton_method(:path) { "file/path" } + end + + context "when the asset host is a string" do + it "prefix the path with the asset host" do + expect(uploader).to receive(:asset_host).and_return("host/") + + expect(url).to eq("host/file/path") + end + end + + context "when the asset host responds to call" do + it "prefix the path with the asset host" do + expect(uploader).to receive(:asset_host).and_return(proc { |f| "callable/#{f.class.class}/" }) + + expect(url).to eq("callable/Class/file/path") + end + end + + context "when asset_host is empty" do + context "when base_path is empty" do + it "returns the file path" do + expect(url).to eq("file/path") + end + end + + context "when base_path is not empty" do + it "returns the file path prefixed with the base_path" do + expect(uploader).to receive(:base_path).and_return("base/path/") + + expect(url).to eq("base/path/file/path") + end + end + end + end + + context "when file does not respond to either url nor path" do + it "returns nil" do + expect(url).to eq(nil) + end + end + end +end diff --git a/spec/initializers/carrierwave_patch_spec.rb b/spec/initializers/carrierwave_s3_encryption_headers_patch_spec.rb similarity index 97% rename from spec/initializers/carrierwave_patch_spec.rb rename to spec/initializers/carrierwave_s3_encryption_headers_patch_spec.rb index 0910342f10f..c8a41847d62 100644 --- a/spec/initializers/carrierwave_patch_spec.rb +++ b/spec/initializers/carrierwave_s3_encryption_headers_patch_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe 'CarrierWave::Storage::Fog::File' do +RSpec.describe 'CarrierWave::Storage::Fog::File', feature_category: :shared do let(:uploader_class) { Class.new(CarrierWave::Uploader::Base) } let(:uploader) { uploader_class.new } let(:storage) { CarrierWave::Storage::Fog.new(uploader) }