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

Still broken uploads, and maybe a lot more! fun times!

Marcello Rocha79fdf7f3d9c1
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb
index 8d6439d7f39..582a2a5bda1 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb
@@ -66,7 +66,7 @@ module Storages
case response
when Net::HTTPSuccess
upload_url = MultiJson.load(response.body, symbolize_keys: true)[:uploadUrl]
- ServiceResult.success(result: ::Storages::UploadLink.new(URI(upload_url)))
+ ServiceResult.success(result: ::Storages::UploadLink.new(URI(upload_url), :put))
when Net::HTTPNotFound
ServiceResult.failure(result: :not_found, errors: ::Storages::StorageError.new(code: :not_found))
when Net::HTTPUnauthorized
@@ -77,7 +77,7 @@ module Storages
end
def uri_path_for(folder, filename)
- "/v1.0/drives/#{@storage.drive_id}/items/#{folder}:/#{filename}:/createUploadSession"
+ "/v1.0/drives/#{@storage.drive_id}/items/#{folder}:/#{URI.encode_uri_component(filename)}:/createUploadSession"
end
end
end
diff --git a/modules/storages/app/models/storages/one_drive_storage.rb b/modules/storages/app/models/storages/one_drive_storage.rb
index 3fa5f7e8fe3..f12e07996a5 100644
--- a/modules/storages/app/models/storages/one_drive_storage.rb
+++ b/modules/storages/app/models/storages/one_drive_storage.rb
@@ -47,6 +47,10 @@ module Storages
URI('https://graph.microsoft.com').normalize
end
+ def connect_src
+ %w[https://*.sharepoint.com https://*.up.1drv.com]
+ end
+
def open_link
::Storages::Peripherals::Registry.resolve("queries.one_drive.open_drive_link")
.call(storage: self, user: User.current)
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index 1bcb79a1035..f8572ec8f8a 100644
--- a/modules/storages/app/models/storages/storage.rb
+++ b/modules/storages/app/models/storages/storage.rb
@@ -107,7 +107,11 @@ module Storages
end
def uri
- URI(host).normalize
+ @uri ||= URI(host).normalize
+ end
+
+ def connect_src
+ ["#{uri.scheme}://#{uri.host}"]
end
def open_link
diff --git a/modules/storages/lib/api/v3/file_links/create_endpoint.rb b/modules/storages/lib/api/v3/file_links/create_endpoint.rb
index dbd8dd82b44..3692242c595 100644
--- a/modules/storages/lib/api/v3/file_links/create_endpoint.rb
+++ b/modules/storages/lib/api/v3/file_links/create_endpoint.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
@@ -59,6 +61,7 @@ class API::V3::FileLinks::CreateEndpoint < API::Utilities::Endpoints::Create
# rollback records created if an error occurred (validation failed)
raise ActiveRecord::Rollback if global_result.failure?
end
+
global_result
end
diff --git a/modules/storages/lib/open_project/storages/append_storages_hosts_to_csp_hook.rb b/modules/storages/lib/open_project/storages/append_storages_hosts_to_csp_hook.rb
index 1eaa3548009..af47ef2a748 100644
--- a/modules/storages/lib/open_project/storages/append_storages_hosts_to_csp_hook.rb
+++ b/modules/storages/lib/open_project/storages/append_storages_hosts_to_csp_hook.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2022 the OpenProject GmbH
@@ -44,24 +46,15 @@ class ::OpenProject::Storages::AppendStoragesHostsToCspHook < OpenProject::Hook:
# (work packages module, BCF module, notification center, boards, ...).
def application_controller_before_action(context)
storage_ids = ::Storages::ProjectStorage.where(
- project_id: Project.allowed_to(User.current, :manage_file_links),
+ project_id: Project.allowed_to(User.current, :manage_file_links)
).select(:storage_id)
storages_hosts = ::Storages::Storage
.where(id: storage_ids)
- .where.not(host: nil)
- .pluck(:host)
- .map(&method(:remove_uri_path))
+ .flat_map(&:connect_src)
if storages_hosts.present?
# secure_headers gem provides this helper method to append to the current content security policy
context[:controller].append_content_security_policy_directives(connect_src: storages_hosts)
end
end
-
- private
-
- def remove_uri_path(url)
- uri = URI.parse(url)
- "#{uri.scheme}://#{uri.host}"
- end
end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/upload_link_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/upload_link_query_spec.rb
index 74f7a858a5d..ed86a17bc59 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/upload_link_query_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/upload_link_query_spec.rb
@@ -66,7 +66,7 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::UploadLinkQu
link = upload_query.call(user:, data: query_payload).result
expect(link.destination).not_to be_nil
- expect(link.method).to eq(:post)
+ expect(link.method).to eq(:put)
end
shared_examples_for 'outbound is failing' do |code, symbol|
diff --git a/modules/storages/spec/contracts/storages/file_links/shared_contract_examples.rb b/modules/storages/spec/contracts/storages/file_links/shared_contract_examples.rb
index e55c91f7db2..a66f90c55ce 100644
--- a/modules/storages/spec/contracts/storages/file_links/shared_contract_examples.rb
+++ b/modules/storages/spec/contracts/storages/file_links/shared_contract_examples.rb
@@ -67,13 +67,13 @@ RSpec.shared_examples_for 'file_link contract' do
context 'when empty' do
let(:file_link_attributes) { { origin_id: '' } }
- include_examples 'contract is invalid', origin_id: :blank
+ include_examples 'contract is invalid', origin_id: %i[blank too_short]
end
context 'when nil' do
let(:file_link_attributes) { { origin_id: nil } }
- include_examples 'contract is invalid', origin_id: :blank
+ include_examples 'contract is invalid', origin_id: %i[blank too_short]
end
context 'when numeric' do
@@ -91,11 +91,11 @@ RSpec.shared_examples_for 'file_link contract' do
context 'when having non ascii characters' do
let(:file_link_attributes) { { origin_id: 'Hëllò Wôrłd!' } }
- include_examples 'contract is invalid', origin_id: :invalid
+ include_examples 'contract is valid'
end
context 'when longer than 100 characters' do
- let(:file_link_attributes) { { origin_id: '1' * 101 } }
+ let(:file_link_attributes) { { origin_id: '1' * 201 } }
include_examples 'contract is invalid', origin_id: :too_long
end
diff --git a/modules/storages/spec/factories/file_link_element_factory.rb b/modules/storages/spec/factories/file_link_element_factory.rb
index 2b083f1f15a..c4d4d5898d1 100644
--- a/modules/storages/spec/factories/file_link_element_factory.rb
+++ b/modules/storages/spec/factories/file_link_element_factory.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
@@ -39,7 +41,7 @@ FactoryBot.define do
storage_url { "https://nextcloud.example.com" }
trait :invalid do
- origin_id { "I'm invalid" }
+ origin_id { ' ' }
end
initialize_with do