Skip to content

Commit

Permalink
Merge pull request #6906 from ministryofjustice/ap-5141/partner-file-…
Browse files Browse the repository at this point in the history
…lengths

AP-5141: Change partner file name lengths
  • Loading branch information
colinbruce authored Jul 10, 2024
2 parents a8e29f5 + 9b86f4b commit 4de705a
Showing 27 changed files with 282 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ def successful_upload
end

def attachments
legal_aid_application.attachments.partner_bank_statement_evidence
legal_aid_application.attachments.part_bank_state_evidence
end

def url
6 changes: 3 additions & 3 deletions app/controllers/v1/partners/bank_statements_controller.rb
Original file line number Diff line number Diff line change
@@ -3,16 +3,16 @@ module Partners
class BankStatementsController < BaseBankStatementsController
def initialize
super
@attachment_type = "partner_bank_statement_evidence"
@attachment_type = "part_bank_state_evidence"
@attachment_type_capture = /^#{@attachment_type}_(\d+)$/
end

private

# can be shared with v1 bank statement controller
def sequenced_attachment_name
if legal_aid_application.attachments.partner_bank_statement_evidence.any?
most_recent_name = legal_aid_application.attachments.partner_bank_statement_evidence.order(:attachment_name).last.attachment_name
if legal_aid_application.attachments.part_bank_state_evidence.any?
most_recent_name = legal_aid_application.attachments.part_bank_state_evidence.order(:attachment_name).last.attachment_name
increment_name(most_recent_name)
else
attachment_type
8 changes: 4 additions & 4 deletions app/forms/providers/partners/bank_statement_form.rb
Original file line number Diff line number Diff line change
@@ -3,20 +3,20 @@ module Partners
class BankStatementForm < BaseBankStatementForm
def initialize(bank_statement_form_params)
super
@attachment_type = "partner_bank_statement_evidence"
@attachment_type = "part_bank_state_evidence"
@attachment_type_capture = /^#{@attachment_type}_(\d+)$/
end

private

def any_bank_statements_or_draft?
legal_aid_application.attachments.partner_bank_statement_evidence.any? || draft?
legal_aid_application.attachments.part_bank_state_evidence.any? || draft?
end

# can be shared with v1 bank statement controller
def sequenced_attachment_name
if legal_aid_application.attachments.partner_bank_statement_evidence.any?
most_recent_name = legal_aid_application.attachments.partner_bank_statement_evidence.order(:created_at, :attachment_name).last.attachment_name
if legal_aid_application.attachments.part_bank_state_evidence.any?
most_recent_name = legal_aid_application.attachments.part_bank_state_evidence.order(:created_at, :attachment_name).last.attachment_name
increment_name(most_recent_name)
else
attachment_type
4 changes: 2 additions & 2 deletions app/models/legal_aid_application.rb
Original file line number Diff line number Diff line change
@@ -539,15 +539,15 @@ def hmrc_response_use_case_one
end

def uploading_bank_statements?
client_not_given_consent_to_open_banking? || attachments.bank_statement_evidence.exists? || attachments.partner_bank_statement_evidence.exists?
client_not_given_consent_to_open_banking? || attachments.bank_statement_evidence.exists? || attachments.part_bank_state_evidence.exists?
end

def client_uploading_bank_statements?
client_not_given_consent_to_open_banking? || attachments.bank_statement_evidence.exists?
end

def partner_uploading_bank_statements?
attachments&.partner_bank_statement_evidence&.exists?
attachments&.part_bank_state_evidence&.exists?
end

def has_transaction_type?(transaction_type)
12 changes: 10 additions & 2 deletions app/services/ccms/requestors/document_id_requestor.rb
Original file line number Diff line number Diff line change
@@ -33,9 +33,17 @@ def soap_body(xml)

