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
Initial mess
Marcello Rochab19b6faa3cc4
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rbindex f8633ec533f..52be08eb8ae 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb@@ -56,7 +56,11 @@ module Storageshandle_response(response)end- result.map { |json_files| storage_files(json_files) }+ if result.result.empty?+ empty_response(folder)+ else+ result.map { |json_files| storage_files(json_files) }+ endendprivate@@ -74,17 +78,10 @@ module Storagesendend- def uri_path_for(folder)- return "/v1.0/drives/#{@storage.drive_id}/root/children" unless folder-- "/v1.0/drives/#{@storage.drive_id}/items/#{folder}/children"- end-def storage_files(json_files)files = json_files.map { |json| storage_file(json) }parent_reference = json_files.first[:parentReference]-StorageFiles.new(files, parent(parent_reference), forge_ancestors(parent_reference))end@@ -99,7 +96,22 @@ module Storagescreated_by_name: json_file.dig(:createdBy, :user, :displayName),last_modified_by_name: json_file.dig(:lastModifiedBy, :user, :displayName),location: extract_location(json_file[:parentReference], json_file[:name]),- permissions: nil+ permissions: %i[readable writeable]+ )+ end++ def empty_response(folder)+ ServiceResult.success(+ result: StorageFiles.new(+ [],+ StorageFile.new(+ id: Digest::SHA256.hexdigest(folder),+ name: folder.split('/').last,+ location: folder,+ permissions: %i[readable writeable]+ ),+ forge_ancestors(path: folder)+ ))end@@ -118,7 +130,8 @@ module StoragesStorageFile.new(id: parent_reference[:id],name:,- location: extract_location(parent_reference)+ location: extract_location(parent_reference),+ permissions: %i[readable writeable])endend@@ -138,7 +151,20 @@ module Storagesenddef root(id)- StorageFile.new(name: "Root", location: "/", id:)+ StorageFile.new(name: "Root",+ location: "/",+ id:,+ permissions: %i[readable writeable])+ end++ def uri_path_for(folder)+ return "/v1.0/drives/#{@storage.drive_id}/root/children" unless folder++ "/v1.0/drives/#{@storage.drive_id}/root:#{encode_path(folder)}:/children"+ end++ def encode_path(path)+ path.split('/').map { |fragment| URI.encode_uri_component(fragment) }.join('/')endendenddiff --git a/modules/storages/app/contracts/storages/file_links/create_contract.rb b/modules/storages/app/contracts/storages/file_links/create_contract.rbindex d59936d4467..a22a5fab546 100644--- a/modules/storages/app/contracts/storages/file_links/create_contract.rb+++ b/modules/storages/app/contracts/storages/file_links/create_contract.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) 2012-2023 the OpenProject GmbH@@ -34,8 +36,7 @@ class Storages::FileLinks::CreateContract < ModelContractattribute :container_typeattribute :origin_id- validates :origin_id, length: { maximum: 100 },- format: { with: /\A[-0-9a-f]*\z/i, message: :only_numeric_or_uuid }+ validates :origin_id, length: 1..100attribute :origin_namevalidates :origin_name, presence: trueattribute :origin_created_by_namediff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rbindex 0110174328f..030b09bb2b0 100644--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb@@ -72,7 +72,7 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesQuery,created_by_name: "Megan Bowen",last_modified_by_name: "Megan Bowen",location: "/All Japan Revenues By City.xlsx",- permissions: nil })+ permissions: %i[readable writeable] })endit 'when the argument folder is nil, gets information from that users root folder' do@@ -90,16 +90,42 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesQuery,expect(storage_files.ancestors).to be_emptyend+ context 'when accessing an empty folder' do+ let(:json) { read_json('empty_folder') }++ before do+ stub_request(+ :get,+ "https://graph.microsoft.com/v1.0/drives/#{storage.drive_id}/root:/TestBatchingFolder:/children#{described_class::FIELDS}"+ )+ .with(headers: { 'Authorization' => "Bearer #{token.access_token}" })+ .to_return(status: 200, body: json, headers: {})+ end++ it 'returns an empty storage files' do+ storage_files = described_class.call(storage:, user:, folder: '/TestBatchingFolder').result++ expect(storage_files.files).to be_empty+ end++ it 'fakes a parent' do+ storage_files = described_class.call(storage:, user:, folder: '/TestBatchingFolder').result++ expect(storage_files.ancestors.size).to eq(1)+ expect(storage_files.ancestors[0].location).to eq '/'+ end+ end+context 'when accessing a specific folder' dolet(:json) { read_json('specific_folder') }it 'uses the specific drive url' do- uri = "https://graph.microsoft.com/v1.0/drives/#{storage.drive_id}/items/01BYE5RZYJ43UXGBP23BBIFPISHHMCDTOY/children#{described_class::FIELDS}"+ uri = "https://graph.microsoft.com/v1.0/drives/#{storage.drive_id}/root:/Class%20Documents:/children#{described_class::FIELDS}"stub_request(:get, uri).with(headers: { 'Authorization' => "Bearer #{token.access_token}" }).to_return(status: 200, body: json, headers: {})- storage_files = described_class.call(storage:, user:, folder: '01BYE5RZYJ43UXGBP23BBIFPISHHMCDTOY').result+ storage_files = described_class.call(storage:, user:, folder: '/Class Documents').resultexpect(storage_files.files.size).to eq(22)expect(storage_files.parent.name).to eq('Class Documents')@@ -117,11 +143,13 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesQuery,endit 'has one ancestors and one parent' do- stub_request(:get, "https://graph.microsoft.com/v1.0/drives/#{storage.drive_id}/items/01BYE5RZ2LCUJQWLOZYNDLDC4DRRGJ7OEN/children#{described_class::FIELDS}")- .with(headers: { 'Authorization' => "Bearer #{token.access_token}" })+ stub_request(+ :get,+ "https://graph.microsoft.com/v1.0/drives/#{storage.drive_id}/root:/Contoso%20Clothing/Clothing%20Articles:/children#{described_class::FIELDS}"+ ).with(headers: { 'Authorization' => "Bearer #{token.access_token}" }).to_return(status: 200, body: payload, headers: {})- storage_files = described_class.call(storage:, user:, folder: "01BYE5RZ2LCUJQWLOZYNDLDC4DRRGJ7OEN").result+ storage_files = described_class.call(storage:, user:, folder: "/Contoso Clothing/Clothing Articles").resultexpect(storage_files.ancestors.size).to eq(2)expect(storage_files.ancestors.map(&:location)).to contain_exactly("/", "/Contoso Clothing")diff --git a/modules/storages/spec/support/payloads/empty_folder.json b/modules/storages/spec/support/payloads/empty_folder.jsonnew file mode 100644index 00000000000..15b961159cc--- /dev/null+++ b/modules/storages/spec/support/payloads/empty_folder.json@@ -0,0 +1,4 @@+{+ "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives('b%21-RIj2DuyvEyV1T4NlOaMHk8XkS_I8MdFlUCq1BlcjgmhRfAj3-Z8RY2VpuvV_tpd')/root/children",+ "value": []+}