Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2023-05-26 15:08:09 +00:00
parent d94409aaaf
commit a8c410f8a1
11 changed files with 141 additions and 15 deletions

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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) }