def document_type(xml)
case @document_type
in "bank_transaction_report" | "bank_statement_evidence_pdf"
when "bank_statement_evidence_pdf", "part_bank_state_evidence_pdf", "bank_transaction_report"
xml.__send__(:"casebio:DocumentType", "BSTMT")
in "gateway_evidence_pdf"
when "client_employment_evidence_pdf", "part_employ_evidence_pdf", "employment_evidence_pdf"
xml.__send__(:"casebio:DocumentType", "PAYSLIP")
when "court_order_pdf", "court_application_or_order_pdf", "court_application_pdf"
xml.__send__(:"casebio:DocumentType", "COURT_ORD")
when "expert_report_pdf", "gateway_evidence_pdf"
xml.__send__(:"casebio:DocumentType", "EX_RPT")
when "benefit_evidence_pdf"
xml.__send__(:"casebio:DocumentType", "BEN_LTR")
when "statement_of_case_pdf"
xml.__send__(:"casebio:DocumentType", "STATE")
else
xml.__send__(:"casebio:DocumentType", "ADMIN1")
16 changes: 14 additions & 2 deletions app/services/ccms/requestors/document_upload_requestor.rb
Original file line number Diff line number Diff line change
@@ -45,10 +45,22 @@ def document_type(xml)
when "bank_transaction_report"
xml.__send__(:"casebio:DocumentType", "BSTMT")
xml.__send__(:"casebio:FileExtension", "csv")
when "bank_statement_evidence_pdf"
when "bank_statement_evidence_pdf", "part_bank_state_evidence_pdf"
xml.__send__(:"casebio:DocumentType", "BSTMT")
xml.__send__(:"casebio:FileExtension", "pdf")
when "gateway_evidence_pdf"
when "client_employment_evidence_pdf", "part_employ_evidence_pdf", "employment_evidence_pdf"
xml.__send__(:"casebio:DocumentType", "PAYSLIP")
xml.__send__(:"casebio:FileExtension", "pdf")
when "court_order_pdf", "court_application_or_order_pdf", "court_application_pdf"
xml.__send__(:"casebio:DocumentType", "COURT_ORD")
xml.__send__(:"casebio:FileExtension", "pdf")
when "expert_report_pdf", "gateway_evidence_pdf"
xml.__send__(:"casebio:DocumentType", "EX_RPT")
xml.__send__(:"casebio:FileExtension", "pdf")
when "benefit_evidence_pdf"
xml.__send__(:"casebio:DocumentType", "BEN_LTR")
xml.__send__(:"casebio:FileExtension", "pdf")
when "statement_of_case_pdf"
xml.__send__(:"casebio:DocumentType", "STATE")
xml.__send__(:"casebio:FileExtension", "pdf")
else
2 changes: 1 addition & 1 deletion app/services/required_document_category_analyser.rb
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ def call
required_document_categories << "benefit_evidence" if @application.dwp_override&.has_evidence_of_benefit?
required_document_categories << "gateway_evidence" if @application.section_8_proceedings?
required_document_categories << "client_employment_evidence" if @application.employment_evidence_required?
required_document_categories << "partner_employment_evidence" if @application&.partner&.employment_evidence_required?
required_document_categories << "part_employ_evidence" if @application&.partner&.employment_evidence_required?
required_document_categories << "court_application_or_order" if has_opponents_application? && !has_listed_final_hearing?
if has_listed_final_hearing? && !has_opponents_application?
required_document_categories << "court_order"
9 changes: 5 additions & 4 deletions app/validators/document_category_validator.rb
Original file line number Diff line number Diff line change
@@ -4,14 +4,15 @@
# - to validate the name field on the DocumentCategory model
#
class DocumentCategoryValidator < ActiveModel::Validator
# these names should not exceed 30 characters
VALID_DOCUMENT_TYPES = %w[
bank_transaction_report
benefit_evidence
benefit_evidence_pdf
client_employment_evidence
client_employment_evidence_pdf
partner_employment_evidence
partner_employment_evidence_pdf
part_employ_evidence
part_employ_evidence_pdf
gateway_evidence
gateway_evidence_pdf
means_report
@@ -28,8 +29,8 @@ class DocumentCategoryValidator < ActiveModel::Validator
expert_report_pdf
court_application_or_order
court_application_or_order_pdf
partner_bank_statement_evidence
partner_bank_statement_evidence_pdf
part_bank_state_evidence
part_bank_state_evidence_pdf
].freeze

def validate(record)
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
<%= render("outgoings", individual: "Client") %>

