114 changed files with 1536 additions and 427 deletions
@ -0,0 +1,37 @@
|
||||
class CheckErrorsController < ApplicationController |
||||
include DuplicateLogsHelper |
||||
|
||||
before_action :authenticate_user! |
||||
before_action :find_resource_by_named_id |
||||
|
||||
def confirm_clear_answer |
||||
return render_not_found unless @log |
||||
|
||||
@related_question_ids = params[@log.model_name.param_key].keys.reject { |id| id == "page_id" } |
||||
@page = @log.form.get_page(params[@log.model_name.param_key]["page_id"]) |
||||
|
||||
if params["clear_all"] |
||||
@questions_to_clear = @related_question_ids.map { |id| |
||||
question = @log.form.get_question(id, @log) |
||||
next if question.subsection.id == "setup" |
||||
|
||||
question.page.questions.map(&:id) |
||||
}.flatten.compact |
||||
|
||||
render :confirm_clear_all_answers |
||||
else |
||||
question_id = @related_question_ids.find { |id| !params[id].nil? } |
||||
@question = @log.form.get_question(question_id, @log) |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def find_resource_by_named_id |
||||
@log = if params[:sales_log_id].present? |
||||
current_user.sales_logs.visible.find_by(id: params[:sales_log_id]) |
||||
else |
||||
current_user.lettings_logs.visible.find_by(id: params[:lettings_log_id]) |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,11 @@
|
||||
module CheckErrorsHelper |
||||
include GovukLinkHelper |
||||
|
||||
def check_errors_answer_text(question, log) |
||||
question.displayed_as_answered?(log) ? "Change" : "Answer" |
||||
end |
||||
|
||||
def check_errors_answer_link(log, question, page, applicable_questions) |
||||
send("#{log.model_name.param_key}_#{question.page.id}_path", log, referrer: "check_errors", original_page_id: page.id, related_question_ids: applicable_questions.map(&:id)) |
||||
end |
||||
end |
||||
@ -0,0 +1,32 @@
|
||||
<% content_for :before_content do %> |
||||
<% content_for :title, "Are you sure you want to clear all?" %> |
||||
<% end %> |
||||
|
||||
<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">You've selected <%= @questions_to_clear.count %> answers to clear</p> |
||||
|
||||
<%= govuk_warning_text(text: "Dependent answers related to this question may also get cleared. You will not be able to undo this action") %> |
||||
<%= form_with model: @log, url: send("#{@log.model_name.param_key}_#{@page.id}_path", @log), method: "post", local: true do |f| %> |
||||
|
||||
<% @related_question_ids.each do |id| %> |
||||
<%= f.hidden_field id, value: @log[id] %> |
||||
<% end %> |
||||
|
||||
<%= f.hidden_field :clear_question_ids, value: @questions_to_clear %> |
||||
<%= f.hidden_field :page, value: @page.id %> |
||||
|
||||
<div class="govuk-button-group"> |
||||
<%= f.govuk_submit "Confirm and continue", name: "check_errors" %> |
||||
<%= govuk_button_link_to( |
||||
"Cancel", |
||||
"javascript:history.back()", |
||||
secondary: true, |
||||
) %> |
||||
</div> |
||||
<% end %> |
||||
</div> |
||||
</div> |
||||
@ -0,0 +1,31 @@
|
||||
<% content_for :before_content do %> |
||||
<% content_for :title, "Are you sure you want to clear #{@question.check_answer_label}?" %> |
||||
<% end %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||
<h1 class="govuk-heading-xl"> |
||||
<%= content_for(:title) %> |
||||
</h1> |
||||
|
||||
<%= govuk_warning_text(text: "Dependent answers related to this question may also get cleared. You will not be able to undo this action.") %> |
||||
<%= form_with model: @log, url: send("#{@log.model_name.param_key}_#{@page.id}_path", @log), method: "post", local: true do |f| %> |
||||
|
||||
<% @related_question_ids.each do |id| %> |
||||
<%= f.hidden_field id, value: @log[id] %> |
||||
<% end %> |
||||
|
||||
<%= f.hidden_field :clear_question_ids, value: [@question.id] %> |
||||
<%= f.hidden_field :page, value: @page.id %> |
||||
|
||||
<div class="govuk-button-group"> |
||||
<%= f.govuk_submit "Confirm and continue", name: "check_errors" %> |
||||
<%= govuk_button_link_to( |
||||
"Cancel", |
||||
"javascript:history.back()", |
||||
secondary: true, |
||||
) %> |
||||
</div> |
||||
<% end %> |
||||
</div> |
||||
</div> |
||||
@ -0,0 +1,66 @@
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-three-quarters-from-desktop"> |
||||
|
||||
<%= form_with model: @log, url: send("#{@log.model_name.param_key}_confirm_clear_answer_path", @log), method: "post", local: true do |f| %> |
||||
<%= f.govuk_error_summary %> |
||||
<%= f.hidden_field :page_id, value: @page.id %> |
||||
|
||||
<h1 class="govuk-heading-m"> |
||||
<div class="govuk-grid-row"> |
||||
<span class="govuk-grid-column-two-thirds"> |
||||
Make sure these answers are correct: |
||||
</span> |
||||
<span class="govuk-body govuk-!-text-align-right govuk-grid-column-one-third"> |
||||
<input type="submit" value="Clear all" class="govuk-body govuk-link submit-button-link" name="clear_all"> |
||||
</span> |
||||
</div> |
||||
</h1> |
||||
|
||||
<div class="govuk-summary-card"> |
||||
<div class="govuk-summary-card__content"> |
||||
<% applicable_questions = @questions.reject { |q| q.hidden_in_check_answers?(@log, current_user) } %> |
||||
<dl class="govuk-summary-list"> |
||||
<% applicable_questions.each do |question| %> |
||||
<%= f.hidden_field question.id, value: @log[question.id] %> |
||||
<div class="govuk-summary-list__row"> |
||||
<dt class="govuk-summary-list__key"> |
||||
<%= get_question_label(question) %> |
||||
</dt> |
||||
<dd class="govuk-summary-list__value"> |
||||
<%= simple_format( |
||||
get_answer_label(question, @log), |
||||
wrapper_tag: "span", |
||||
class: "govuk-!-margin-right-4", |
||||
) %> |
||||
|
||||
<% extra_value = question.get_extra_check_answer_value(@log) %> |
||||
|
||||
<% if extra_value && question.answer_label(@log).present? %> |
||||
<%= simple_format( |
||||
extra_value, |
||||
wrapper_tag: "span", |
||||
class: "govuk-!-font-weight-regular app-!-colour-muted", |
||||
) %> |
||||
<% end %> |
||||
|
||||
<% question.get_inferred_answers(@log).each do |inferred_answer| %> |
||||
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span> |
||||
<% end %> |
||||
</dd> |
||||
<dd class="govuk-summary-list__actions"> |
||||
<% if !question.displayed_as_answered?(@log) || question.subsection.id == "setup" %> |
||||
<%= govuk_link_to check_errors_answer_text(question, @log), check_errors_answer_link(@log, question, @page, applicable_questions) %> |
||||
<% else %> |
||||
<input type="submit" value="Clear" class="govuk-body govuk-link submit-button-link" name="<%= question.id %>"> |
||||
<% end %> |
||||
</dd> |
||||
</div> |
||||
<% end %> |
||||
</dl> |
||||
</div> |
||||
</div> |
||||
<% end %> |
||||
|
||||
<%= govuk_button_link_to "Confirm and continue", @original_page_id ? send("#{@log.model_name.param_key}_#{@original_page_id}_path", @log) : send("#{@log.model_name.param_key}_#{@page.id}_path", @log) %> |
||||
</div> |
||||
</div> |
||||
@ -1 +1 @@
|
||||
<p class="govuk-body">Make sure the buyer has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p> |
||||
<p class="govuk-body">Make sure the buyer has seen <%= govuk_link_to "the Ministry of Housing, Communities and Local Government (MHCLG) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p> |
||||
|
||||
@ -1 +1 @@
|
||||
<p class="govuk-body">Make sure the buyer has seen or been given access to <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log. This is a legal requirement under data protection legislation.</p> |
||||
<p class="govuk-body">Make sure the buyer has seen or been given access to <%= govuk_link_to "the Ministry of Housing, Communities and Local Government (MHCLG) privacy notice", privacy_notice_path, target: :_blank %> before completing this log. This is a legal requirement under data protection legislation.</p> |
||||
|
||||
@ -1 +1 @@
|
||||
<p class="govuk-body">Make sure the buyers have seen or been given access to <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log. This is a legal requirement under data protection legislation.</p> |
||||
<p class="govuk-body">Make sure the buyers have seen or been given access to <%= govuk_link_to "the Ministry of Housing, Communities and Local Government (MHCLG) privacy notice", privacy_notice_path, target: :_blank %> before completing this log. This is a legal requirement under data protection legislation.</p> |
||||
|
||||
@ -1 +1 @@
|
||||
<p class="govuk-body">Make sure the buyers have seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p> |
||||
<p class="govuk-body">Make sure the buyers have seen <%= govuk_link_to "the Ministry of Housing, Communities and Local Government (MHCLG) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p> |
||||
|
||||
@ -1 +1 @@
|
||||
<p class="govuk-body">Make sure the tenant has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p> |
||||
<p class="govuk-body">Make sure the tenant has seen <%= govuk_link_to "the Ministry of Housing, Communities and Local Government (MHCLG) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p> |
||||
|
||||
@ -1 +1 @@
|
||||
<p class="govuk-body">Make sure the lead tenant has seen or been given access to <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log. This is a legal requirement under data protection legislation.</p> |
||||
<p class="govuk-body">Make sure the lead tenant has seen or been given access to <%= govuk_link_to "the Ministry of Housing, Communities and Local Government (MHCLG) privacy notice", privacy_notice_path, target: :_blank %> before completing this log. This is a legal requirement under data protection legislation.</p> |
||||
|
||||
@ -0,0 +1,5 @@
|
||||
class AddRentFixStatus < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :bulk_uploads, :rent_type_fix_status, :string, default: "not_applied" |
||||
end |
||||
end |
||||
@ -0,0 +1,5 @@
|
||||
class RemoveNointFixStatus < ActiveRecord::Migration[7.0] |
||||
def change |
||||
remove_column :bulk_uploads, :noint_fix_status, :string, default: "not_applied" |
||||
end |
||||
end |
||||
@ -1,24 +0,0 @@
|
||||
desc "Alter noint values for bulk uploaded sales logs where these have not been set in the service" |
||||
task correct_noint_value: :environment do |
||||
update_counts = { |
||||
in_progress: 0, |
||||
completed: 0, |
||||
pending: 0, |
||||
deleted: 0, |
||||
} |
||||
affected_uploads = BulkUpload.where(log_type: "sales", noint_fix_status: BulkUpload.noint_fix_statuses[:not_applied]) |
||||
affected_uploads.each do |upload| |
||||
upload.logs.where(noint: 2).each do |log| |
||||
noint_at_upload = log.versions.length == 1 ? log.noint : log.versions.first.next.reify.noint |
||||
next unless noint_at_upload == 2 |
||||
|
||||
Rails.logger.info("Updating noint value on log #{log.id}, owning org #{log.owning_organisation_id}") |
||||
update_counts[log.status.to_sym] += 1 |
||||
log.noint = 1 |
||||
log.skip_update_status = true |
||||
log.save! |
||||
end |
||||
upload.update!(noint_fix_status: BulkUpload.noint_fix_statuses[:applied]) |
||||
end |
||||
Rails.logger.info("Logs updated; #{update_counts}") |
||||
end |
||||
@ -0,0 +1,21 @@
|
||||
desc "Alter rent_type values for bulk uploaded lettings logs for 2024 where they were not mapped correctly" |
||||
task correct_rent_type_value: :environment do |
||||
affected_uploads = BulkUpload.where(log_type: "lettings", year: 2024, rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_applied]) |
||||
affected_uploads.each do |upload| |
||||
upload.logs.where.not(rent_type: nil).each do |log| |
||||
current_rent_type = log.rent_type |
||||
rent_type_at_upload = log.versions.length == 1 ? log.rent_type : log.versions.first.next.reify.rent_type |
||||
next unless rent_type_at_upload == current_rent_type |
||||
|
||||
new_rent_type_value = BulkUpload::Lettings::Year2024::RowParser::RENT_TYPE_BU_MAPPING[rent_type_at_upload] |
||||
log.rent_type = new_rent_type_value |
||||
log.skip_update_status = true if log.status == "pending" |
||||
if log.save |
||||
Rails.logger.info("Log #{log.id} rent_type updated from #{rent_type_at_upload} to #{log.rent_type}") |
||||
else |
||||
Rails.logger.error("Log #{log.id} rent_type could not be updated from #{rent_type_at_upload} to #{log.rent_type}. Error: #{log.errors.full_messages.join(', ')}") |
||||
end |
||||
end |
||||
upload.update!(rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:applied]) |
||||
end |
||||
end |
||||
@ -1,9 +0,0 @@
|
||||
FactoryBot.define do |
||||
factory :admin_user do |
||||
sequence(:email) { |i| "admin#{i}@example.com" } |
||||
password { "pAssword1" } |
||||
phone { "07563867654" } |
||||
created_at { Time.zone.now } |
||||
updated_at { Time.zone.now } |
||||
end |
||||
end |
||||
|
|
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
Can't render this file because it contains an unexpected character in line 3 and column 219.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1,87 +0,0 @@
|
||||
require "rails_helper" |
||||
require "rake" |
||||
|
||||
RSpec.describe "correct_noint_value" do |
||||
describe ":correct_noint_value", type: :task do |
||||
subject(:task) { Rake::Task["correct_noint_value"] } |
||||
|
||||
before do |
||||
Rake.application.rake_require("tasks/correct_noint_value") |
||||
Rake::Task.define_task(:environment) |
||||
task.reenable |
||||
end |
||||
|
||||
context "when the rake task is run" do |
||||
context "and there is a sales bulk upload with the fix needed" do |
||||
let(:bulk_upload) { create(:bulk_upload, :sales, noint_fix_status: BulkUpload.noint_fix_statuses[:not_applied]) } |
||||
|
||||
before do |
||||
bulk_upload.save! |
||||
end |
||||
|
||||
it "updates the noint value on a log with noint = 2 where it was set to 2 on create" do |
||||
log = create(:sales_log, :completed, noint: 2, bulk_upload:) |
||||
|
||||
task.invoke |
||||
log.reload |
||||
|
||||
expect(log.noint).to be(1) |
||||
end |
||||
|
||||
it "updates the noint value on a log with noint = 2 where it was set to 2 on create and other fields have since changed" do |
||||
log = create(:sales_log, :in_progress, noint: 2, bulk_upload:) |
||||
log.update!(status: Log.statuses[:completed]) |
||||
|
||||
task.invoke |
||||
log.reload |
||||
|
||||
expect(log.noint).to be(1) |
||||
end |
||||
|
||||
it "does not update the noint value on a log that has noint = 1" do |
||||
log = create(:sales_log, :completed, noint: 2, bulk_upload:) |
||||
log.update!(noint: 1) |
||||
|
||||
task.invoke |
||||
log.reload |
||||
|
||||
expect(log.noint).to be(1) |
||||
end |
||||
|
||||
it "does not update the noint value on a log with noint = 2 where noint was nil on create" do |
||||
log = create(:sales_log, :completed, noint: nil, bulk_upload:) |
||||
log.update!(noint: 2) |
||||
|
||||
task.invoke |
||||
log.reload |
||||
|
||||
expect(log.noint).to be(2) |
||||
end |
||||
|
||||
it "updates the noint_fix_status value on the bulk upload" do |
||||
task.invoke |
||||
bulk_upload.reload |
||||
|
||||
expect(bulk_upload.noint_fix_status).to eq(BulkUpload.noint_fix_statuses[:applied]) |
||||
end |
||||
end |
||||
|
||||
context "and there is a sales bulk upload with the fix marked as not needed" do |
||||
let(:bulk_upload) { create(:bulk_upload, :sales, noint_fix_status: BulkUpload.noint_fix_statuses[:not_needed]) } |
||||
|
||||
before do |
||||
bulk_upload.save! |
||||
end |
||||
|
||||
it "does not update the noint values on logs" do |
||||
log = create(:sales_log, :completed, noint: 2, bulk_upload:) |
||||
|
||||
task.invoke |
||||
log.reload |
||||
|
||||
expect(log.noint).to be(2) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue