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
[#44916] File picker does not load directory listing when OAuth token is expired
Andreas Pfohl806d84a11f50
diff --git a/app/services/oauth_clients/connection_manager.rb b/app/services/oauth_clients/connection_manager.rbindex 76085ccc1f3..bb21b6b9493 100644--- a/app/services/oauth_clients/connection_manager.rb+++ b/app/services/oauth_clients/connection_manager.rb@@ -151,7 +151,7 @@ module OAuthClients# `yield` needs to returns a ServiceResult:# success: result= any object with data# failure: result= :error or :not_authorized- yield_service_result = yield+ yield_service_result = yield(oauth_client_token)if yield_service_result.failure? && yield_service_result.result == :not_authorizedrefresh_service_result = refresh_token@@ -162,19 +162,12 @@ module OAuthClientsendoauth_client_token.reload- yield_service_result = yield # Should contain result=<data> in case of success+ yield_service_result = yield(oauth_client_token) # Should contain result=<data> in case of successendyield_service_resultend- def with_refreshed_token(&)- token = get_existing_token- return ServiceResult.failure(result: :not_authorized) if token.blank?-- request_with_token_refresh(token, &)- end-private# Check if a OAuthClientToken already exists and return nil otherwise.diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud_storage_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud_storage_query.rbindex 0fc43640593..000619d04e2 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud_storage_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud_storage_query.rb@@ -28,25 +28,24 @@module Storages::Peripherals::StorageInteractionclass NextcloudStorageQuery- def initialize(base_uri:, origin_user_id:, token:, with_refreshed_token:)+ def initialize(base_uri:, 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/#{token.origin_user_id}"enddef files(parent)http = Net::HTTP.new(@uri.host, @uri.port)http.use_ssl = @uri.scheme == 'https'- result = @with_refreshed_token.call do+ result = @with_refreshed_token.call(@token) do |token|response = http.propfind("#{@base_path}#{parent}",requested_properties,{'Depth' => '1',- 'Authorization' => "Bearer #{@token}"+ 'Authorization' => "Bearer #{token.access_token}"})diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/storage_queries.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/storage_queries.rbindex dbaba2bba44..11d91662730 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/storage_queries.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/storage_queries.rb@@ -47,9 +47,8 @@ module Storages::Peripherals::StorageInteractionresult:::Storages::Peripherals::StorageInteraction::NextcloudStorageQuery.new(base_uri: @uri,- origin_user_id: token.origin_user_id,- token: token.access_token,- with_refreshed_token: connection_manager.method(:with_refreshed_token).to_proc+ token:,+ with_refreshed_token: connection_manager.method(:request_with_token_refresh).to_proc))end,diff --git a/modules/storages/app/services/storages/file_link_sync_service.rb b/modules/storages/app/services/storages/file_link_sync_service.rbindex c37c416f76d..65b1aba2886 100644--- a/modules/storages/app/services/storages/file_link_sync_service.rb+++ b/modules/storages/app/services/storages/file_link_sync_service.rb@@ -78,8 +78,8 @@ class Storages::FileLinkSyncServicereturnend- nextcloud_request_result = connection_manager.request_with_token_refresh(oauth_client_token) do- response = request_files_info(oauth_client_token, file_links.map(&:origin_id))+ nextcloud_request_result = connection_manager.request_with_token_refresh(oauth_client_token) do |token|+ response = request_files_info(token, file_links.map(&:origin_id))Rails.logger.debug { "Got nextcloud filesinfo response: #{response.inspect}" }# Parse HTTP response an return a ServiceResult with:# success: result= Hash with Nextcloud filesinfo (name of endpoint) datadiff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rbindex 7bd66eca721..9082448366c 100644--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb@@ -101,20 +101,20 @@ describe Storages::Peripherals::StorageRequests, webmock: true dostorageend- let(:connection_manager) do- connection_manager = instance_double(::OAuthClients::ConnectionManager)- allow(connection_manager).to receive(:get_access_token).and_return(ServiceResult.success(result: access_token))- allow(connection_manager).to receive(:with_refreshed_token).and_yield- connection_manager- end-- let(:access_token) do+ let(:token) dotoken = instance_double(OAuthClientToken)allow(token).to receive(:origin_user_id).and_return(origin_user_id)allow(token).to receive(:access_token).and_return('xyz')tokenend+ let(:connection_manager) do+ connection_manager = instance_double(::OAuthClients::ConnectionManager)+ allow(connection_manager).to receive(:get_access_token).and_return(ServiceResult.success(result: token))+ allow(connection_manager).to receive(:request_with_token_refresh).and_yield(token)+ connection_manager+ end+subject { described_class.new(storage:) }before dodiff --git a/modules/storages/spec/features/create_file_links_spec.rb b/modules/storages/spec/features/create_file_links_spec.rbindex 2a637eada9f..382ef9d23ca 100644--- a/modules/storages/spec/features/create_file_links_spec.rb+++ b/modules/storages/spec/features/create_file_links_spec.rb@@ -45,7 +45,7 @@ describe 'Creating file links in work package', js: true, webmock: true, with_flallow(connection_manager).to receive(:refresh_token).and_return(ServiceResult.success(result: oauth_client_token))allow(connection_manager).to receive(:get_access_token).and_return(ServiceResult.success(result: oauth_client_token))allow(connection_manager).to receive(:authorization_state).and_return(:connected)- allow(connection_manager).to receive(:with_refreshed_token).and_yield+ allow(connection_manager).to receive(:request_with_token_refresh).and_yield(oauth_client_token)connection_managerend