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

[#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.yml
index 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: Error
errorIdentifier: 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 links
diff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rb
index 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::StorageFilesAPI
end
end
diff --git a/modules/storages/spec/requests/api/v3/storages/storages_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_spec.rb
index 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 do
include API::V3::Utilities::PathHelper
let(:permissions) { %i(view_work_packages view_file_links) }
@@ -76,7 +76,7 @@ describe 'API v3 storages resource', type: :request, content_type: :json do
describe 'GET /api/v3/storages/:storage_id' do
let(: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' do
let!(: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 do
end
end
- 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' do
let(: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 do
end
end
+ 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' do
let(: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.rb
index 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|
end
end
+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) do
provided_message || message