Browse Source

update emails

pull/1953/head
Kat 3 years ago
parent
commit
c62c97ee54
  1. 59
      app/mailers/csv_download_mailer.rb
  2. 15
      lib/tasks/send_missing_addresses_csv.rake
  3. 4
      spec/lib/tasks/send_missing_addresses_csv_spec.rb
  4. 19
      spec/mailers/csv_download_mailer_spec.rb

59
app/mailers/csv_download_mailer.rb

@ -29,27 +29,58 @@ class CsvDownloadMailer < NotifyMailer
private private
def issue_explanation(issue_types) HELPDESK_URL = "https://dluhcdigital.atlassian.net/servicedesk/customer/portal/6/group/11".freeze
issue_type_explanations = {
"missing_address" => "- Full address required: The UPRN in some logs is incorrect, so address data was not imported.\n",
"missing_town" => "- Missing town or city: The town or city in some logs is missing. This data is required in the new version of CORE.\n",
"wrong_uprn" => "- UPRN may be incorrect: The UPRN in some logs may be incorrect, so wrong address data was imported. We think this is an issue because in some logs the UPRN is the same as the tenant code or property reference, and because your organisation has submitted logs for properties in Bristol for the first time.\n",
}
"Some address data is missing or incorrect. We've detected the following issues in your logs imported to the new version of CORE:\n\n#{issue_types.map { |issue_type| issue_type_explanations[issue_type] }.join('')}" def issue_explanation(issue_types)
[
"We have found #{multiple_issue_types?(issue_types) ? 'these issues' : 'this issue'} in your logs imported to the new version of CORE:\n",
issue_types.include?("missing_address") ? "## Full address required\nThe Unique Property Reference number (UPRN) in some logs is incorrect, so the address data was not imported. Provide the full address and leave the UPRN column blank.\n" : "",
issue_types.include?("missing_town") ? "## Missing town or city\nThe town or city in some logs is missing. This data is required in the new version of CORE.\n" : "",
has_uprn_issues(issue_types) ? uprn_issue_explanation(issue_types) : "",
].join("")
end end
def how_to_fix(issue_types, link, log_type) def how_to_fix(issue_types, link, log_type)
[ [
"You need to:\n\n", "You need to:\n\n",
"- download [this spreadsheet for #{log_type} logs](#{link})\n", "- download [this spreadsheet for #{log_type} logs](#{link}). This link will expire in one week. To request another link, [contact the CORE helpdesk](#{HELPDESK_URL}).\n",
issue_types.include?("missing_address") || issue_types.include?("missing_town") ? "- fill in the missing address data\n" : "", issue_types.include?("missing_address") || issue_types.include?("missing_town") ? "- fill in the missing address data\n" : "",
if issue_types == %w[wrong_uprn] uprn_issues_only(issue_types) ? "- check that the address data is correct\n" : "- check that the existing address data is correct\n",
"- check the address data\n" has_uprn_issues(issue_types) ? "- correct any address errors\n" : "",
else
!issue_types.include?("wrong_uprn") ? "- check that the existing address data is correct\n" : "- check the existing address data\n"
end,
issue_types.include?("wrong_uprn") ? "- correct any errors\n" : "",
].join("") ].join("")
end end
def uprn_issues_only(issue_types)
issue_types == %w[wrong_uprn] || issue_types == %w[bristol_uprn] || issue_types.count == 2 && issue_types.include?("wrong_uprn") && issue_types.include?("bristol_uprn")
end
def has_uprn_issues(issue_types)
issue_types.include?("wrong_uprn") || issue_types.include?("bristol_uprn")
end
def multiple_issue_types?(issue_types)
issue_types.count > 1 && !uprn_issues_only(issue_types) || issue_types.count > 2
end
def uprn_issue_explanation(issue_types)
if issue_types.include?("wrong_uprn") && !issue_types.include?("bristol_uprn")
"## Incorrect UPRN\nThe UPRN in some logs may be incorrect, so the wrong address data may have been imported.
In some of your logs, the UPRN is the same as the tenant code or property reference, but these are different things. Property references are codes that yourorganisation uses to identify properties. UPRNs are unique numbers assigned by the Ordnance Survey.
If a log has the correct UPRN, leave the UPRN unchanged. If the UPRN is incorrect, clear the value and provide the full address instead. Alternatively, you can change the UPRN on the CORE system.\n"
elsif issue_types.include?("bristol_uprn") && !issue_types.include?("wrong_uprn")
"## Incorrect UPRN\nThe UPRN in some logs may be incorrect, so the wrong address data may have been imported. In some of your logs, the UPRN links to an address in Bristol, but this is the first time your organisation has submitted logs for properties in Bristol.
If a log has the correct UPRN, leave the UPRN unchanged. If the UPRN is incorrect, clear the value and provide the full address instead. Alternatively, you can change the UPRN on the CORE system.\n"
else
"## Incorrect UPRN\nThe UPRN in some logs may be incorrect, so the wrong address data may have been imported. We think this is an issue for two reasons.
In some of your logs, the UPRN links to an address in Bristol, but this is the first time your organisation has submitted logs for properties in Bristol.
In other logs, the UPRN is the same as the tenant code or property reference, but these are different things. Property references are codes that your organisation uses to identify properties. UPRNs are unique numbers assigned by the Ordnance Survey.
If a log has the correct UPRN, leave the UPRN unchanged. If the UPRN is incorrect, clear the value and provide the full address instead. Alternatively, you can change the UPRN on the CORE system."
end
end
end end

