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
[#44901] API endpoint for deleting a file storage
Eric Schubert2fc97653d4fc
diff --git a/docs/api/apiv3/paths/storage.yml b/docs/api/apiv3/paths/storage.ymlindex 7b73abb5080..547ec577760 100644--- a/docs/api/apiv3/paths/storage.yml+++ b/docs/api/apiv3/paths/storage.yml@@ -27,7 +27,7 @@ get:content:application/hal+json:schema:- $ref: "../components/schemas/error_response.yml"+ $ref: '../components/schemas/error_response.yml'example:_type: ErrorerrorIdentifier: urn:openproject-org:api:v3:errors:NotFound@@ -37,3 +37,50 @@ get:**Required permission:** view file links+delete:+ summary: Deletes a storage.+ operationId: delete_storage+ tags:+ - File links+ description: |-+ Deletes a storage resource. This also deletes all related records, like the created oauth application, client, and+ any file links created within this storage.+ parameters:+ - name: id+ description: Storage id+ in: path+ required: true+ schema:+ type: integer+ example: 1337+ responses:+ '204':+ description: No content+ '403':+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ examples:+ response:+ value:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission+ message: You are not authorized to access this resource.+ description: |-+ Returned if the client does not have sufficient permissions.++ **Required permission:** admin+ '404':+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ example:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:NotFound+ message: The requested resource could not be found.+ description: |-+ Returned if the storage does not exist or the client does not have sufficient permissions to see it.++ **Required permission:** view file linksdiff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rbindex 69d8a5e07b2..8330d2afcf9 100644--- a/modules/storages/lib/api/v3/storages/storages_api.rb+++ b/modules/storages/lib/api/v3/storages/storages_api.rb@@ -58,6 +58,8 @@ class API::V3::Storages::StoragesAPI < ::API::OpenProjectAPI# route.get &::API::V3::Utilities::Endpoints::Show.new(model: ::Storages::Storage).mount+ delete &::API::V3::Utilities::Endpoints::Delete.new(model: ::Storages::Storage).mount+mount API::V3::StorageFiles::StorageFilesAPIendenddiff --git a/modules/storages/spec/requests/api/v3/storages/storages_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_spec.rbindex 8821585e89a..6f9c75db5b0 100644--- a/modules/storages/spec/requests/api/v3/storages/storages_spec.rb+++ b/modules/storages/spec/requests/api/v3/storages/storages_spec.rb@@ -29,7 +29,7 @@require 'spec_helper'require_module_spec_helper-describe 'API v3 storages resource', type: :request, content_type: :json do+describe 'API v3 storages resource', content_type: :json doinclude API::V3::Utilities::PathHelperlet(:permissions) { %i(view_work_packages view_file_links) }@@ -76,7 +76,7 @@ describe 'API v3 storages resource', type: :request, content_type: :json dodescribe 'GET /api/v3/storages/:storage_id' dolet(:path) { api_v3_paths.storage(storage.id) }- context 'when user belongs to a project using the given storage' do+ context 'if user belongs to a project using the given storage' dolet!(:project_storage) { create(:project_storage, project:, storage:) }it_behaves_like 'successful storage response'@@ -94,7 +94,7 @@ describe 'API v3 storages resource', type: :request, content_type: :json doendend- context 'when user has :manage_storages_in_project permission in any project' do+ context 'if user has :manage_storages_in_project permission in any project' dolet(:permissions) { %i(manage_storages_in_project) }it_behaves_like 'successful storage response'@@ -153,6 +153,34 @@ describe 'API v3 storages resource', type: :request, content_type: :json doendend+ describe 'DELETE /api/v3/storages/:storage_id' do+ let(:path) { api_v3_paths.storage(storage.id) }++ subject(:last_response) do+ delete path+ end++ context 'as admin' do+ let(:current_user) { create(:admin) }++ it_behaves_like 'successful no content response'+ end++ context 'as non-admin' do+ context 'if user belongs to a project using the given storage' do+ it_behaves_like 'unauthorized access'+ end++ context 'if user does not belong to a project using the given storage' do+ let(:current_user) do+ create(:user, member_with_permissions: permissions)+ end++ it_behaves_like 'not found'+ end+ end+ end+describe 'GET /api/v3/storages/:storage_id/files' dolet(:path) { api_v3_paths.storage_files(storage.id) }diff --git a/spec/requests/api/v3/support/response_examples.rb b/spec/requests/api/v3/support/response_examples.rbindex f7fd3802aef..3ec05eac15f 100644--- a/spec/requests/api/v3/support/response_examples.rb+++ b/spec/requests/api/v3/support/response_examples.rb@@ -40,6 +40,12 @@ shared_examples_for 'successful response' do |code = 200|endend+shared_examples_for 'successful no content response' do |code = 204|+ it "has the status code #{code}" do+ expect(last_response.status).to eq(code)+ end+end+shared_examples_for 'error response' do |code, id, provided_message = nil|let(:expected_message) doprovided_message || message