diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb index cc13532b8..9b0c67872 100644 --- a/app/components/check_answers_summary_list_card_component.html.erb +++ b/app/components/check_answers_summary_list_card_component.html.erb @@ -25,7 +25,7 @@ <%= inferred_answer %> <% end %> <% end %> - <% if @log.form.end_date > Time.zone.today %> + <% if @log.collection_period_open? %> <% row.action( text: question.action_text(log), href: question.action_href(log, question.page.id), diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 6e71de6c6..a529ef6e7 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -50,7 +50,7 @@ class FormController < ApplicationController page_id = request.path.split("/")[-1].underscore @page = @log.form.get_page(page_id) @subsection = @log.form.subsection_for_page(@page) - if @page.routed_to?(@log, current_user) + if @page.routed_to?(@log, current_user) && @log.collection_period_open? render "form/page" else redirect_to lettings_log_path(@log) diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index bb75fcfff..fe842c7d7 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -38,7 +38,7 @@ module TasklistHelper end def review_log_text(log) - if log.form.end_date > Time.zone.today + if log.collection_period_open? "You can #{govuk_link_to 'review and make changes to this log', "/lettings-logs/#{log.id}/review"} until #{(log.form.end_date + 1.day).to_formatted_s(:govuk_date)}.".html_safe else "This log is from the #{log.form.start_date.year}/#{log.form.start_date.year + 1} collection window, which is now closed." diff --git a/app/models/log.rb b/app/models/log.rb index abde757e5..68e50c78c 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -44,6 +44,10 @@ class Log < ApplicationRecord managing_organisation&.provider_type end + def collection_period_open? + form.end_date > Time.zone.today + end + private def update_status! diff --git a/app/views/form/_check_answers_summary_list.html.erb b/app/views/form/_check_answers_summary_list.html.erb index a03569084..56ae87905 100644 --- a/app/views/form/_check_answers_summary_list.html.erb +++ b/app/views/form/_check_answers_summary_list.html.erb @@ -13,7 +13,7 @@ <%= inferred_answer %> <% end %> <% end %> - <% if @log.form.end_date > Time.zone.today %> + <% if @log.collection_period_open? %> <% row.action( text: question.action_text(@log), href: question.action_href(@log, question.page.id), diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 2a79254fc..f605d065a 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -782,6 +782,11 @@ RSpec.describe LettingsLogsController, type: :request do expect(page).not_to have_link("Change") expect(page).not_to have_link("Answer") end + + it "does not let the user navigate to questions for previous collection year logs" do + get "/lettings-logs/#{completed_lettings_log.id}/needs-type", headers: { "Accept" => "text/html" }, params: {} + expect(response).to redirect_to("/lettings-logs/#{completed_lettings_log.id}") + end end context "when requesting CSV download" do