[#40228] added delete endpoint

pull/10183/head
Eric Schubert 3 years ago
parent b53fb9f15f
commit 7919f5259d
No known key found for this signature in database
GPG Key ID: 1D346C019BD4BAA2
  1. 47
      modules/storages/app/contracts/storages/file_links/delete_contract.rb
  2. 34
      modules/storages/app/services/storages/file_links/delete_service.rb
  3. 6
      modules/storages/lib/api/v3/file_links/file_links_api.rb
  4. 24
      modules/storages/spec/requests/api/v3/file_links/file_links_spec.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

@ -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

@ -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

@ -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

Loading…
Cancel
Save