-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to destroy a namespace and its contents (#653)
Co-authored-by: Bess Sadler <bess@users.noreply.github.com> Co-authored-by: Carolyn Cole <carolyncole@users.noreply.github.com>
- Loading branch information
1 parent
4de0389
commit 87783db
Showing
7 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
module Mediaflux | ||
module Http | ||
# Destroy a MediaFlux namespace and everything in it | ||
# @example | ||
# Mediaflux::Http::NamespaceDestroyRequest.new(session_token: session_id, namespace: "/td-test-001/tigerdataNS/Banana1NS").destroy | ||
# => true | ||
class NamespaceDestroyRequest < Request | ||
attr_reader :description, :namespace, :store | ||
|
||
# Constructor | ||
# @param session_token [String] the API token for the authenticated session | ||
# @param namespace [String] name of namespace to be destroyed | ||
def initialize(session_token:, namespace:) | ||
super(session_token: session_token) | ||
@namespace = namespace | ||
end | ||
|
||
def destroy | ||
resolve | ||
if error? | ||
response_error | ||
end | ||
end | ||
|
||
# Specifies the Mediaflux service to use when destroying namespaces | ||
# @return [String] | ||
def self.service | ||
"asset.namespace.hard.destroy" | ||
end | ||
|
||
private | ||
|
||
def build_http_request_body(name:) | ||
super do |xml| | ||
xml.args do | ||
xml.namespace @namespace | ||
xml.atomic true | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
spec/models/mediaflux/http/namespace_destroy_request_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe Mediaflux::Http::NamespaceDestroyRequest, type: :model, connect_to_mediaflux: true do | ||
let(:valid_project) { FactoryBot.create(:project_with_dynamic_directory, project_id: "10.34770/tbd") } | ||
let(:namespace) { "#{valid_project.directory}NS".strip.gsub(/[^A-Za-z\d]/, "-") } | ||
let(:sponsor_user) { FactoryBot.create(:project_sponsor) } | ||
let(:session_id) { sponsor_user.mediaflux_session } | ||
it "deletes a namespace and everything inside of it" do | ||
valid_project | ||
mediaflux_id = ProjectMediaflux.create!(project: valid_project, session_id: session_id) | ||
expect(mediaflux_id).not_to be_nil | ||
namespace_list = Mediaflux::Http::NamespaceListRequest.new(session_token: session_id, parent_namespace: "/td-test-001/tigerdataNS").namespaces | ||
namespace_names = namespace_list.map { |a| a[:name] } | ||
expect(namespace_names).to include(namespace) | ||
|
||
# Destroy the namespace of the project and everything in it | ||
described_class.new(session_token: session_id, namespace: "/td-test-001/tigerdataNS/#{namespace}").destroy | ||
namespace_list = Mediaflux::Http::NamespaceListRequest.new(session_token: session_id, parent_namespace: "/td-test-001/tigerdataNS").namespaces | ||
namespace_names = namespace_list.map { |a| a[:name] } | ||
expect(namespace_names).not_to include(namespace) | ||
response = described_class.new(session_token: session_id, namespace: "/td-test-001/tigerdataNS/#{namespace}").destroy | ||
expect(response[:message]).to include("The namespace '/td-test-001/tigerdataNS/#{namespace}' does not exist or is not accessible") | ||
end | ||
end |