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

[#40228] added delete endpoint

Eric Schubert7919f5259d32
diff --git a/modules/storages/app/contracts/storages/file_links/delete_contract.rb b/modules/storages/app/contracts/storages/file_links/delete_contract.rb
new file mode 100644
index 00000000000..bcebe5af9d2
--- /dev/null
+++ b/modules/storages/app/contracts/storages/file_links/delete_contract.rb
@@ -0,0 +1,47 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 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
+ module FileLinks
+ class DeleteContract < ::ModelContract
+ def self.model
+ Storages::FileLink
+ end
+
+ validate :validate_manage_allowed
+
+ private
+
+ def validate_manage_allowed
+ unless user.allowed_to?(:manage_file_links, model.container.project)
+ errors.add :base, :error_unauthorized
+ end
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/services/storages/file_links/delete_service.rb b/modules/storages/app/services/storages/file_links/delete_service.rb
new file mode 100644
index 00000000000..92be0972e14
--- /dev/null
+++ b/modules/storages/app/services/storages/file_links/delete_service.rb
@@ -0,0 +1,34 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 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
+ module FileLinks
+ class DeleteService < ::BaseServices::Delete
+ end
+ end
+end
diff --git a/modules/storages/lib/api/v3/file_links/file_links_api.rb b/modules/storages/lib/api/v3/file_links/file_links_api.rb
index 1ee9cfff373..61ad8fb8098 100644
--- a/modules/storages/lib/api/v3/file_links/file_links_api.rb
+++ b/modules/storages/lib/api/v3/file_links/file_links_api.rb
@@ -54,9 +54,9 @@ module API
get &::API::V3::Utilities::Endpoints::Show.new(model: ::Storages::FileLink).mount
- delete do
- raise ::API::Errors::NotImplemented
- end
+ delete &::API::V3::Utilities::Endpoints::Delete.new(model: ::Storages::FileLink,
+ process_service: ::Storages::FileLinks::DeleteService)
+ .mount
mount ::API::V3::FileLinks::FileLinksDownloadAPI
mount ::API::V3::FileLinks::FileLinksOpenAPI
diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb
index f85fb4f408c..ce0ef4f09bd 100644
--- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb
+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb
@@ -60,6 +60,7 @@ describe 'API v3 file links resource', type: :request do
let(:path) { api_v3_paths.file_links(work_package.id) }
before do
+ file_link
get path
end
@@ -115,14 +116,33 @@ describe 'API v3 file links resource', type: :request do
describe 'DELETE /api/v3/work_packages/:work_package_id/file_links/:file_link_id' do
let(:path) { api_v3_paths.file_link(work_package.id, file_link.id) }
+ let(:permissions) { %i(view_work_packages view_file_links manage_file_links) }
before do
header 'Content-Type', 'application/json'
delete path
end
- it 'returns not implemented' do
- expect(subject.status).to be 501
+ it 'is successful' do
+ expect(subject.status).to be 204
+ end
+
+ context 'if user has no view permissions' do
+ let(:permissions) { %i(view_work_packages) }
+
+ it_behaves_like 'not found'
+ end
+
+ context 'if user has no manage permissions' do
+ let(:permissions) { %i(view_work_packages view_file_links) }
+
+ it_behaves_like 'unauthorized access'
+ end
+
+ context 'if no storage with that id exists' do
+ let(:path) { api_v3_paths.file_link(work_package.id, 1337) }
+
+ it_behaves_like 'not found'
end
end