diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index acfdbda29..d92f31a8e 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -2,7 +2,7 @@ class ToolsController < BasePublishedRecordController include ManageMetadataHelper - before_action :set_tool, only: [:show, :edit] #, :clone, :destroy, :revisions, :revert, :download_json] + before_action :set_tool, only: [:show, :edit, :revisions] #, :clone, :destroy, :revert, :download_json] 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] diff --git a/app/helpers/manage_metadata_helper.rb b/app/helpers/manage_metadata_helper.rb index 43f752208..c420b2c47 100644 --- a/app/helpers/manage_metadata_helper.rb +++ b/app/helpers/manage_metadata_helper.rb @@ -80,7 +80,7 @@ def resource_type end def display_header_subtitle(metadata, type) - return unless type.downcase.include?('variable') || type.downcase.include?('service') + return unless ['variable', 'service', 'tool'].any? { |type_fragment| type.downcase.include?(type_fragment) } metadata['LongName'] || 'Long Name Not Provided' end diff --git a/app/views/tools/revisions.html.erb b/app/views/tools/revisions.html.erb new file mode 100644 index 000000000..9c4f2a277 --- /dev/null +++ b/app/views/tools/revisions.html.erb @@ -0,0 +1,119 @@ +<% content_for :header_title do %> +

<%= fetch_entry_id(@tool, 'tools') %>

+

<%= display_header_subtitle(@tool, 'tool') %>

+<% end %> + +<% if @errors && !@errors.empty? %> +
+
+
+
    + <% @errors.each do |error| %> +
  • + <%= "#{error[:field]}, " if error[:field] %> + <%= error[:error] %> + <% if error[:request_id] %> + Click here to submit feedback + <% end %> +
  • + <% end %> +
+
+
+
+<% end %> + +
+
+

Revision History

+
+ <% if @error %> +
+
+

+ This tool could not be updated. You may <%= link_to 'edit', edit_tool_path(revision_id: @revision_id) %> the tool to resolve these issues. +

+
+
+ <% end %> +
+
+ + + + + + + + + + + <% @revisions.each_with_index do |revision, index| %> + <% revision_id = revision['meta']['revision-id'] %> + + + + + + + <% end %> + +
DescriptionRevision DateAction byActions
+ <% title = "View revision #{revision_id}" %> + <%= revision_id %> - + <% if revision['meta']['deleted'] == true %> + Deleted + <% elsif index == 0 %> + Published + <%# Uncomment in MMT-2232 %> + <%#= link_to 'View', tool_path(revision_id: revision_id), title: title %> + <% else %> + Revision + <%# Uncomment in MMT-2232 %> + <%#= link_to 'View', tool_path(revision_id: revision_id), title: title %> + <% end %> + + <%= revision['meta']['revision-date'] %> + + <%= revision['meta']['user-id'] %> + + <% if @revisions.first['meta']['deleted'] == true %> + <% phrase = 'Reinstate' %> + <% confirm_phrase = 'Are you sure you want to reinstate this record?' %> + <% action = 'reinstate-tool' %> + <% else %> + <% phrase = 'Revert to this Revision' %> + <% confirm_phrase = 'Are you sure you want to revert to this revision?' %> + <% action = 'revert-tool' %> + <% end %> + + <% unless index == 0 || revision['meta']['deleted'] == true %> + <%# Uncomment in MMT-2233 %> + <%# if current_provider?(@provider_id) %> + <%#= link_to phrase, "#revert-revisions-modal-#{revision_id}", class: 'display-modal' %> + <%# elsif available_provider?(@provider_id) %> + <%#= link_to phrase, "#not-current-provider-modal-#{revision_id}", class: 'display-modal not-current-provider', data: { 'provider': @provider_id, record_action: action } %> + <%# end %> + + <% end %> +
+
+
+
diff --git a/app/views/tools/show.html.erb b/app/views/tools/show.html.erb index 9cf647aed..6665cf2bb 100644 --- a/app/views/tools/show.html.erb +++ b/app/views/tools/show.html.erb @@ -133,8 +133,7 @@ } %>

- <%= link_to 'Revisions', '#', class: 'eui-btn--link disabled' %> - <%#= link_to "Revisions (#{@revisions.size})", tool_revisions_path, class: 'eui-btn--link disabled' %> + <%= link_to "Revisions (#{@revisions.size})", tool_revisions_path, class: 'eui-btn--link' %>

diff --git a/config/routes.rb b/config/routes.rb index 4b61880ee..6e8cc5c8a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -104,6 +104,7 @@ get '/services/:id/download_json(/:revision_id)' => 'services#download_json', as: 'download_json_service' resources :tools, only: [:show, :create, :edit] + get '/tools/:id/revisions' => 'tools#revisions', as: 'tool_revisions' resources :variable_drafts, controller: 'variable_drafts', draft_type: 'VariableDraft' do member do diff --git a/spec/features/services/revision_list_spec.rb b/spec/features/services/revision_list_spec.rb index 80a1a2c18..6fbe57f1d 100644 --- a/spec/features/services/revision_list_spec.rb +++ b/spec/features/services/revision_list_spec.rb @@ -1,5 +1,3 @@ -require 'rails_helper' - describe 'Service revision list', reset_provider: true, js: true do context 'when viewing a published service' do before do diff --git a/spec/features/tools/revision_list_spec.rb b/spec/features/tools/revision_list_spec.rb new file mode 100644 index 000000000..b33ba78f1 --- /dev/null +++ b/spec/features/tools/revision_list_spec.rb @@ -0,0 +1,90 @@ +describe 'Tool revision list', reset_provider: true, js: true do + context 'when viewing a published tool' do + before :all do + @ingest_response, @concept_response, @native_id = publish_tool_draft(revision_count: 2) + end + + # TODO: remove after CMR-6332 + after :all do + delete_response = cmr_client.delete_tool('MMT_2', @native_id, 'token') + + raise unless delete_response.success? + end + + before do + login + + visit tool_path(@ingest_response['concept-id']) + end + + it 'displays the number of revisions' do + expect(page).to have_content('Revisions (2)') + end + + context 'when clicking on the revision link' do + before do + wait_for_cmr + click_on 'Revisions' + end + + it 'displays the revision page' do + expect(page).to have_content('Revision History') + end + + it 'displays the tool long name' do + expect(page).to have_content(@concept_response.body['LongName']) + end + + it 'displays when the revision was made' do + expect(page).to have_content(today_string, count: 2) + end + + it 'displays what user made the revision' do + expect(page).to have_content('typical', count: 2) + end + +# TODO: Uncomment in MMT-2233 +# it 'displays the correct phrasing for reverting records' do +# expect(page).to have_content('Revert to this Revision', count: 1) +# end + +# TODO: Uncomment in MMT-2232 +# context 'when viewing an old revision' do +# link_text = 'You are viewing an older revision of this tool. Click here to view the latest published version.' +# before do +# all('a', text: 'View').last.click +# end +# +# it 'displays a message that the revision is old' do +# expect(page).to have_link(link_text) +# end +# +# it 'does not display a link to manage collection associations' do +# expect(page).to have_no_link('Manage Collection Associations') +# end +# +# context 'when clicking the message' do +# before do +# click_on link_text +# end +# +# it 'displays the latest revision to the user' do +# expect(page).to have_no_link(link_text) +# end +# end +# end + end + + context 'when searching for the tool' do + before do + full_search(record_type: 'Tools', keyword: @concept_response.body['LongName'], provider: 'MMT_2') + end + + it 'only displays the latest revision' do + within '#tool-search-results' do + expect(page).to have_content(@concept_response.body['LongName'], count: 1) + end + end + end + end +end