diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb
index eaec5a604..4b2965aee 100644
--- a/app/controllers/lettings_logs_controller.rb
+++ b/app/controllers/lettings_logs_controller.rb
@@ -13,6 +13,7 @@ class LettingsLogsController < LogsController
@pagy, @logs = pagy(unpaginated_filtered_logs)
@searched = search_term.presence
@total_count = all_logs.size
+ @logs_to_update = LettingsLog.where(created_by: current_user, impacted_by_scheme_deactivation: true).count
render "logs/index"
end
end
diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb
index 415db5c7a..f38119e79 100644
--- a/app/controllers/schemes_controller.rb
+++ b/app/controllers/schemes_controller.rb
@@ -344,6 +344,7 @@ private
end
def reset_location_and_scheme_for_logs!
- @scheme.lettings_logs.filter_by_before_startdate(params[:deactivation_date].to_time).update!(location: nil, scheme: nil)
+ @scheme.lettings_logs.filter_by_before_startdate(params[:deactivation_date].to_time).update!(location: nil, scheme: nil, impacted_by_scheme_deactivation: true)
+ # TODO: E-mail users
end
end
diff --git a/app/controllers/update_logs_controller.rb b/app/controllers/update_logs_controller.rb
new file mode 100644
index 000000000..9de4a250c
--- /dev/null
+++ b/app/controllers/update_logs_controller.rb
@@ -0,0 +1,8 @@
+class UpdateLogsController < ApplicationController
+ before_action :authenticate_user!
+
+ def show
+ @logs = LettingsLog.where(created_by: current_user, impacted_by_scheme_deactivation: true)
+ render "logs/update_logs"
+ end
+end
diff --git a/app/views/logs/index.html.erb b/app/views/logs/index.html.erb
index 431ca0f45..9c5acc904 100644
--- a/app/views/logs/index.html.erb
+++ b/app/views/logs/index.html.erb
@@ -4,6 +4,18 @@
<% content_for :title, title %>
<% if current_page?(controller: 'lettings_logs', action: 'index') %>
+ <% if @logs_to_update > 0 %>
+ <%= govuk_notification_banner(
+ title_text: "Important",
+ title_heading_level: 3,
+ title_id: "impacted-logs-banner",
+ ) do |notification_banner| %>
+ <% notification_banner.heading(text: "A scheme has changed and it has affected #{@logs_to_update} #{@logs_to_update > 1 ? 'logs' : 'log'}") %>
+
+ <% end %>
+ <% end %>
<%= render partial: "organisations/headings", locals: current_user.support? ? { main: "Lettings logs", sub: nil } : { main: "Lettings logs", sub: current_user.organisation.name } %>
<% elsif current_page?(controller: 'sales_logs', action: 'index') %>
<%= render partial: "organisations/headings", locals: current_user.support? ? { main: "Sales logs", sub: nil } : { main: "Sales logs", sub: current_user.organisation.name } %>
diff --git a/app/views/logs/update_logs.html.erb b/app/views/logs/update_logs.html.erb
new file mode 100644
index 000000000..738e03505
--- /dev/null
+++ b/app/views/logs/update_logs.html.erb
@@ -0,0 +1,38 @@
+<% content_for :title, "Update logs" %>
+
+
+
You need to update <%= @logs.count %> logs
+
+
+ Some scheme details have changed, and now the following <%= @logs.count %> logs need updating.
+
+
+ You'll have to answer a few questions for each log.
+
+
+
+
+ <%= govuk_table do |table|
+ table.head do |head|
+ head.row do |row|
+ row.cell(header: true, text: "Log ID")
+ row.cell(header: true, text: "Tenancy code")
+ row.cell(header: true, text: "Property reference")
+ row.cell(header: true, text: "Status")
+ row.cell # "Update now" column has no heading
+ end
+ end
+
+ table.body do |body|
+ @logs.each do |log|
+ body.row do |row|
+ row.cell(header: true, text: log.id)
+ row.cell(text: log.tenancycode)
+ row.cell(text: log.propcode)
+ row.cell { status_tag(log.status) }
+ row.cell(numeric: true) { govuk_link_to("Update now", "#") } # "numeric" to right-align
+ end
+ end
+ end
+ end %>
+
diff --git a/config/routes.rb b/config/routes.rb
index ce005902f..3b6faf816 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -111,6 +111,7 @@ Rails.application.routes.draw do
get "csv-download", to: "lettings_logs#download_csv"
post "email-csv", to: "lettings_logs#email_csv"
get "csv-confirmation", to: "lettings_logs#csv_confirmation"
+ get "update-logs", to: "update_logs#show"
end
member do
diff --git a/db/migrate/20221124171430_add_impacted_by_scheme_deactivation.rb b/db/migrate/20221124171430_add_impacted_by_scheme_deactivation.rb
new file mode 100644
index 000000000..1ab25749a
--- /dev/null
+++ b/db/migrate/20221124171430_add_impacted_by_scheme_deactivation.rb
@@ -0,0 +1,13 @@
+class AddImpactedBySchemeDeactivation < ActiveRecord::Migration[7.0]
+ def up
+ change_table :lettings_logs, bulk: true do |t|
+ t.column :impacted_by_scheme_deactivation, :boolean
+ end
+ end
+
+ def down
+ change_table :lettings_logs, bulk: true do |t|
+ t.remove :impacted_by_scheme_deactivation
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 9df577686..a7de2404e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
+ActiveRecord::Schema[7.0].define(version: 2022_11_24_171430) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -237,6 +237,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "void_date_value_check"
t.integer "housingneeds_type"
t.integer "housingneeds_other"
+ t.boolean "impacted_by_scheme_deactivation"
t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id"
t.index ["location_id"], name: "index_lettings_logs_on_location_id"
t.index ["managing_organisation_id"], name: "index_lettings_logs_on_managing_organisation_id"
@@ -345,12 +346,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "jointmore"
t.integer "jointpur"
t.integer "beds"
- t.integer "companybuy"
t.integer "age1"
t.integer "age1_known"
+ t.integer "companybuy"
t.string "sex1"
- t.integer "national"
- t.string "othernational"
t.integer "ethnic"
t.integer "ethnic_group"
t.integer "buy1livein"
@@ -364,8 +363,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "noint"
t.integer "buy2livein"
t.integer "ecstat2"
- t.integer "privacynotice"
t.integer "ecstat1"
+ t.integer "national"
+ t.string "othernational"
+ t.integer "privacynotice"
t.integer "wheel"
t.integer "hholdcount"
t.integer "age3"
@@ -374,15 +375,15 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "la_known"
t.integer "income1"
t.integer "income1nk"
- t.integer "details_known_2"
- t.integer "details_known_3"
- t.integer "details_known_4"
t.integer "age4"
t.integer "age4_known"
t.integer "age5"
t.integer "age5_known"
t.integer "age6"
t.integer "age6_known"
+ t.integer "details_known_2"
+ t.integer "details_known_3"
+ t.integer "details_known_4"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"
diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb
index 6d09b205a..06ae7eea0 100644
--- a/spec/features/lettings_log_spec.rb
+++ b/spec/features/lettings_log_spec.rb
@@ -134,4 +134,34 @@ RSpec.describe "Lettings Log Features" do
end
end
end
+
+ context "when logs the user created have been affected by a scheme deactivation" do
+ let(:user) { create(:user, last_sign_in_at: Time.zone.now) }
+ let!(:my_impacted_logs) do
+ [
+ create(:lettings_log, created_by: user, impacted_by_scheme_deactivation: true),
+ create(:lettings_log, created_by: user, impacted_by_scheme_deactivation: true),
+ ]
+ end
+
+ before do
+ # Non-impacted log
+ create(:lettings_log, created_by: user)
+ # Impacted log for a different user user
+ create(:lettings_log, impacted_by_scheme_deactivation: true)
+
+ visit("/lettings-logs")
+ fill_in("user[email]", with: user.email)
+ fill_in("user[password]", with: user.password)
+ click_button("Sign in")
+ end
+
+ it "displays a banner" do
+ expect(page).to have_content("A scheme has changed")
+ end
+
+ it "displays the count of affected logs" do
+ expect(page).to have_content("it has affected #{my_impacted_logs.count} logs")
+ end
+ end
end