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
[#50987] Add ParentFolder class for clearer code
Dominic Bräunlein02838362ec2e
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rbindex 479b7b640ed..20c2122a093 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb@@ -46,7 +46,7 @@ module Storages@uri = storage.uriend- def call(user:, folder: nil)+ def call(user:, folder:)result = Util.using_user_token(@storage, user) do |token|# Make the Get Request to the necessary endpointsresponse = Net::HTTP.start(@uri.host, @uri.port, use_ssl: true) do |http|@@ -107,7 +107,7 @@ module Storagesenddef empty_response(folder)- files_result = if folder.blank?+ files_result = if folder.root?StorageFiles.new([], root(Digest::SHA256.hexdigest('i_am_root')), [])elseStorageFiles.new(@@ -168,7 +168,7 @@ module Storagesenddef uri_path_for(folder)- return "/v1.0/drives/#{@storage.drive_id}/root/children" unless folder+ return "/v1.0/drives/#{@storage.drive_id}/root/children" if folder.root?"/v1.0/drives/#{@storage.drive_id}/root:#{encode_path(folder)}:/children"enddiff --git a/modules/storages/app/common/storages/peripherals/storage_parent_folder_extractor.rb b/modules/storages/app/common/storages/peripherals/storage_parent_folder_extractor.rbnew file mode 100644index 00000000000..b4c7388111b--- /dev/null+++ b/modules/storages/app/common/storages/peripherals/storage_parent_folder_extractor.rb@@ -0,0 +1,51 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module Storages::Peripherals+ class ParentFolder+ attr_reader :path++ def initialize(path)+ @path = path+ end++ def root?+ @path == '/'+ end++ def to_s+ @path+ end+ end++ module StorageParentFolderExtractor+ def extract_parent_folder(params)+ ParentFolder.new(params[:parent].presence || '/')+ end+ end+enddiff --git a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb b/modules/storages/lib/api/v3/storage_files/storage_files_api.rbindex 25314b3f052..a1a00971d9a 100644--- a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb+++ b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb@@ -31,7 +31,9 @@module API::V3::StorageFilesclass StorageFilesAPI < ::API::OpenProjectAPIusing Storages::Peripherals::ServiceResultRefinements- helpers Storages::Peripherals::StorageErrorHelper, Storages::Peripherals::StorageFileInfoConverter+ helpers Storages::Peripherals::StorageErrorHelper,+ Storages::Peripherals::StorageFileInfoConverter,+ Storages::Peripherals::StorageParentFolderExtractorresources :files doget do@@ -39,7 +41,7 @@ module API::V3::StorageFiles.resolve("queries.#{@storage.short_provider_type}.files").call(storage: @storage,- user: current_user, folder: params[:parent]+ user: current_user, folder: extract_parent_folder(params)).match(on_success: ->(files) { API::V3::StorageFiles::StorageFilesRepresenter.new(files, @storage, current_user:) },