15
lib/tasks/send_missing_addresses_csv.rake

@ -20,15 +20,26 @@ namespace :correct_addresses do
.imported_2023 .imported_2023
.where(needstype: 1) .where(needstype: 1)
.where.not(uprn: nil) .where.not(uprn: nil)
.where("uprn = propcode OR uprn = tenancycode OR town_or_city = 'Bristol'") .where("uprn = propcode OR uprn = tenancycode")
end end
logs_impacted_by_bristol_uprn_issue = if skip_uprn_issue_organisations.include?(organisation.id)
[]
else
organisation.managed_lettings_logs
.imported_2023
.where(needstype: 1)
.where.not(uprn: nil)
.where("town_or_city = 'Bristol'")
end
missing_addresses_threshold = EmailMissingAddressesCsvJob::MISSING_ADDRESSES_THRESHOLD missing_addresses_threshold = EmailMissingAddressesCsvJob::MISSING_ADDRESSES_THRESHOLD
if logs_impacted_by_missing_address >= missing_addresses_threshold || logs_impacted_by_missing_town_or_city >= missing_addresses_threshold || logs_impacted_by_uprn_issue.any? if logs_impacted_by_missing_address >= missing_addresses_threshold || logs_impacted_by_missing_town_or_city >= missing_addresses_threshold || logs_impacted_by_uprn_issue.any? || logs_impacted_by_bristol_uprn_issue.any?
issue_types = [] issue_types = []
issue_types << "missing_address" if logs_impacted_by_missing_address.positive? issue_types << "missing_address" if logs_impacted_by_missing_address.positive?
issue_types << "missing_town" if logs_impacted_by_missing_town_or_city.positive? issue_types << "missing_town" if logs_impacted_by_missing_town_or_city.positive?
issue_types << "wrong_uprn" if logs_impacted_by_uprn_issue.any? issue_types << "wrong_uprn" if logs_impacted_by_uprn_issue.any?
issue_types << "bristol_uprn" if logs_impacted_by_bristol_uprn_issue.any?
data_coordinators = organisation.users.where(role: 2).filter_by_active data_coordinators = organisation.users.where(role: 2).filter_by_active
users_to_contact = data_coordinators.any? ? data_coordinators : organisation.users.filter_by_active users_to_contact = data_coordinators.any? ? data_coordinators : organisation.users.filter_by_active
EmailMissingAddressesCsvJob.perform_later(users_to_contact.map(&:id), organisation, "lettings", issue_types, skip_uprn_issue_organisations) EmailMissingAddressesCsvJob.perform_later(users_to_contact.map(&:id), organisation, "lettings", issue_types, skip_uprn_issue_organisations)

4
spec/lib/tasks/send_missing_addresses_csv_spec.rb

