diff --git a/app/controllers/collection_resources_controller.rb b/app/controllers/collection_resources_controller.rb index f1fd6de07..e8e25487d 100644 --- a/app/controllers/collection_resources_controller.rb +++ b/app/controllers/collection_resources_controller.rb @@ -68,6 +68,16 @@ class CollectionResourcesController < ApplicationController redirect_to collection_resources_path 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 def resource_params diff --git a/app/helpers/collection_resources_helper.rb b/app/helpers/collection_resources_helper.rb index b5aec1405..9deb13887 100644 --- a/app/helpers/collection_resources_helper.rb +++ b/app/helpers/collection_resources_helper.rb @@ -72,7 +72,7 @@ module CollectionResourcesHelper def display_next_year_banner? 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) end diff --git a/app/views/collection_resources/confirm_mandatory_collection_resources_release.erb b/app/views/collection_resources/confirm_mandatory_collection_resources_release.erb new file mode 100644 index 000000000..e5da8d58a --- /dev/null +++ b/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 %> +
+
+

+ <%= content_for(:title) %> +

+ +

+ The files uploaded will immediately become available for users to download. +

+ + <%= govuk_warning_text(text: "You will not be able to undo this action.") %> + +
+ <%= 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 %> +
+
+
diff --git a/config/routes.rb b/config/routes.rb index c8e1c40f5..db4b2a8a2 100644 --- a/config/routes.rb +++ b/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/edit", to: "collection_resources#edit", as: :edit_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 get "/download", to: "collection_resources#download_additional_collection_resource" # when we get to adding them diff --git a/spec/requests/collection_resources_controller_spec.rb b/spec/requests/collection_resources_controller_spec.rb index 93b6755d6..dbc48d28d 100644 --- a/spec/requests/collection_resources_controller_spec.rb +++ b/spec/requests/collection_resources_controller_spec.rb @@ -111,7 +111,7 @@ RSpec.describe CollectionResourcesController, type: :request 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_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 @@ -343,4 +343,62 @@ RSpec.describe CollectionResourcesController, type: :request do 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