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
Clean up the call methods and start flipping to the containers
Marcello Rochab20319b0ff36
diff --git a/modules/storages/app/common/storages/peripherals/registry.rb b/modules/storages/app/common/storages/peripherals/registry.rbindex 12ee4c8980f..32b687d8db3 100644--- a/modules/storages/app/common/storages/peripherals/registry.rb+++ b/modules/storages/app/common/storages/peripherals/registry.rb@@ -4,7 +4,6 @@ module Storagesextend Dry::Container::Mixinend- require_relative 'storage_interaction/nextcloud'- require_relative 'storage_interaction/sharepoint'+ Registry.import StorageInteraction::Nextcloud::Queriesendenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rbindex 6bb3e943488..168d52093a9 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb@@ -1,20 +1,47 @@+# frozen_string_literal:true++#-- 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 Storagesmodule Peripheralsmodule StorageInteractionmodule NextcloudQueries = Dry::Container::Namespace.new('queries') donamespace('nextcloud') do- register(:file_query, FileQuery.new)- register(:download_link_query) { DownloadLinkQuery }- register(:files_query, FilesQuery.new)- register(:upload_link_query) { UploadLinkQuery }- register(:group_users_query) { GroupUsersQuery }- register(:propfind_query) { PropfindQuery }+ register(:download_link_query, DownloadLinkQuery)+ register(:files_query, FilesQuery)+ register(:upload_link_query, UploadLinkQuery)+ register(:group_users_query, GroupUsersQuery)+ register(:propfind_query, Internal::PropfindQuery)endendendend-- Registry.import StorageInteraction::Nextcloud::Queriesendenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rbindex 2004a9cde4a..0c30fb2a3e1 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb@@ -35,6 +35,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud@oauth_client = storage.oauth_clientend+ def self.call(storage:, user:, file_link:)+ new(storage).call(user:, file_link:)+ end+# rubocop:disable Metrics/AbcSizedef call(user:, file_link:)result = Util.token(user:, oauth_client: @oauth_client) do |token|diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rbindex e1b0f255be0..66688722038 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb@@ -33,6 +33,10 @@ module Storages::Peripherals::StorageInteraction::Nextcloud@oauth_client = storage.oauth_clientend+ def self.call(storage:, user:, folder:)+ new(storage).call(user:, folder:)+ end+# rubocop:disable Metrics/AbcSizedef call(user:, folder:)result = Util.token(user:, oauth_client: @oauth_client) do |token|diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rbindex 36fdea298cf..dc79744f591 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb@@ -34,11 +34,14 @@ module Storages::Peripherals::StorageInteraction::Nextcloud@uri = URI(storage.host).normalize@username = storage.username@password = storage.password- @group = storage.group+ end++ def self.call(storage:, group: storage.group)+ new(storage).call(group:)end# rubocop:disable Metrics/AbcSize- def call(group: @group)+ def call(group:)response = Util.http(@uri).get(Util.join_uri_path(@uri, "ocs/v1.php/cloud/groups", CGI.escapeURIComponent(group)),Util.basic_auth_header(@username, @password).merge('OCS-APIRequest' => 'true')diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rbindex 042e70678e7..7f451e39544 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb@@ -47,12 +47,12 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Util)end- def join_uri_path(uri, *parts)+ def join_uri_path(uri, *)# We use `File.join` to ensure single `/` in between every part. This API will break if executed on a# Windows context, as it used `\` as file separators. But we anticipate that OpenProject# Server is not run on a Windows context.# URI::join cannot be used, as it behaves very different for the path parts depending on trailing slashes.- File.join(uri.to_s, *parts)+ File.join(uri.to_s, *)enddef token(user:, oauth_client:, &block)diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/sharepoint.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/sharepoint.rbdeleted file mode 100644index 314b13a8a86..00000000000--- a/modules/storages/app/common/storages/peripherals/storage_interaction/sharepoint.rb+++ /dev/null@@ -1,20 +0,0 @@-module Storages- module Peripherals- module StorageInteraction- module Sharepoint- Queries = Dry::Container::Namespace.new('queries') do- namespace('sharepoint') do- register(:file_query, 10)- # register(:download_link_query) { DownloadLinkQuery }- # register(:files_query) { FilesQuery }- # register(:upload_link_query) { UploadLinkQuery }- # register(:group_users_query) { GroupUsersQuery }- # register(:propfind_query) { PropfindQuery }- end- end- end- end-- Registry.import StorageInteraction::Sharepoint::Queries- end-enddiff --git a/modules/storages/app/common/storages/peripherals/storage_requests.rb b/modules/storages/app/common/storages/peripherals/storage_requests.rbindex 9bdaed7341c..3ccbd2e5cc4 100644--- a/modules/storages/app/common/storages/peripherals/storage_requests.rb+++ b/modules/storages/app/common/storages/peripherals/storage_requests.rb@@ -39,18 +39,19 @@ module Storages::Peripherals].freezeQUERIES = %i[- download_link_query- files_info_query- files_queryfile_ids_query+ files_info_queryfolder_files_file_ids_deep_queryupload_link_query- group_users_query].freezedef initialize(storage:)@storage = storageend+ #+ # def self.call(storage:, operation:, **)+ # Registry.resolve("queries.#{storage.short_provider_type}.#{operation}").call(storage:, **)+ # end(COMMANDS + QUERIES).each do |request|define_method(request) do@@ -59,5 +60,19 @@ module Storages::Peripheralsclazz.new(@storage).method(:call).to_procendend++ private++ def method_missing(name, *args)+ Registry.resolve("queries.#{@storage.short_provider_type}.#{name}")+ rescue Dry::Container::KeyError+ super+ end++ def respond_to_missing?(name)+ !!Registry.resolve("queries.#{@storage.short_provider_type}.#{name}")+ rescue Dry::Container::KeyError+ super+ endendenddiff --git a/modules/storages/app/models/storages/nextcloud_storage.rb b/modules/storages/app/models/storages/nextcloud_storage.rbindex acd2d42025b..2e1338ba5dc 100644--- a/modules/storages/app/models/storages/nextcloud_storage.rb+++ b/modules/storages/app/models/storages/nextcloud_storage.rb@@ -66,4 +66,6 @@ class Storages::NextcloudStorage < Storages::Storagedef provider_fields_defaultsPROVIDER_FIELDS_DEFAULTSend++ def namespace = 'nextcloud'enddiff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rbindex ce5c90fcf45..cc54f194bd3 100644--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb@@ -86,7 +86,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return a download link URL' doresult = subject.download_link_query- .call(user:, file_link:)+ .call(storage:, user:, file_link:)expect(result).to be_successexpect(result.result).to be_eql(uri)end@@ -97,7 +97,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return a download link URL' doresult = subject.download_link_query- .call(user:, file_link:)+ .call(storage:, user:, file_link:)expect(result).to be_successexpect(result.result).to be_eql(uri)end@@ -124,7 +124,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return ":not_authorized" ServiceResult' doresult = subject.download_link_query- .call(user:, file_link:)+ .call(storage:, user:, file_link:)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)end@@ -138,7 +138,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return :not_authorized ServiceResult' doresult = subject.download_link_query- .call(user:, file_link:)+ .call(user:, file_link:, storage:)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)end@@ -153,7 +153,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit "must return :#{symbol} ServiceResult" doresult = subject.download_link_query- .call(user:, file_link:)+ .call(user:, file_link:, storage:)expect(result).to be_failureexpect(result.errors.code).to be(symbol)end@@ -187,23 +187,25 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true dodescribe 'with Nextcloud storage type selected' doit 'returns a list files directories with names and permissions' do- result = subject.files_query.call(folder: nil, user:)+ result = subject.files_query.call(folder: nil, user:, storage:)expect(result).to be_success- expect(result.result.files.size).to eq(4)- expect(result.result.ancestors.size).to eq(0)- expect(result.result.parent).not_to be_nil- expect(result.result.files[0]).to have_attributes(id: '11',- name: 'Folder1',- mime_type: 'application/x-op-directory',- permissions: include(:readable, :writeable))- expect(result.result.files[1]).to have_attributes(mime_type: 'application/x-op-directory',- permissions: %i[readable])- expect(result.result.files[2]).to have_attributes(id: '12',- name: 'README.md',- mime_type: 'text/markdown',- permissions: include(:readable, :writeable))- expect(result.result.files[3]).to have_attributes(mime_type: 'application/pdf',- permissions: %i[readable])++ query_result = result.result+ expect(query_result.files.size).to eq(4)+ expect(query_result.ancestors.size).to eq(0)+ expect(query_result.parent).not_to be_nil+ expect(query_result.files[0]).to have_attributes(id: '11',+ name: 'Folder1',+ mime_type: 'application/x-op-directory',+ permissions: include(:readable, :writeable))+ expect(query_result.files[1]).to have_attributes(mime_type: 'application/x-op-directory',+ permissions: %i[readable])+ expect(query_result.files[2]).to have_attributes(id: '12',+ name: 'README.md',+ mime_type: 'text/markdown',+ permissions: include(:readable, :writeable))+ expect(query_result.files[3]).to have_attributes(mime_type: 'application/pdf',+ permissions: %i[readable])enddescribe 'with origin user id containing whitespaces' do@@ -213,7 +215,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit doresult = subject.files_query- .call(folder: parent, user:)+ .call(folder: parent, user:, storage:)expect(result.result.files[0].location).to eq('/Folder1')assert_requested(:propfind, request_url)@@ -226,7 +228,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit doresult = subject.files_query- .call(folder: parent, user:)+ .call(folder: parent, user:, storage:)expect(result.result.files[2].location).to eq('/Photos/Birds/README.md')expect(result.result.ancestors[0].location).to eq('/')expect(result.result.ancestors[1].location).to eq('/Photos')@@ -241,7 +243,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit doresult = subject.files_query- .call(folder: nil, user:)+ .call(folder: nil, user:, storage:)expect(result.result.files[2].location).to eq('/README.md')assert_requested(:propfind, request_url)end@@ -254,7 +256,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit doresult = subject.files_query- .call(folder: parent, user:)+ .call(folder: parent, user:, storage:)expect(result.result.files[2].location).to eq('/Photos/Birds/README.md')assert_requested(:propfind, request_url)@@ -282,7 +284,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return ":not_authorized" ServiceResult' doresult = subject.files_query- .call(folder: parent, user:)+ .call(folder: parent, user:, storage:)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)end@@ -298,7 +300,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit "must return :#{symbol} ServiceResult" doresult = subject.files_query- .call(folder: parent, user:)+ .call(folder: parent, user:, storage:)expect(result).to be_failureexpect(result.errors.code).to be(symbol)end@@ -436,7 +438,7 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true doit 'responds with a strings array with group users' doresult = subject.group_users_query- .call+ .call(storage:)expect(result).to be_successexpect(result.result).to eq(["admin", "OpenProject", "reader", "TestUser", "TestUser34"])end