<% if @legal_aid_application.applicant.has_partner_with_no_contrary_interest? %>
<%= render("bank_statements", bank_statements: @legal_aid_application.attachments.partner_bank_statement_evidence, individual: "Partner", read_only: true) %>
<%= render("bank_statements", bank_statements: @legal_aid_application.attachments.part_bank_state_evidence, individual: "Partner", read_only: true) %>

<% if @cfe_result.partner_jobs? %>
<%= render("employment_income", individual: "Partner") %>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<section class="partner">
<h2 class="govuk-heading-l govuk-!-margin-bottom-8"><%= t(".income-heading") %></h2>

<%= render("shared/check_answers/bank_statements", bank_statements: @legal_aid_application.attachments.partner_bank_statement_evidence, read_only: false, partner: true) %>
<%= render("shared/check_answers/bank_statements", bank_statements: @legal_aid_application.attachments.part_bank_state_evidence, read_only: false, partner: true) %>

<% if @legal_aid_application.partner.hmrc_employment_income? %>
<% if @legal_aid_application.partner.has_multiple_employments? %>
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@
<%= row.with_key(text: t(".partner_bank_statement_question"), classes: "govuk-!-width-one-half") %>
<%= row.with_value do %>
<ul class="govuk-list">
<% attachments_with_size(@legal_aid_application.attachments.partner_bank_statement_evidence).each do |answer| %>
<% attachments_with_size(@legal_aid_application.attachments.part_bank_state_evidence).each do |answer| %>
<li><%= answer %></li>
<% end %>
</ul>
2 changes: 1 addition & 1 deletion app/views/providers/partners/bank_statements/show.html.erb
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@
warning: t(".warning"),
url: providers_legal_aid_application_partners_bank_statements_path,
data_url: v1_partners_bank_statements_path,
attachments: @form.legal_aid_application.attachments.partner_bank_statement_evidence %>
attachments: @form.legal_aid_application.attachments.part_bank_state_evidence %>
2 changes: 1 addition & 1 deletion app/views/shared/review_application/_partner_income.erb
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
<!-- UPLOADED BANK STATEMENTS -->

<% if @legal_aid_application.partner_uploading_bank_statements? %>
<%= render("shared/check_answers/bank_statements", bank_statements: @legal_aid_application.attachments.partner_bank_statement_evidence, read_only: true, partner: true) %>
<%= render("shared/check_answers/bank_statements", bank_statements: @legal_aid_application.attachments.part_bank_state_evidence, read_only: true, partner: true) %>
<% end %>

