Skip to content
2 changes: 2 additions & 0 deletions app/assets/javascripts/change_current_provider.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ $(document).ready ->
'Editing this tool'
when 'clone-tool'
'Cloning this tool'
when 'delete-tool'
'Deleting this tool'

$link.data('type', action)
$modal.find('span.provider').text(provider)
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
class ToolsController < BasePublishedRecordController
include ManageMetadataHelper

before_action :set_tool, only: [:show, :edit, :clone, :revisions, :download_json] #, :destroy, :revert]
before_action :set_schema, only: [:show, :edit, :clone] #, :destroy]
before_action :set_tool, only: [:show, :edit, :clone, :destroy, :revisions, :download_json] #, :revert]
before_action :set_schema, only: [:show, :edit, :clone, :destroy]
before_action :ensure_supported_version, only: [:show, :edit]
before_action :ensure_correct_provider, only: [:edit, :clone] #, :destroy]
before_action :ensure_correct_provider, only: [:edit, :clone, :destroy]
before_action :set_preview, only: [:show]

# If clone is not defined like this performing the clone action leads to a `action not found error`
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_not_current_provider_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<% elsif options[:tool] %>
<%= link_to 'Yes', edit_tool_path(options[:concept_id], revision_id: options[:revision_id]), class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-edit-tool-link' %>
<%= link_to 'Yes', clone_tool_path(options[:concept_id], revision_id: options[:revision_id]), class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-clone-tool-link' %>
<%#= link_to 'Yes', tool_path(options[:concept_id]), method: :delete, class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-delete-tool-link' %>
<%= link_to 'Yes', tool_path(options[:concept_id]), method: :delete, class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-delete-tool-link' %>
<% end %>

<% if options[:draft] %>
Expand Down
17 changes: 8 additions & 9 deletions app/views/tools/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,21 @@

<%= link_to 'Download JSON', download_json_tool_path(@concept_id, revision_id: @revision_id), class: 'eui-btn--link', target: '_blank' %>

<%= link_to 'Delete Tool Record', '#', class: 'display-modal delete-tool eui-btn--link bar-before disabled' %>
<%# if current_provider?(@provider_id) %>
<%#= link_to 'Delete Tool Record', "#delete-record-modal", class: 'display-modal delete-tool eui-btn--link bar-before' %>
<%# elsif available_provider?(@provider_id) %>
<%#= link_to 'Delete Tool Record', '#not-current-provider-modal', class: 'display-modal not-current-provider eui-btn--link bar-before', data: { 'provider': @provider_id, record_action: 'delete-tool', num_associated_collections: "#{@num_associated_collections}" } %>
<%# end %>
<% if current_provider?(@provider_id) %>
<%= link_to 'Delete Tool Record', "#delete-record-modal", class: 'display-modal delete-tool eui-btn--link bar-before' %>
<% elsif available_provider?(@provider_id) %>
<%= link_to 'Delete Tool Record', '#not-current-provider-modal', class: 'display-modal not-current-provider eui-btn--link bar-before', data: { 'provider': @provider_id, record_action: 'delete-tool' } %>
<% end %>

