Skip to content

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

Pattern matching and variable rename

Marcello Rocha6b75c7ff5a35
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/create_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/create_folder_command.rb
index 2e30ce60e52..d06e1375bf5 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/create_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/create_folder_command.rb
@@ -56,17 +56,17 @@ module Storages
def handle_response(response)
data = ::Storages::StorageErrorData.new(source: self.class, payload: response)
- case response.status
- when 200..299
+ case response
+ in { status: 200..299 }
ServiceResult.success(result: file_info_for(MultiJson.load(response.body, symbolize_keys: true)),
message: 'Folder was successfully created.')
- when 404
+ in { status: 404 }
ServiceResult.failure(result: :not_found,
errors: ::Storages::StorageError.new(code: :not_found, data:))
- when 401
+ in { status: 401 }
ServiceResult.failure(result: :unauthorized,
errors: ::Storages::StorageError.new(code: :unauthorized, data:))
- when 409
+ in { status: 409 }
ServiceResult.failure(result: :already_exists,
errors: ::Storages::StorageError.new(code: :conflict, data:))
else
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb
index cc6ab26d733..d56e475c06c 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb
@@ -48,17 +48,17 @@ module Storages
data = ::Storages::StorageErrorData.new(source: self.class, payload: response)
- case response.status
- when 200..299
+ case response
+ in { status: 200..299 }
# The service returns a 204 with an empty body
ServiceResult.success
- when 401
+ in { status: 401 }
ServiceResult.failure(result: :unauthorized,
errors: ::Storages::StorageError.new(code: :unauthorized, data:))
- when 404
+ in { status: 404 }
ServiceResult.failure(result: :not_found,
errors: ::Storages::StorageError.new(code: :not_found, data:))
- when 409
+ in { status: 409 }
ServiceResult.failure(result: :conflict,
errors: ::Storages::StorageError.new(code: :conflict, data:))
else
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/rename_file_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/rename_file_command.rb
index 78f2d41852f..fd0f18b07e3 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/rename_file_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/rename_file_command.rb
@@ -55,16 +55,16 @@ module Storages
def handle_response(response)
data = ::Storages::StorageErrorData.new(source: self.class, payload: response)
- case response.status
- when 200..299
+ case response
+ in { status: 200..299 }
ServiceResult.success(result: storage_file(response.json(symbolize_keys: true)))
- when 401
+ in { status: 401 }
ServiceResult.failure(result: :unauthorized,
errors: ::Storages::StorageError.new(code: :unauthorized, data:))
- when 404
+ in { status: 404 }
ServiceResult.failure(result: :not_found,
errors: ::Storages::StorageError.new(code: :not_found, data:))
- when 409
+ in { status: 409 }
ServiceResult.failure(result: :conflict,
errors: ::Storages::StorageError.new(code: :conflict, data:))
else
diff --git a/modules/storages/app/services/storages/one_drive_managed_folder_sync_service.rb b/modules/storages/app/services/storages/one_drive_managed_folder_sync_service.rb
index 3c5c538633b..0b105d767da 100644
--- a/modules/storages/app/services/storages/one_drive_managed_folder_sync_service.rb
+++ b/modules/storages/app/services/storages/one_drive_managed_folder_sync_service.rb
@@ -46,9 +46,9 @@ module Storages
def call
return unless @storage.automatic_management_enabled?
- rfm = remote_folders_map.on_failure { |failed_result| return failed_result }.result
+ existing_remote_folders = remote_folders_map.on_failure { |failed_result| return failed_result }.result
- ensure_folders_exist(rfm).on_success { hide_inactive_folders(rfm) }
+ ensure_folders_exist(existing_remote_folders).on_success { hide_inactive_folders(existing_remote_folders) }
apply_permission_to_folders
end