Skip to content

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

[#45860] fixed files query for storages with sub path

Eric Schubertac87e7ee64a5
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
index ffdd5d4fd84..7e1048db9e8 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
@@ -42,7 +42,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
result = @retry_proc.call(@token) do |token|
response = http.propfind(
- "#{@base_path}#{requested_folder(parent)}",
+ request_path(parent),
requested_properties,
{
'Depth' => '1',
@@ -58,6 +58,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
private
+ def request_path(folder)
+ File.join(@uri.path, @base_path, requested_folder(folder)).gsub(/\/+$/, '')
+ end
+
def requested_folder(folder)
return '' if folder.nil?
diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
index df3cdce6265..d7117e58848 100644
--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
@@ -185,10 +185,11 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
describe '#files_query' do
let(:xml) { create(:webdav_data) }
+ let(:request_url) { "#{url}/remote.php/dav/files/#{origin_user_id}" }
before do
allow(OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)
- stub_request(:propfind, "#{url}/remote.php/dav/files/#{origin_user_id}")
+ stub_request(:propfind, request_url)
.to_return(status: 207, body: xml, headers: {})
end
@@ -261,6 +262,21 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
assert_requested(:propfind, request_url)
end
end
+
+ describe 'with storage running on a sub path' do
+ let(:url) { 'https://example.com/storage' }
+
+ it do
+ subject
+ .files_query(user:)
+ .match(
+ on_success: ->(query) { query.call(nil) },
+ on_failure: ->(error) { raise "Files query could not be created: #{error}" }
+ )
+
+ assert_requested(:propfind, request_url)
+ end
+ end
end
describe 'with not supported storage type selected' do
diff --git a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
index 48f6ba06916..f94d064030f 100644
--- a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
+++ b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
@@ -64,9 +64,9 @@ describe 'API v3 storage files', content_type: :json, webmock: true do
let(:files) do
[
- Storages::StorageFile.new(1, 'new_younglings.md', 4096, 'plain/text', DateTime.now, DateTime.now,
+ Storages::StorageFile.new(1, 'new_younglings.md', 4096, 'text/markdown', DateTime.now, DateTime.now,
'Obi-Wan Kenobi', 'Obi-Wan Kenobi', '/'),
- Storages::StorageFile.new(2, 'holocron_inventory.md', 4096, 'plain/text', DateTime.now, DateTime.now,
+ Storages::StorageFile.new(2, 'holocron_inventory.md', 4096, 'text/markdown', DateTime.now, DateTime.now,
'Obi-Wan Kenobi', 'Obi-Wan Kenobi', '/')
]
end