@ -159,7 +159,7 @@ RSpec.describe "correct_addresses" do
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
expect { task.invoke }.to enqueue_job(EmailMissingAddressesCsvJob).with(include(data_coordinator.id, data_coordinator2.id), organisation, "lettings", %w[wrong_uprn], []) expect { task.invoke }.to enqueue_job(EmailMissingAddressesCsvJob).with(include(data_coordinator.id, data_coordinator2.id), organisation, "lettings", %w[bristol_uprn], [])
end end
it "prints out the jobs enqueued" do it "prints out the jobs enqueued" do
@ -198,7 +198,7 @@ RSpec.describe "correct_addresses" do
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
expect { task.invoke }.to enqueue_job(EmailMissingAddressesCsvJob).with(include(data_provider.id, data_provider2.id), organisation, "lettings", %w[wrong_uprn], []) expect { task.invoke }.to enqueue_job(EmailMissingAddressesCsvJob).with(include(data_provider.id, data_provider2.id), organisation, "lettings", %w[wrong_uprn bristol_uprn], [])
end end
it "prints out the jobs enqueued" do it "prints out the jobs enqueued" do

19
spec/mailers/csv_download_mailer_spec.rb

@ -38,9 +38,11 @@ RSpec.describe CsvDownloadMailer do
template_id: described_class::CSV_MISSING_LETTINGS_ADDRESSES_DOWNLOAD_TEMPLATE_ID, template_id: described_class::CSV_MISSING_LETTINGS_ADDRESSES_DOWNLOAD_TEMPLATE_ID,
personalisation: { personalisation: {
name: user.name, name: user.name,
issue_explanation: "Some address data is missing or incorrect. We've detected the following issues in your logs imported to the new version of CORE:\n\n- Missing town or city: The town or city in some logs is missing. This data is required in the new version of CORE.\n", issue_explanation: "We have found this issue in your logs imported to the new version of CORE:
## Missing town or city
The town or city in some logs is missing. This data is required in the new version of CORE.\n",
how_to_fix: "You need to:\n how_to_fix: "You need to:\n
- download [this spreadsheet for lettings logs](#{link}) - download [this spreadsheet for lettings logs](#{link}). This link will expire in one week. To request another link, [contact the CORE helpdesk](https://dluhcdigital.atlassian.net/servicedesk/customer/portal/6/group/11).
- fill in the missing address data - fill in the missing address data
- check that the existing address data is correct\n", - check that the existing address data is correct\n",
duration: "20 minutes", duration: "20 minutes",
@ -61,11 +63,16 @@ RSpec.describe CsvDownloadMailer do
template_id: described_class::CSV_MISSING_SALES_ADDRESSES_DOWNLOAD_TEMPLATE_ID, template_id: described_class::CSV_MISSING_SALES_ADDRESSES_DOWNLOAD_TEMPLATE_ID,
personalisation: { personalisation: {
name: user.name, name: user.name,
issue_explanation: "Some address data is missing or incorrect. We've detected the following issues in your logs imported to the new version of CORE:\n\n- UPRN may be incorrect: The UPRN in some logs may be incorrect, so wrong address data was imported. We think this is an issue because in some logs the UPRN is the same as the tenant code or property reference, and because your organisation has submitted logs for properties in Bristol for the first time.\n", issue_explanation: "We have found this issue in your logs imported to the new version of CORE:
## Incorrect UPRN\nThe UPRN in some logs may be incorrect, so the wrong address data may have been imported.
In some of your logs, the UPRN is the same as the tenant code or property reference, but these are different things. Property references are codes that yourorganisation uses to identify properties. UPRNs are unique numbers assigned by the Ordnance Survey.
If a log has the correct UPRN, leave the UPRN unchanged. If the UPRN is incorrect, clear the value and provide the full address instead. Alternatively, you can change the UPRN on the CORE system.\n",
how_to_fix: "You need to:\n how_to_fix: "You need to:\n
- download [this spreadsheet for sales logs](#{link}) - download [this spreadsheet for sales logs](#{link}). This link will expire in one week. To request another link, [contact the CORE helpdesk](https://dluhcdigital.atlassian.net/servicedesk/customer/portal/6/group/11).
- check the address data - check that the address data is correct
- correct any errors\n", - correct any address errors\n",
duration: "20 minutes", duration: "20 minutes",
}, },
) )

Loading…
Cancel
Save