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

[#49233] added delete folder command

Eric Schubert1f8676f660ec
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/delete_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/delete_folder_command.rb
new file mode 100644
index 00000000000..78117222220
--- /dev/null
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/delete_folder_command.rb
@@ -0,0 +1,39 @@
+#-- 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::StorageInteraction::Nextcloud
+ class DeleteFolderCommand
+ def initialize(storage)
+ @delegate = Internal::DeleteEntityCommand.new(storage)
+ end
+
+ def call(location:)
+ @delegate.call(location:)
+ end
+ end
+end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb
new file mode 100644
index 00000000000..da930005c6c
--- /dev/null
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb
@@ -0,0 +1,58 @@
+#-- 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::StorageInteraction::Nextcloud::Internal
+ class DeleteEntityCommand
+ UTIL = ::Storages::Peripherals::StorageInteraction::Nextcloud::Util
+
+ def initialize(storage)
+ @uri = URI(storage.host).normalize
+ @base_path = UTIL.join_uri_path(@uri.path, "remote.php/dav/files", CGI.escapeURIComponent(storage.username))
+ @username = storage.username
+ @password = storage.password
+ end
+
+ def call(location:)
+ response = UTIL.http(@uri).delete(
+ UTIL.join_uri_path(@base_path, UTIL.escape_path(location)),
+ UTIL.basic_auth_header(@username, @password)
+ )
+
+ case response
+ when Net::HTTPSuccess
+ ServiceResult.success
+ when Net::HTTPNotFound
+ UTIL.error(:not_found)
+ when Net::HTTPUnauthorized
+ UTIL.error(:not_authorized)
+ else
+ UTIL.error(:error)
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/common/storages/peripherals/storage_requests.rb b/modules/storages/app/common/storages/peripherals/storage_requests.rb
index 558e40d4dee..12aafaf70b3 100644
--- a/modules/storages/app/common/storages/peripherals/storage_requests.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_requests.rb
@@ -32,6 +32,7 @@ module Storages::Peripherals
set_permissions_command
create_folder_command
add_user_to_group_command
+ delete_folder_command
remove_user_from_group_command
rename_file_command
copy_template_folder_command
diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
index 9d5e6951df5..861efc53f7f 100644
--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
@@ -1000,4 +1000,21 @@ RSpec.describe Storages::Peripherals::StorageRequests, webmock: true do
end
end
end
+
+ describe '#delete_folder_command' do
+ before do
+ stub_request(:delete, "https://example.com/remote.php/dav/files/OpenProject/OpenProject/Folder%201")
+ .with(headers: { 'Authorization' => 'Basic T3BlblByb2plY3Q6T3BlblByb2plY3RTZWN1cmVQYXNzd29yZA==' })
+ .to_return(status: 204, body: '', headers: {})
+ end
+
+ describe 'with Nextcloud storage type selected' do
+ it 'deletes the folder' do
+ result = subject
+ .delete_folder_command
+ .call(location: 'OpenProject/Folder 1')
+ expect(result).to be_success
+ end
+ end
+ end
end