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
[#42160] extracted method clocks to service results
Eric Schubertb6fc38058980
diff --git a/modules/storages/lib/api/v3/file_links/storage_url_helper.rb b/modules/storages/lib/api/v3/file_links/storage_url_helper.rbindex 2308a3bf9a8..df1b667b555 100644--- a/modules/storages/lib/api/v3/file_links/storage_url_helper.rb+++ b/modules/storages/lib/api/v3/file_links/storage_url_helper.rb@@ -39,25 +39,18 @@ module API::V3::FileLinks::StorageUrlHelperstorage = file_link.storageoauth_client = storage.oauth_client- client_token = ::OAuthClients::ConnectionManager- .new(user:, oauth_client:)- .get_access_token+ client_token = get_oauth_client_token(user:, oauth_client:)+ return client_token if client_token.failure?- return ServiceResult.failure(result: I18n.t('http.request.missing_authorization')) if client_token.failure?+ direct_download_response = make_direct_download oauth_client:,+ access_token: client_token.result.access_token,+ file_id: file_link.origin_id+ return direct_download_response if direct_download_response.failure?- response = make_direct_download oauth_client:,- access_token: client_token.result.access_token,- file_id: file_link.origin_id+ download_token = direct_download_token(body: direct_download_response.result)+ return download_token if download_token.failure?- return response if response.failure?-- token = parse_direct_download_token body: response.result- if token.blank?- Rails.logger.error "Received unexpected json response: #{response.result}"- return ServiceResult.failure(result: I18n.t('http.response.unexpected'))- end-- url = "#{storage.host}/apps/integration_openproject/direct/#{token}/#{file_link.origin_name}"+ url = "#{storage.host}/apps/integration_openproject/direct/#{download_token.result}/#{file_link.origin_name}"ServiceResult.success(result: url)end@@ -65,6 +58,14 @@ module API::V3::FileLinks::StorageUrlHelperprivate+ def get_oauth_client_token(user:, oauth_client:)+ client_token = ::OAuthClients::ConnectionManager+ .new(user:, oauth_client:)+ .get_access_token++ client_token.success? ? client_token : ServiceResult.failure(result: I18n.t('http.request.missing_authorization'))+ end+def make_direct_download(oauth_client:, access_token:, file_id:)response = API::V3::Storages::StorageRequestFactory.new(oauth_client:)@@ -79,6 +80,16 @@ module API::V3::FileLinks::StorageUrlHelperServiceResult.success(result: response.result.body)end+ def direct_download_token(body:)+ token = parse_direct_download_token(body:)+ if token.blank?+ Rails.logger.error "Received unexpected json response: #{direct_download_response.result}"+ return ServiceResult.failure(result: I18n.t('http.response.unexpected'))+ end++ ServiceResult.success(result: token)+ end+def parse_direct_download_token(body:)beginjson = JSON.parse body