<!-- EMPLOYMENT INCOME -->
2 changes: 1 addition & 1 deletion config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
@@ -938,7 +938,7 @@ en:
benefit_evidence_missing: Upload evidence that your client receives %{benefit}
content_type_invalid: The selected file must be a DOC, DOCX, RTF, ODT, JPG, BMP, PNG, TIF or PDF
client_employment_evidence_missing: Upload your client's employment evidence
partner_employment_evidence_missing: Upload the partner's employment evidence
part_employ_evidence_missing: Upload the partner's employment evidence
court_application_or_order_missing: Upload the application to court or the court order for Section 8 proceedings
court_application_missing: Upload the application to court for Section 8 proceedings
court_order_missing: Upload the court order for Section 8 proceedings
2 changes: 1 addition & 1 deletion config/locales/en/providers.yml
Original file line number Diff line number Diff line change
@@ -790,7 +790,7 @@ en:
list_text: 'Use this page to upload:'
benefit_evidence: evidence that your client receives %{benefit}
client_employment_evidence: evidence of your client's employment
partner_employment_evidence: evidence of the partner's employment
part_employ_evidence: evidence of the partner's employment
gateway_evidence: gateway evidence for Section 8 proceedings (optional)
court_application: the application to court for Section 8 proceedings (optional)
court_order: the court order for Section 8 proceedings
2 changes: 1 addition & 1 deletion config/locales/en/shared.yml
Original file line number Diff line number Diff line change
@@ -543,7 +543,7 @@ en:
evidence_types:
benefit_evidence: Benefit evidence
client_employment_evidence: Client's employment evidence
partner_employment_evidence: Partner's employment evidence
part_employ_evidence: Partner's employment evidence
gateway_evidence: Gateway evidence
court_application_or_order: Court application or order
court_order: Court order
6 changes: 4 additions & 2 deletions db/seeds/document_categories.csv
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ benefit_evidence,FALSE,,TRUE,TRUE
benefit_evidence_pdf,TRUE,ADMIN1,FALSE,FALSE
client_employment_evidence,FALSE,,TRUE,TRUE
client_employment_evidence_pdf,TRUE,ADMIN1,FALSE,FALSE
partner_employment_evidence,FALSE,,TRUE,TRUE
partner_employment_evidence_pdf,TRUE,ADMIN1,FALSE,FALSE
part_employ_evidence,FALSE,,TRUE,TRUE
part_employ_evidence_pdf,TRUE,ADMIN1,FALSE,FALSE
gateway_evidence,FALSE,,TRUE,FALSE
gateway_evidence_pdf,TRUE,STATE,FALSE,FALSE
means_report,TRUE,ADMIN1,FALSE,FALSE
@@ -22,3 +22,5 @@ expert_report,FALSE,,TRUE,FALSE
expert_report_pdf,TRUE,ADMIN1,FALSE,FALSE
court_application_or_order,FALSE,,TRUE,TRUE
court_application_or_order_pdf,TRUE,ADMIN1,FALSE,FALSE
part_bank_state_evidence,FALSE,,FALSE,FALSE
part_bank_state_evidence_pdf,TRUE,BSTMT,FALSE,FALSE
43 changes: 43 additions & 0 deletions lib/tasks/migrate_partner_attachments.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace :migrate do
desc "AP-5141 migrate attachment names after length exceeded CCMS limits"

task partner_attachments: :environment do
changes = {
partner_bank_statement_evidence: "part_bank_state_evidence",
partner_bank_statement_evidence_pdf: "part_bank_state_evidence_pdf",
partner_employment_evidence: "part_employ_evidence",
partner_employment_evidence_pdf: "part_employ_evidence_pdf",
}

attachments = Attachment.where(attachment_type: changes.keys)
documents = CCMS::SubmissionDocument.where(document_type: changes.keys)
Rails.logger.info "Migrating filenames"
Rails.logger.info "----------------------------------------"
Rails.logger.info "Affected attachments : #{attachments.count}"
Rails.logger.info "Affected documents : #{documents.count}"
Rails.logger.info "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
Benchmark.benchmark do |bm|
bm.report("Migrate:") do
ActiveRecord::Base.transaction do
attachments.each do |file|
file.attachment_type = changes[file.attachment_type.to_sym]
file.save!(touch: false) # this prevents the updated_at date being changed and delaying purging of stale records
end
raise StandardError, "Not all attachments updated" if Attachment.where(attachment_type: changes.keys).count.positive?

documents.each do |file|
file.document_type = changes[file.document_type.to_sym]
file.save!(touch: false) # this prevents the updated_at date being changed and delaying purging of stale records
end
raise StandardError, "Not all documents updated" if CCMS::SubmissionDocument.where(document_type: changes.keys).count.positive?
end
end
end
Rails.logger.info "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
Rails.logger.info "Attachments updated : #{Attachment.where(attachment_type: changes.values).count}"
Rails.logger.info "Documents updated : #{CCMS::SubmissionDocument.where(document_type: changes.values).count}"
Rails.logger.info "Attachments not updated: #{Attachment.where(attachment_type: changes.keys).count}"
Rails.logger.info "Documents not updated : #{CCMS::SubmissionDocument.where(document_type: changes.keys).count}"
Rails.logger.info "----------------------------------------"
end
end
4 changes: 2 additions & 2 deletions spec/factories/attachments.rb
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@
end

trait :partner_bank_statement do
attachment_type { "partner_bank_statement_evidence" }
sequence(:attachment_name) { |n| "partner_bank_statement_evidence_#{n}" }
attachment_type { "part_bank_state_evidence" }
sequence(:attachment_name) { |n| "part_bank_state_evidence_#{n}" }
sequence(:original_filename) { "original_filename.pdf" }
end

