Browse Source

Add confirm_mandatory_collection_resources_release page

pull/2683/head
Kat 2 years ago
parent
commit
bb3152842d
  1. 10
      app/controllers/collection_resources_controller.rb
  2. 2
      app/helpers/collection_resources_helper.rb
  3. 27
      app/views/collection_resources/confirm_mandatory_collection_resources_release.erb
  4. 3
      config/routes.rb
  5. 60
      spec/requests/collection_resources_controller_spec.rb

10
app/controllers/collection_resources_controller.rb

@ -68,6 +68,16 @@ class CollectionResourcesController < ApplicationController
redirect_to collection_resources_path redirect_to collection_resources_path
end end
def confirm_mandatory_collection_resources_release
return render_not_found unless current_user.support?
@year = params[:year].to_i
return render_not_found unless editable_collection_resource_years.include?(@year)
render "collection_resources/confirm_mandatory_collection_resources_release"
end
private private
def resource_params def resource_params

2
app/helpers/collection_resources_helper.rb

@ -72,7 +72,7 @@ module CollectionResourcesHelper
def display_next_year_banner? def display_next_year_banner?
return false if CollectionResource.where(year: next_collection_start_year, mandatory: true, released_to_user: true).any? return false if CollectionResource.where(year: next_collection_start_year, mandatory: true, released_to_user: true).any?
editable_collection_resource_years.include?(next_collection_start_year) editable_collection_resource_years.include?(next_collection_start_year)
end end

27
app/views/collection_resources/confirm_mandatory_collection_resources_release.erb

@ -0,0 +1,27 @@
<% content_for :before_content do %>
<% content_for :title, "Are you sure you want to release the #{text_year_range_format(@year)} collection resources?" %>
<%= govuk_back_link(href: collection_resources_path) %>
<% end %>
<% binding.pry %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-xl">
<%= content_for(:title) %>
</h1>
<p class="govuk-body">
The files uploaded will immediately become 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(
"Release the resources",
release_mandatory_collection_resources_path(year: @year),
method: :patch,
) %>
<%= govuk_button_link_to "Cancel", collection_resources_path, secondary: true %>
</div>
</div>
</div>

3
config/routes.rb

@ -44,7 +44,8 @@ Rails.application.routes.draw do
get "/collection-resources/:log_type/:year/:resource_type/download", to: "collection_resources#download_mandatory_collection_resource", as: :download_mandatory_collection_resource get "/collection-resources/:log_type/:year/:resource_type/download", to: "collection_resources#download_mandatory_collection_resource", as: :download_mandatory_collection_resource
get "/collection-resources/:log_type/:year/:resource_type/edit", to: "collection_resources#edit", as: :edit_mandatory_collection_resource get "/collection-resources/:log_type/:year/:resource_type/edit", to: "collection_resources#edit", as: :edit_mandatory_collection_resource
patch "/collection-resources", to: "collection_resources#update", as: :update_mandatory_collection_resource patch "/collection-resources", to: "collection_resources#update", as: :update_mandatory_collection_resource
get "/collection-resources/:year/release", to: "collection_resources#release_mandatory_resources", as: :release_mandatory_collection_resources get "/collection-resources/:year/release", to: "collection_resources#confirm_mandatory_collection_resources_release", as: :confirm_mandatory_collection_resources_release
patch "/collection-resources/:year/release", to: "collection_resources#release_mandatory_collection_resources", as: :release_mandatory_collection_resources
resources :collection_resources, path: "/collection-resources" do resources :collection_resources, path: "/collection-resources" do
get "/download", to: "collection_resources#download_additional_collection_resource" # when we get to adding them get "/download", to: "collection_resources#download_additional_collection_resource" # when we get to adding them

60
spec/requests/collection_resources_controller_spec.rb

@ -111,7 +111,7 @@ RSpec.describe CollectionResourcesController, type: :request do
it "displays next year banner" do it "displays next year banner" do
expect(page).to have_content("The 2025 to 2026 collection resources are not yet available to users.") expect(page).to have_content("The 2025 to 2026 collection resources are not yet available to users.")
expect(page).to have_link("Release the 2025 to 2026 collection resources to users", href: release_mandatory_collection_resources_path(year: 2025)) expect(page).to have_link("Release the 2025 to 2026 collection resources to users", href: confirm_mandatory_collection_resources_release(year: 2025))
end end
end end
@ -343,4 +343,62 @@ RSpec.describe CollectionResourcesController, type: :request do
end end
end end
end end
describe "GET #confirm_mandatory_collection_resources_release" do
context "when user is not signed in" do
it "redirects to the sign in page" do
get confirm_mandatory_collection_resources_release_path(year: 2025)
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 confirm_mandatory_collection_resources_release_path(year: 2025)
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 confirm_mandatory_collection_resources_release_path(year: 2025)
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
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of(CollectionResourcesHelper).to receive(:editable_collection_resource_years).and_return([2025])
# rubocop:enable RSpec/AnyInstance
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
end
it "displays correct page content" do
get confirm_mandatory_collection_resources_release_path(year: 2025)
expect(page).to have_content("Are you sure you want to release the 2025 to 2026 collection resources?")
expect(page).to have_content("The files uploaded will immediately become available for users to download.")
expect(page).to have_content("You will not be able to undo this action.")
expect(page).to have_button("Release the resources")
expect(page).to have_link("Cancel", href: collection_resources_path)
expect(page).to have_link("Back", href: collection_resources_path)
end
end
end
end end

Loading…
Cancel
Save