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
[chore] added debug logs for the file sync service
Eric Schubertddbe0d15590f
diff --git a/modules/storages/app/services/storages/file_link_sync_service.rb b/modules/storages/app/services/storages/file_link_sync_service.rbindex e4728fdfe4b..16d55e942fa 100644--- a/modules/storages/app/services/storages/file_link_sync_service.rb+++ b/modules/storages/app/services/storages/file_link_sync_service.rb@@ -28,6 +28,8 @@# Handle synchronization of FileLinks with external data store such as Storagesclass Storages::FileLinkSyncService+ include OpenProjectErrorHelper+FILESINFO_URL_PATH = "/ocs/v1.php/apps/integration_openproject/filesinfo".freeze# @param user Current user@@ -42,6 +44,7 @@ class Storages::FileLinkSyncService# the storage endpoint.# @return ServiceResult with FileLinks in the resultdef call(file_links)+ op_handle_debug "Started synchronization for #{file_links.count} file link(s)."@file_links = file_linksstorage_file_link_hash = @file_links.group_by(&:storage_id)storage_file_link_hash.each do |storage_id, storage_file_links|@@ -56,11 +59,14 @@ class Storages::FileLinkSyncService# Get the OAuthClientToken that will authenticate us against Nextclouddef get_connection_manager(storage_id)+ op_handle_debug "Make connection manager for storage #{storage_id}."oauth_client = OAuthClient.find_by(integration_id: storage_id)::OAuthClients::ConnectionManager.new(user: @user, oauth_client:)enddef get_oauth_client_token(connection_manager)+ op_handle_debug "Get oauth client token with connection manager of user #{@user.id}."+access_token_service_result = connection_manager.get_access_token # No scope for Nextcloud...if access_token_service_result.failure?return nil@@ -70,16 +76,20 @@ class Storages::FileLinkSyncServiceend# Sync a Nextcloud storage+ # rubocop:disable Metrics/AbcSizedef sync_nextcloud(storage_id, file_links)+ op_handle_debug "Sync storage { id: #{storage_id} } with #{file_links.count} file link(s)."connection_manager = get_connection_manager(storage_id)oauth_client_token = get_oauth_client_token(connection_manager)if oauth_client_token.nil?+ op_handle_debug 'No oauth client token found.'set_error_for_file_links(file_links)returnendstorage_origin_file_ids = file_links.map(&:origin_id)nextcloud_request_result = connection_manager.request_with_token_refresh do+ op_handle_debug "Requesting live data for files #{storage_origin_file_ids}."response = request_files_info(oauth_client_token, storage_origin_file_ids)# Parse HTTP response an return a ServiceResult with:# success: result= Hash with Nextcloud filesinfo (name of endpoint) data@@ -90,6 +100,7 @@ class Storages::FileLinkSyncService@service_result.merge!(nextcloud_request_result)if nextcloud_request_result.failure?+ op_handle_debug 'Request to storage failed. Setting error code to file links.'set_error_for_file_links(file_links)returnend@@ -97,7 +108,10 @@ class Storages::FileLinkSyncServiceset_file_link_permissions(file_links, nextcloud_request_result.result)end+ # rubocop:enable Metrics/AbcSize+def set_file_link_permissions(file_links, parsed_response)+ op_handle_debug "Setting file link permissions for #{file_links.count} file links."file_links.each do |file_link|origin_file_info_hash = parsed_response[file_link.origin_id]@@ -173,6 +187,7 @@ class Storages::FileLinkSyncServicerequest = build_files_info_request(uri, token, file_ids)begin+ op_handle_debug "Request file live data from #{uri}."Net::HTTP.start(uri.hostname, uri.port, request_file_info_options) do |http|http.request(request)end@@ -207,7 +222,9 @@ class Storages::FileLinkSyncService# parses the returned JSON and# @returns ServiceResult containing data in result and success=true,# or success=false with result=:error or result=:not_authorized.+ # rubocop:disable Metrics/AbcSizedef parse_files_info_response(response)+ op_handle_debug "Parse http response: status #{response.code}, body: #{response.body}."return ServiceResult.failure(result: :error) if files_info_response_error?(response)return ServiceResult.failure(result: :not_authorized) if ["401", "403"].include?(response.code)return ServiceResult.failure(result: :error) unless response.code == "200" # Interpret any other response as an error@@ -228,4 +245,6 @@ class Storages::FileLinkSyncService!response.key?('content-type') || # Reply without content-type can't be valid.response['content-type'].split(';').first.strip.downcase != 'application/json'end++ # rubocop:enable Metrics/AbcSizeend