OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[chore] change of logic for nextcloud storage hosts
Eric Schubert0541c04d0270
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 07e02e575ab..d98d8ee83f3 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -160,7 +160,11 @@ module Storagesdef urireturn unless host- @uri ||= URI(host).normalize+ @uri ||= if host.end_with?("/")+ URI(host).normalize+ else+ URI("#{host}/").normalize+ endenddef connect_srcdiff --git a/modules/storages/app/services/storages/storages/set_attributes_service.rb b/modules/storages/app/services/storages/storages/set_attributes_service.rbindex f35f6d5ab58..93ce25e4116 100644--- a/modules/storages/app/services/storages/storages/set_attributes_service.rb+++ b/modules/storages/app/services/storages/storages/set_attributes_service.rb@@ -29,7 +29,7 @@# See also: create_service.rb for commentsmodule Storages::Storagesclass SetAttributesService < ::BaseServices::SetAttributes- after_call :remove_host_trailing_slashes+ after_call :sanitize_hostdef set_default_attributes(_params)storage.creator ||= user@@ -38,22 +38,19 @@ module Storages::Storagesprivatedef set_attributes(params)- super(replace_empty_host_with_nil(params))+ superunset_nextcloud_application_credentials if nextcloud_storage?end- def remove_host_trailing_slashes- storage.host = storage.host&.gsub(/\/+$/, "")- end-- def replace_empty_host_with_nil(params)- cloned_param = params.clone-- if cloned_param[:host] == ""- cloned_param[:host] = nil- end-- cloned_param+ def sanitize_host+ host_input = storage.host+ storage.host = if host_input.present? && !host_input.ends_with?("/")+ "#{host_input}/"+ elsif host_input == ""+ nil+ else+ host_input+ endenddef unset_nextcloud_application_credentialsdiff --git a/modules/storages/spec/models/storages/storage_spec.rb b/modules/storages/spec/models/storages/storage_spec.rbindex 6bd2bb9529a..4571d70480c 100644--- a/modules/storages/spec/models/storages/storage_spec.rb+++ b/modules/storages/spec/models/storages/storage_spec.rb@@ -115,4 +115,27 @@ RSpec.describe Storages::Storage doendendend++ describe "uri" do+ it "returns nil if host is nil" do+ storage = build(:storage, host: nil)+ expect(storage.uri).to be_nil+ end++ it "returns host with trailing slash" do+ storage = build(:storage, host: "https://example.com")+ expect(storage.uri.to_s).to eq("https://example.com/")+ storage = build(:storage, host: "https://endor")+ expect(storage.uri.to_s).to eq("https://endor/")+ storage = build(:storage, host: "https://deathstar.org/html")+ expect(storage.uri.to_s).to eq("https://deathstar.org/html/")++ storage = build(:storage, host: "https://example.com/")+ expect(storage.uri.to_s).to eq("https://example.com/")+ storage = build(:storage, host: "https://endor/")+ expect(storage.uri.to_s).to eq("https://endor/")+ storage = build(:storage, host: "https://deathstar.org/html/")+ expect(storage.uri.to_s).to eq("https://deathstar.org/html/")+ end+ endenddiff --git a/modules/storages/spec/services/storages/storages/set_attributes_service_spec.rb b/modules/storages/spec/services/storages/storages/set_attributes_service_spec.rbindex e5fe1297283..fcd84d1bdcc 100644--- a/modules/storages/spec/services/storages/storages/set_attributes_service_spec.rb+++ b/modules/storages/spec/services/storages/storages/set_attributes_service_spec.rb@@ -88,13 +88,33 @@ RSpec.describe Storages::Storages::SetAttributesService, type: :model doexpect(subject.result.provider_type).to eq Storages::Storage::PROVIDER_TYPE_NEXTCLOUDend- context "when setting host" do+ context "with host" dobefore do- params[:host] = "https://some.host.com//"+ params[:host] = host_inputend- it "removes trailing slashes from host" do- expect(subject.result.host).to eq("https://some.host.com")+ context "if host input has a trailing slashes" do+ let(:host_input) { "https://some.host.com//" }++ it "keeps a trailing slash" do+ expect(subject.result.host).to eq(host_input)+ end+ end++ context "if host input is empty string" do+ let(:host_input) { "" }++ it "sets host to nil" do+ expect(subject.result.host).to be_nil+ end+ end++ context "if host input has no trailing slash" do+ let(:host_input) { "https://some.host.com" }++ it "adds a trailing slash" do+ expect(subject.result.host).to eq("https://some.host.com/")+ endendendend