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
More tests added. More incoming - part 2
Marcello Rocha2da63e11fe48
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rbindex af295beef98..e7dcad18f8c 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb@@ -60,9 +60,9 @@ module Storages::Peripherals::StorageInteraction::NextcloudUtil.error(:not_allowed, 'Outbound request method not allowed', response)endwhen Net::HTTPNotFound- Util.error(:not_found, 'Outbound request destination not found!', response)+ Util.error(:not_found, 'Outbound request destination not found', response)when Net::HTTPUnauthorized- Util.error(:unauthorized, 'Outbound request not authorized!', response)+ Util.error(:unauthorized, 'Outbound request not authorized', response)when Net::HTTPConflictUtil.error(:conflict, Util.error_text_from_response(response), response)elsediff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rbindex f9f2d7b1fc6..6ce8e83e521 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.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@@ -53,11 +55,11 @@ module Storages::Peripherals::StorageInteraction::Nextcloudwhen Net::HTTPSuccessServiceResult.successwhen Net::HTTPNotFound- Util.error(:not_found)+ Util.error(:not_found, 'Outbound request destination not found', response)when Net::HTTPUnauthorized- Util.error(:unauthorized)+ Util.error(:unauthorized, 'Outbound request not authorized', response)else- Util.error(:error)+ Util.error(:error, 'Outbound request failed', response)endendenddiff --git a/modules/storages/app/services/storages/group_folder_properties_sync_service.rb b/modules/storages/app/services/storages/group_folder_properties_sync_service.rbindex d17450866a1..e11fa77c3c4 100644--- a/modules/storages/app/services/storages/group_folder_properties_sync_service.rb+++ b/modules/storages/app/services/storages/group_folder_properties_sync_service.rb@@ -190,12 +190,16 @@ module Storagesactive_project_storages_scope.map do |project_storage|next create_folder(project_storage) unless id_folder_map.key?(project_storage.project_folder_id)- if id_folder_map[project_storage.project_folder_id] == project_storage.project_folder_path+ current_path = id_folder_map[project_storage.project_folder_id]+ if current_path == project_storage.project_folder_pathproject_storage.project_folder_idelse- move_folder(project_storage, id_folder_map[project_storage.project_folder_id])+ move_folder(project_storage, current_path).result_or do |error|- error_msg = "MOVE #{project_storage.project_folder_path} #{error.log_message}. Response: #{error.data.inspect}"+ error_msg = { command: 'nextcloud.rename_file',+ source: current_path,+ target: project_storage.project_folder_path,+ data: { status: error.data.code, body: error.data.body } }.to_json# we need to stop as this would mess with the other processesreturn OpenProject.logger.warn error_msgdiff --git a/modules/storages/spec/services/storages/group_folder_properties_sync_service_spec.rb b/modules/storages/spec/services/storages/group_folder_properties_sync_service_spec.rbindex 92ac568e356..14232aaab8f 100644--- a/modules/storages/spec/services/storages/group_folder_properties_sync_service_spec.rb+++ b/modules/storages/spec/services/storages/group_folder_properties_sync_service_spec.rb@@ -776,7 +776,7 @@ RSpec.describe Storages::GroupFolderPropertiesSyncService, :webmock doit 'continues normally ignoring that folder' doexpect { described_class.new(storage).call }.not_to change(project_storage1, :project_folder_id)- expect(request_stubs.delete_at(7)).not_to have_been_requested+ expect(request_stubs.delete_at(5)).not_to have_been_requestedexpect(request_stubs.delete_at(3)).not_to have_been_requestedexpect(request_stubs).to all(have_been_requested)end@@ -792,20 +792,38 @@ RSpec.describe Storages::GroupFolderPropertiesSyncService, :webmock doendendend- #- # context 'when renaming a folder fail' do- # it 'logs the occurrence'- # it 'logs the occurrence' do- # skip 'to be implemented'- # allow(OpenProject.logger).to receive(:warn)- # described_class.new(storage).call- #- # expect(OpenProject.logger).to have_received(:warn) do |msg|- # expect(msg).to eq({}.to_json)- # end- # end- # end- #++ context 'when renaming a folder fail' do+ before do+ request_stubs[4] = stub_request(:move,+ "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \+ "Lost%20Jedi%20Project%20Folder%20%233/")+ .with(headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',+ 'Destination' => "/remote.php/dav/files/OpenProject/OpenProject/" \+ "Jedi%20Project%20Folder%20%7C%7C%7C%20%28#{project2.id}%29/"+ })+ .to_return(status: 404, body: "", headers: {})+ end++ it 'we stop processing to avoid issues with permissions' do+ described_class.new(storage).call+ request_stubs[5..].each { |request| expect(request).not_to have_been_requested }+ end++ it 'logs the occurrence' do+ allow(OpenProject.logger).to receive(:warn)+ described_class.new(storage).call++ expect(OpenProject.logger).to have_received(:warn) do |msg, _|+ expect(msg).to eq({ command: 'nextcloud.rename_file',+ source: "OpenProject/Lost Jedi Project Folder #3/",+ target: project_storage2.project_folder_path,+ data: { status: '404', body: '' } }.to_json)+ end+ end+ end+# context 'when hiding a folder fail' do# it 'logs the occurrence' do# skip 'to be implemented'@@ -905,45 +923,7 @@ RSpec.describe Storages::GroupFolderPropertiesSyncService, :webmock do}).to_return(status: 207, body: created_folder_propfind_response_body, headers: {})- request_stubs << stub_request(:post, "#{storage.host}/ocs/v1.php/cloud/users/Obi-Wan/groups")- .with(- body: "groupid=OpenProject",- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',- 'Ocs-Apirequest' => 'true'- }- ).to_return(status: 200, body: add_user_to_group_response_body, headers: {})-- request_stubs << stub_request(:post, "#{storage.host}/ocs/v1.php/cloud/users/Yoda/groups")- .with(- body: "groupid=OpenProject",- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',- 'Ocs-Apirequest' => 'true'- }- ).to_return(status: 200, body: add_user_to_group_response_body, headers: {})-- request_stubs << stub_request(:post, "#{storage.host}/ocs/v1.php/cloud/users/Darth%20Vader/groups")- .with(- body: "groupid=OpenProject",- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',- 'Ocs-Apirequest' => 'true'- }- ).to_return(status: 200, body: add_user_to_group_response_body, headers: {})-- # 7 - Set Permissions for the Created Folder- request_stubs << stub_request(- :proppatch,- "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \- "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})/"- ).with(- body: created_folder_set_permissions_request_body,- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='- }- ).to_return(status: 207, body: created_folder_set_permissions_response_body, headers: {})-+ # 4 - Move/Rename Folderrequest_stubs << stub_request(:move,"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \@@ -956,6 +936,18 @@ RSpec.describe Storages::GroupFolderPropertiesSyncService, :webmock do}).to_return(status: 201, body: "", headers: {})+ # 5 - Set Permissions for the Created Folder+ request_stubs << stub_request(+ :proppatch,+ "#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \+ "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})/"+ ).with(+ body: created_folder_set_permissions_request_body,+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='+ }+ ).to_return(status: 207, body: created_folder_set_permissions_response_body, headers: {})+request_stubs << stub_request(:proppatch,"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \@@ -1044,6 +1036,33 @@ RSpec.describe Storages::GroupFolderPropertiesSyncService, :webmock do</d:error>XML+ request_stubs << stub_request(:post, "#{storage.host}/ocs/v1.php/cloud/users/Obi-Wan/groups")+ .with(+ body: "groupid=OpenProject",+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',+ 'Ocs-Apirequest' => 'true'+ }+ ).to_return(status: 200, body: add_user_to_group_response_body, headers: {})++ request_stubs << stub_request(:post, "#{storage.host}/ocs/v1.php/cloud/users/Yoda/groups")+ .with(+ body: "groupid=OpenProject",+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',+ 'Ocs-Apirequest' => 'true'+ }+ ).to_return(status: 200, body: add_user_to_group_response_body, headers: {})++ request_stubs << stub_request(:post, "#{storage.host}/ocs/v1.php/cloud/users/Darth%20Vader/groups")+ .with(+ body: "groupid=OpenProject",+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',+ 'Ocs-Apirequest' => 'true'+ }+ ).to_return(status: 200, body: add_user_to_group_response_body, headers: {})+request_stubs << stub_request(:propfind,"#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/Project3%20(#{project3.id})/"