5 changes: 3 additions & 2 deletions spec/models/document_category_spec.rb
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
%w[
benefit_evidence
client_employment_evidence
partner_employment_evidence
part_employ_evidence
gateway_evidence
uncategorised
court_application_or_order
@@ -39,7 +39,7 @@
bank_statement_evidence_pdf
benefit_evidence_pdf
client_employment_evidence_pdf
partner_employment_evidence_pdf
part_employ_evidence_pdf
gateway_evidence_pdf
means_report
merits_report
@@ -48,6 +48,7 @@
court_application_pdf
court_order_pdf
expert_report_pdf
part_bank_state_evidence_pdf
]
end

20 changes: 10 additions & 10 deletions spec/requests/providers/partners/bank_statements_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@

it "sets attachment_name to model name" do
request
expect(legal_aid_application.reload.attachments.last.attachment_name).to eq("partner_bank_statement_evidence")
expect(legal_aid_application.reload.attachments.last.attachment_name).to eq("part_bank_state_evidence")
end

context "with background job processing" do
@@ -154,34 +154,34 @@

it "adds original and converted attachments types" do
request
expect(legal_aid_application.reload.attachments.pluck(:attachment_type)).to match_array(%w[partner_bank_statement_evidence partner_bank_statement_evidence_pdf])
expect(legal_aid_application.reload.attachments.pluck(:attachment_type)).to match_array(%w[part_bank_state_evidence part_bank_state_evidence_pdf])
end

it "associates pdf converted attachment to original attachment" do
request
original_attachment = legal_aid_application.attachments.find_by(attachment_type: "partner_bank_statement_evidence")
original_attachment = legal_aid_application.attachments.find_by(attachment_type: "part_bank_state_evidence")
expect(original_attachment.pdf_attachment_id).not_to be_nil
end
end

context "when the application has one bank statement attachment already" do
let(:partner_bank_statement_evidence) { create(:attachment, :partner_bank_statement, attachment_name: "partner_bank_statement_evidence") }
let!(:legal_aid_application) { create(:legal_aid_application, attachments: [partner_bank_statement_evidence]) }
let(:part_bank_state_evidence) { create(:attachment, :partner_bank_statement, attachment_name: "part_bank_state_evidence") }
let!(:legal_aid_application) { create(:legal_aid_application, attachments: [part_bank_state_evidence]) }

it "increments the attachment name" do
request
expect(legal_aid_application.reload.attachments.pluck(:attachment_name)).to match_array(%w[partner_bank_statement_evidence partner_bank_statement_evidence_1])
expect(legal_aid_application.reload.attachments.pluck(:attachment_name)).to match_array(%w[part_bank_state_evidence part_bank_state_evidence_1])
end
end

context "when the application has multiple attachments for statement of case already" do
let(:bs1) { create(:attachment, :partner_bank_statement, attachment_name: "partner_bank_statement_evidence") }
let(:bs2) { create(:attachment, :partner_bank_statement, attachment_name: "partner_bank_statement_evidence_1") }
let(:bs1) { create(:attachment, :partner_bank_statement, attachment_name: "part_bank_state_evidence") }
let(:bs2) { create(:attachment, :partner_bank_statement, attachment_name: "part_bank_state_evidence_1") }
let!(:legal_aid_application) { create(:legal_aid_application, attachments: [bs1, bs2]) }

it "increments the attachment name" do
request
expect(legal_aid_application.reload.attachments.pluck(:attachment_name)).to match_array(%w[partner_bank_statement_evidence partner_bank_statement_evidence_1 partner_bank_statement_evidence_2])
expect(legal_aid_application.reload.attachments.pluck(:attachment_name)).to match_array(%w[part_bank_state_evidence part_bank_state_evidence_1 part_bank_state_evidence_2])
end
end
end
@@ -420,7 +420,7 @@
before { login_as provider }

context "with existing file" do
let(:params) { { attachment_id: legal_aid_application.attachments.partner_bank_statement_evidence.first.id } }
let(:params) { { attachment_id: legal_aid_application.attachments.part_bank_state_evidence.first.id } }

before do
patch(providers_legal_aid_application_partners_bank_statements_path(legal_aid_application),
Loading

0 comments on commit 4de705a

Please sign in to comment.