<!-- <div id="delete-record-modal" class="eui-modal-content">
<div id="delete-record-modal" class="eui-modal-content">
<a href="javascript:void(0);" class="modal-close float-r"><i class="fa fa-times"></i><span class="is-invisible">Close</span></a>
<p>
Are you sure you want to delete this tool record?
<p>
<a href="javascript:void(0)" class="eui-btn modal-close">No</a>
<%#= link_to 'Yes', tool_path, method: :delete, class: 'eui-btn--blue spinner' %>
<%= link_to 'Yes', tool_path, method: :delete, class: 'eui-btn--blue spinner' %>
</p>
</div> -->
</div>
<%= render partial: 'shared/not_current_provider_modal', locals: {
options: {
tool: @tool,
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ en:
flash:
success: 'Tool Draft Published Successfully!'
error: 'Tool Draft was not published successfully'
destroy:
flash:
success: 'Tool Deleted Successfully!'
error: 'Tool was not deleted successfully'
clone:
flash:
notice: 'Records must have a unique Name and Long Name within a provider. Click here to enter a new Name and Long Name.'
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
get '/services/:id/clone' => 'services#clone', as: 'clone_service'
get '/services/:id/download_json(/:revision_id)' => 'services#download_json', as: 'download_json_service'

resources :tools, only: [:show, :create, :edit]
resources :tools, only: [:show, :create, :edit, :destroy]
get '/tools/:id/clone' => 'tools#clone', as: 'clone_tool'
get '/tools/:id/revisions' => 'tools#revisions', as: 'tool_revisions'
get '/tools/:id/download_json(/:revision_id)' => 'tools#download_json', as: 'download_json_tool'
Expand Down
95 changes: 95 additions & 0 deletions spec/features/tools/delete_tool_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
describe 'Delete tool', reset_provider: true, js: true do
before :all do
@ingested_tool, _concept_response, _native_id_1 = publish_tool_draft

@ingested_tool_for_delete_messages, _concept_response, @native_id_2 = publish_tool_draft
end

# Remove this section after CMR-6332 is resolved
after :all do
delete_response = cmr_client.delete_tool('MMT_2', @native_id_2, 'token')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a comment to remove this after the reset_provider ticket is resolved (can't recall the ticket number right now)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMR-6332

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added

# First tool should be deleted in the delete test

raise unless delete_response.success?
end

before do
login
end

context 'when viewing a published tool' do
before do
visit tool_path(@ingested_tool['concept-id'])
end

it 'displays a delete link' do
expect(page).to have_content('Delete Tool Record')
end

context 'when clicking the delete link' do
before do
click_on 'Delete Tool Record'
end

it 'displays a confirmation modal' do
expect(page).to have_content('Are you sure you want to delete this tool record?')
end

context 'when clicking Yes' do
before do
within '#delete-record-modal' do
click_on 'Yes'
end
end

it 'redirects to the revisions page and displays a confirmation message' do
expect(page).to have_content('Revision History')

expect(page).to have_content('Tool Deleted Successfully!')
end
end
end
end

context 'when deleting the tool will fail' do
before do
visit tool_path(@ingested_tool_for_delete_messages['concept-id'])
end

context 'when CMR provides a message' do
before do
error_body = '{"errors": ["You do not have permission to perform that action."]}'
error_response = Cmr::Response.new(Faraday::Response.new(status: 401, body: JSON.parse(error_body), response_headers: {}))
allow_any_instance_of(Cmr::CmrClient).to receive(:delete_tool).and_return(error_response)

click_on 'Delete Tool Record'

within '#delete-record-modal' do
click_on 'Yes'
end
end

it 'displays the CMR error message' do
expect(page).to have_css('.eui-banner--danger', text: 'You do not have permission to perform that action.')
end
end

context 'when CMR does not provide a message' do
before do
error_body = '{"message": "useless message"}'
error_response = Cmr::Response.new(Faraday::Response.new(status: 401, body: JSON.parse(error_body), response_headers: {}))
allow_any_instance_of(Cmr::CmrClient).to receive(:delete_tool).and_return(error_response)

click_on 'Delete Tool Record'

within '#delete-record-modal' do
click_on 'Yes'
end
end

it 'displays the CMR error message' do
expect(page).to have_css('.eui-banner--danger', text: 'Tool was not deleted successfully')
end
end
end
end
77 changes: 33 additions & 44 deletions spec/features/tools/tool_permissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
context "when the tool's provider is in the users available providers" do
before :all do
@ingested_tool, _concept_response, @native_id_1 = publish_tool_draft
# @ingested_tool_for_delete_modal, _concept_response, _native_id_2 = publish_tool_draft
end

after :all do
delete_response = cmr_client.delete_tool('MMT_2', @native_id_1, 'token')
# Second tool should be deleted in the delete test

raise unless delete_response.success?
end
Expand Down Expand Up @@ -84,46 +82,38 @@
end
end

# TODO: Uncomment in MMT-2229
# context 'when clicking the delete link' do
# context 'when the tool has no associated collections' do
# before do
# visit tool_path(@ingested_tool_for_delete_modal['concept-id'])
#
# click_on 'Delete Tool Record'
# end
#
# it 'displays a modal informing the user they need to switch providers' do
# expect(page).to have_content("Deleting this tool #{modal_text}")
# end
#
# it 'does not display a message about collection associations that will also be deleted' do
# expect(page).to have_no_content('This tool is associated with')
# expect(page).to have_no_content('collections. Deleting this tool will also delete the collection associations')
# end
# end
#
# context 'when deleting the tool' do
# before do
# ingested_tool_to_delete, _concept_response = publish_tool_draft
#
# visit tool_path(ingested_tool_to_delete['concept-id'])
#
# click_on 'Delete Tool Record'
#
# find('.not-current-provider-link').click
# wait_for_jQuery
# end
#
# it 'switches the provider context' do
# expect(User.first.provider_id).to eq('MMT_2')
# end
#
# it 'deletes the record' do
# expect(page).to have_content('Tool Deleted Successfully!')
# end
# end
# end
context 'when clicking the delete link' do
before do
@ingested_tool_for_delete_modal, _concept_response, @native_id_2 = publish_tool_draft
login(provider: 'MMT_1', providers: %w(MMT_1 MMT_2))
visit tool_path(@ingested_tool_for_delete_modal['concept-id'])

click_on 'Delete Tool Record'
end

it 'displays a modal informing the user they need to switch providers' do
expect(page).to have_content("Deleting this tool #{modal_text}")

# Remove this section after CMR-6332 is resolved
delete_response = cmr_client.delete_tool('MMT_2', @native_id_2, 'token')
raise unless delete_response.success?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that this test was still making searching tools have the error from CMR-6332. Should be able to remove this part after CMR-6332 is resolved.

end

context 'when clicking Yes' do
before do
find('.not-current-provider-link').click
wait_for_jQuery
end

it 'switches the provider context' do
expect(User.first.provider_id).to eq('MMT_2')
end

it 'deletes the record' do
expect(page).to have_content('Tool Deleted Successfully!')
end
end
end

context 'when trying to visit the action paths directly' do
context 'when visiting the edit path directly' do
Expand Down Expand Up @@ -194,8 +184,7 @@
it 'does not display the action links' do
expect(page).to have_no_link('Edit Tool Record')
expect(page).to have_no_link('Clone Tool Record')
# TODO: Uncomment in MMT-2229
# expect(page).to have_no_link('Delete Tool Record')
expect(page).to have_no_link('Delete Tool Record')
end

context 'when trying to visit the action paths directly' do
Expand Down