simplified parent handling in storage files API

pull/11484/head
Andreas Pfohl 2 years ago
parent 7ecf5cf414
commit f58a3f5615
No known key found for this signature in database
GPG Key ID: FF58F3B771328EB4
  1. 9
      modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud_storage_query.rb
  2. 6
      modules/storages/lib/api/v3/storage_files/storage_files_api.rb
  3. 18
      modules/storages/spec/common/peripherals/storage_requests_spec.rb

@ -28,14 +28,12 @@
module Storages::Peripherals::StorageInteraction
class NextcloudStorageQuery
using Storages::Peripherals::ServiceResultRefinements
def initialize(base_uri:, origin_user_id:, token:, with_refreshed_token:)
@uri = base_uri
@origin_user_id = origin_user_id
@token = token
@with_refreshed_token = with_refreshed_token
@base_path = "/remote.php/dav/files/#{@origin_user_id}/"
@base_path = "/remote.php/dav/files/#{@origin_user_id}"
end
def files(parent)
@ -44,10 +42,7 @@ module Storages::Peripherals::StorageInteraction
result = @with_refreshed_token.call do
response = http.propfind(
parent.match(
on_success: ->(p) { "#{@base_path}#{p}" },
on_failure: ->(_) { @base_path }
),
"#{@base_path}#{parent}",
requested_properties,
{
'Depth' => '1',

@ -41,10 +41,6 @@ module API::V3::StorageFiles
raise API::Errors::InternalError.new
end
end
def find_param(symbol)
params[symbol] ? ServiceResult.success(result: params[symbol]) : ServiceResult.failure
end
end
resources :files do
@ -55,7 +51,7 @@ module API::V3::StorageFiles
.match(
on_success: ->(files_query) {
files_query
.call(find_param(:parent))
.call(params[:parent])
.map do |files|
API::V3::StorageFiles::StorageFileCollectionRepresenter.new(
files,

@ -119,7 +119,7 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
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, "#{url}/remote.php/dav/files/#{origin_user_id}")
.to_return(status: 207, body: xml, headers: {})
end
@ -130,7 +130,7 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
.files_query(user:)
.match(
on_success: ->(query) do
result = query.call(ServiceResult.failure)
result = query.call(nil)
expect(result).to be_success
expect(result.result.size).to eq(2)
end,
@ -145,7 +145,7 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
.files_query(user:)
.match(
on_success: ->(query) do
result = query.call(ServiceResult.failure)
result = query.call(nil)
expect(result).to be_success
expect(result.result[1].name).to eq('Documents')
expect(result.result[1].mime_type).to eq('application/x-op-directory')
@ -162,7 +162,7 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
.files_query(user:)
.match(
on_success: ->(query) do
result = query.call(ServiceResult.failure)
result = query.call(nil)
expect(result).to be_success
expect(result.result[0].name).to eq('Nextcloud Manual.pdf')
expect(result.result[0].mime_type).to eq('application/pdf')
@ -175,8 +175,8 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
end
describe 'with parent query parameter' do
let(:parent) { 'Photos/Birds' }
let(:request_url) { "#{url}/remote.php/dav/files/#{origin_user_id}/#{parent}" }
let(:parent) { '/Photos/Birds' }
let(:request_url) { "#{url}/remote.php/dav/files/#{origin_user_id}#{parent}" }
before do
stub_request(:propfind, request_url).to_return(status: 207, body: xml, headers: {})
@ -186,7 +186,7 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
subject
.files_query(user:)
.match(
on_success: ->(query) { query.call(ServiceResult.success(result: parent)) },
on_success: ->(query) { query.call(parent) },
on_failure: ->(error) { raise "Files query could not be created: #{error}" }
)
@ -218,7 +218,7 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
shared_examples_for 'outbound is failing' do |code = 500, symbol = :error|
describe "with outbound request returning #{code}" do
before do
stub_request(:propfind, "#{url}/remote.php/dav/files/#{origin_user_id}/").to_return(status: code)
stub_request(:propfind, "#{url}/remote.php/dav/files/#{origin_user_id}").to_return(status: code)
end
it "must return :#{symbol} ServiceResult" do
@ -226,7 +226,7 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
.files_query(user:)
.match(
on_success: ->(query) do
result = query.call(ServiceResult.failure)
result = query.call(nil)
expect(result).to be_failure
expect(result.result).to be(symbol)
end,

Loading…
Cancel
Save