diff --git a/app/controllers/admin/review_reminders_controller.rb b/app/controllers/admin/review_reminders_controller.rb index 2519eca85eb..9361f537119 100644 --- a/app/controllers/admin/review_reminders_controller.rb +++ b/app/controllers/admin/review_reminders_controller.rb @@ -1,6 +1,6 @@ class Admin::ReviewRemindersController < Admin::BaseController before_action :load_document - before_action :load_review_reminder, only: %i[edit update] + before_action :load_review_reminder, only: %i[edit update confirm_destroy destroy] before_action :build_review_reminder, only: %i[new create] before_action :enforce_permissions! @@ -24,6 +24,13 @@ def update end end + def confirm_destroy; end + + def destroy + @review_reminder.destroy! + redirect_to admin_edition_path(@document.latest_edition), notice: "Review reminder deleted" + end + private def load_document diff --git a/app/views/admin/review_reminders/_form.html.erb b/app/views/admin/review_reminders/_form.html.erb index fff61166578..97043181d37 100644 --- a/app/views/admin/review_reminders/_form.html.erb +++ b/app/views/admin/review_reminders/_form.html.erb @@ -47,6 +47,9 @@ text: "Save", } %> + <% if Flipflop.delete_review_reminders? && review_reminder.persisted? %> + <%= link_to("Delete", confirm_destroy_admin_document_review_reminder_path(document, review_reminder), class: "govuk-link gem-link--destructive govuk-link--no-visited-state") %> + <% end %> <%= link_to("Cancel", admin_edition_path(@document.latest_edition), class: "govuk-link govuk-link--no-visited-state") %> <% end %> diff --git a/app/views/admin/review_reminders/confirm_destroy.html.erb b/app/views/admin/review_reminders/confirm_destroy.html.erb new file mode 100644 index 00000000000..85a5910b32c --- /dev/null +++ b/app/views/admin/review_reminders/confirm_destroy.html.erb @@ -0,0 +1,21 @@ +<% content_for :page_title, "Delete review reminder for #{@document.latest_edition.title}" %> +<% content_for :title, "Delete review reminder" %> +<% content_for :context, @document.latest_edition.title %> +<% content_for :title_margin_bottom, 8 %> + +
+
+ <%= form_tag admin_document_review_reminder_path(@document, @review_reminder), method: :delete do %> +

Are you sure you want to delete this review reminder?

+ +
+ <%= render "govuk_publishing_components/components/button", { + text: "Delete", + destructive: true, + } %> + + <%= link_to("Cancel", edit_admin_document_review_reminder_path(@document, @review_reminder), class: "govuk-link govuk-link--no-visited-state") %> +
+ <% end %> +
+
diff --git a/config/features.rb b/config/features.rb index 09a5dcaf884..e180a95811b 100644 --- a/config/features.rb +++ b/config/features.rb @@ -21,6 +21,7 @@ # feature :world_domination, # default: true, # description: "Take over the world." + feature :delete_review_reminders, description: "Enables deletion of review reminders", default: false feature :govspeak_visual_editor, description: "Enables a visual editor for Govspeak fields", default: false feature :override_government, description: "Enables GDS Editors and Admins to override the government associated with a document", default: false feature :show_link_to_content_block_manager, description: "Shows link to Content Block Manager from Whitehall editor", default: Whitehall.integration_or_staging? diff --git a/config/routes.rb b/config/routes.rb index f737b5061c5..ec2400c9561 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,7 +77,9 @@ def redirect(path, options = { prefix: Whitehall.router_prefix }) end resources :documents, only: [] do - resources :review_reminders, only: %i[new create edit update] + resources :review_reminders, only: %i[new create edit update destroy] do + get :confirm_destroy, on: :member + end end resources :authors, only: [:show] diff --git a/features/review_reminder.feature b/features/review_reminder.feature index 0f04705a03a..5ef2475a456 100644 --- a/features/review_reminder.feature +++ b/features/review_reminder.feature @@ -23,3 +23,11 @@ Feature: Review reminders When I click the button "Edit review date" on the edition summary page for "Standard Beard Lengths" And I update the review date to "2033-1-1" Then I should see the review date of "1 January 2033" on the edition summary page + + Scenario: Deleting the review date for a published publication + Given a published publication "Standard Beard Lengths" with a PDF attachment + And The delete review reminder feature flag is "enabled" + And a review reminder exists for "Standard Beard Lengths" with the date "2032-1-1" + When I click the button "Edit review date" on the edition summary page for "Standard Beard Lengths" + And I delete the review date + Then I should not see a review date on the edition summary page diff --git a/features/step_definitions/review_reminder_steps.rb b/features/step_definitions/review_reminder_steps.rb index 9738fc2c9d4..9a09e62c0a7 100644 --- a/features/step_definitions/review_reminder_steps.rb +++ b/features/step_definitions/review_reminder_steps.rb @@ -1,3 +1,8 @@ +And(/^The delete review reminder feature flag is "(enabled|disabled)"$/) do |enabled| + @test_strategy ||= Flipflop::FeatureSet.current.test! + @test_strategy.switch!(:delete_review_reminders, enabled == "enabled") +end + And(/^I add a review date of "([^"]*)" and the email address "([^"]*)" on the edit page$/) do |date, email| click_link "Edit draft" check "Set a reminder to review this content after it has been published" @@ -19,6 +24,11 @@ assert_selector ".app-view-summary__section .govuk-summary-list__row:nth-child(5) .govuk-summary-list__value", text: date end +Then(/^I should not see a review date on the edition summary page$/) do + assert_selector ".app-view-summary__section .govuk-summary-list__row:nth-child(5) .govuk-summary-list__key", text: "Review date" + assert_selector ".app-view-summary__section .govuk-summary-list__row:nth-child(5) .govuk-summary-list__value", text: "Not set" +end + When(/^I click the button "([^"]*)" on the edition summary page for "([^"]*)"$/) do |label, title| edition = Edition.find_by!(title:) visit admin_edition_path(edition) @@ -45,3 +55,8 @@ check "Review overdue" click_on "Search" end + +And(/^I delete the review date$/) do + click_link "Delete" + click_button "Delete" +end diff --git a/test/functional/admin/review_reminders_controller_test.rb b/test/functional/admin/review_reminders_controller_test.rb index ed7baa568b7..8e36cacf23a 100644 --- a/test/functional/admin/review_reminders_controller_test.rb +++ b/test/functional/admin/review_reminders_controller_test.rb @@ -103,4 +103,22 @@ class Admin::ReviewRemindersControllerTest < ActionController::TestCase assert_equal assigns(:review_reminder).email_address, "" assert_template :edit end + + test "GET to :confirm_destroy assigns the correct values and renders the correct template" do + review_reminder = create(:review_reminder, document: @document) + + get :confirm_destroy, params: { document_id: @document, id: review_reminder } + + assert_equal assigns(:document), @document + assert_equal assigns(:review_reminder), review_reminder + assert_template :confirm_destroy + end + + test "DELETE to :destroy destroys the review reminder" do + review_reminder = create(:review_reminder, document: @document) + + delete :destroy, params: { document_id: @document, id: review_reminder } + + assert @document.reload.review_reminder.nil? + end end