[chore] upload fix for storages on sub pathes (#11990)

- fixed CSP hook
- fixed upload link query
pull/11991/head
Eric Schubert 2 years ago committed by GitHub
parent 945d1cedb6
commit 7c26f5ef60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
  2. 8
      modules/storages/lib/open_project/storages/append_storages_hosts_to_csp_hook.rb

@ -68,7 +68,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
end
def build_upload_link(response)
destination = @base_uri.merge(File.join(URI_UPLOAD_BASE_PATH, response.token))
destination = URI.parse(File.join(@base_uri.to_s, URI_UPLOAD_BASE_PATH, response.token))
ServiceResult.success(result: Storages::UploadLink.new(destination))
end
@ -79,7 +79,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
response = ServiceResult.success(
result: RestClient::Request.execute(
method:,
url: @base_uri.merge(relative_path).to_s,
url: File.join(@base_uri.to_s, relative_path),
payload: payload.to_json,
headers: {
'Authorization' => "Bearer #{token.access_token}",

@ -48,6 +48,7 @@ class ::OpenProject::Storages::AppendStoragesHostsToCspHook < OpenProject::Hook:
.select(:storage_id)
hosts = ::Storages::Storage.where(id: projects_with_permission)
.pluck(:host)
.map(&method(:remove_uri_path))
return if hosts.empty?
@ -55,4 +56,11 @@ class ::OpenProject::Storages::AppendStoragesHostsToCspHook < OpenProject::Hook:
controller = context[:controller]
controller.append_content_security_policy_directives({ connect_src: hosts })
end
private
def remove_uri_path(url)
uri = URI.parse(url)
"#{uri.scheme}://#{uri.host}"
end
end

Loading…
Cancel
Save