Browse Source

Add delete confirmation page

pull/2693/head
Kat 2 years ago committed by Kat
parent
commit
440c5325fb
  1. 10
      app/controllers/collection_resources_controller.rb
  2. 2
      app/views/collection_resources/_collection_resource_summary_list.erb
  3. 31
      app/views/collection_resources/delete_confirmation.html.erb
  4. 1
      config/routes.rb
  5. 63
      spec/requests/collection_resources_controller_spec.rb

10
app/controllers/collection_resources_controller.rb

@ -184,6 +184,16 @@ class CollectionResourcesController < ApplicationController
end end
end end
def delete_confirmation
return render_not_found unless current_user.support?
@collection_resource = CollectionResource.find_by(id: params[:collection_resource_id])
return render_not_found unless @collection_resource
render "collection_resources/delete_confirmation"
end
private private
def resource_params def resource_params

2
app/views/collection_resources/_collection_resource_summary_list.erb

@ -35,7 +35,7 @@
) %> ) %>
<% row.with_action( <% row.with_action(
text: "Delete", text: "Delete",
href: "/", href: collection_resource_delete_confirmation_path(resource),
classes: "app-!-colour-red" classes: "app-!-colour-red"
) %> ) %>
<% end %> <% end %>

31
app/views/collection_resources/delete_confirmation.html.erb

@ -0,0 +1,31 @@
<% content_for :before_content do %>
<% content_for :title, "Are you sure you want to delete the #{@collection_resource.short_display_name.downcase}?" %>
<%= govuk_back_link href: collection_resources_path %>
<% end %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<span class="govuk-caption-l"><%= "#{@collection_resource.log_type.humanize} #{text_year_range_format(@collection_resource.year)}" %></span>
<h1 class="govuk-heading-xl">
<%= content_for(:title) %>
</h1>
<p class="govuk-body app-!-colour-muted">
This file will no longer be available for users to download.
</p>
<%= govuk_warning_text(text: "You will not be able to undo this action.") %>
<div class="govuk-button-group">
<%= govuk_button_to(
"Delete resource",
"/",
method: :delete,
) %>
<%= govuk_button_link_to(
"Cancel",
collection_resources_path,
secondary: true,
) %>
</div>
</div>
</div>

1
config/routes.rb

@ -51,6 +51,7 @@ Rails.application.routes.draw do
get "/download", to: "collection_resources#download_additional_collection_resource" get "/download", to: "collection_resources#download_additional_collection_resource"
get "/edit", to: "collection_resources#edit_additional_collection_resource" get "/edit", to: "collection_resources#edit_additional_collection_resource"
patch "/update", to: "collection_resources#update_additional_collection_resource" patch "/update", to: "collection_resources#update_additional_collection_resource"
get "/delete-confirmation", to: "collection_resources#delete_confirmation"
end end
get "clear-filters", to: "sessions#clear_filters" get "clear-filters", to: "sessions#clear_filters"

63
spec/requests/collection_resources_controller_spec.rb

@ -183,7 +183,7 @@ RSpec.describe CollectionResourcesController, type: :request do
expect(page).to have_content("additional resource") expect(page).to have_content("additional resource")
expect(page).not_to have_content("additional resource 2") expect(page).not_to have_content("additional resource 2")
expect(page).to have_link("additional.pdf", href: collection_resource_download_path(collection_resource)) expect(page).to have_link("additional.pdf", href: collection_resource_download_path(collection_resource))
expect(page).to have_link("Delete") expect(page).to have_link("Delete", href: collection_resource_delete_confirmation_path(collection_resource))
end end
end end
end end
@ -813,4 +813,65 @@ RSpec.describe CollectionResourcesController, type: :request do
end end
end end
end end
describe "GET #collection_resource_delete_confirmation" do
let(:collection_resource) { create(:collection_resource, :additional, year: 2025, log_type: "sales", short_display_name: "additional resource", download_filename: "additional.pdf") }
context "when user is not signed in" do
it "redirects to the sign in page" do
get collection_resource_delete_confirmation_path(collection_resource)
expect(response).to redirect_to(new_user_session_path)
end
end
context "when user is signed in as a data coordinator" do
let(:user) { create(:user, :data_coordinator) }
before do
sign_in user
end
it "returns page not found" do
get collection_resource_delete_confirmation_path(collection_resource)
expect(response).to have_http_status(:not_found)
end
end
context "when user is signed in as a data provider" do
let(:user) { create(:user, :data_provider) }
before do
sign_in user
end
it "returns page not found" do
get collection_resource_delete_confirmation_path(collection_resource)
expect(response).to have_http_status(:not_found)
end
end
context "when user is signed in as a support user" do
let(:user) { create(:user, :support) }
before do
allow(Time.zone).to receive(:today).and_return(Time.zone.local(2025, 1, 8))
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
end
context "and the file exists on S3" do
it "displays delete confirmation page content" do
get collection_resource_delete_confirmation_path(collection_resource)
expect(page).to have_content("Sales 2025 to 2026")
expect(page).to have_content("Are you sure you want to delete the additional resource?")
expect(page).to have_content("This file will no longer be available for users to download.")
expect(page).to have_content("You will not be able to undo this action.")
expect(page).to have_button("Delete resource")
expect(page).to have_link("Back", href: collection_resources_path)
expect(page).to have_link("Cancel", href: collection_resources_path)
end
end
end
end
end end

Loading…
Cancel
Save