Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP-5699 Fix incorrect PDA data #7591

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

naseberry
Copy link
Contributor

@naseberry naseberry commented Jan 21, 2025

What

Link to story

The new PDA added Provider to incorrect firms and therefore office.
A few new firms where then created because of the above.

This is to transfer application to the correct office; providers to the correct firms; and to remove Firms where no providers have been onboarded.

Checklist

Before you ask people to review this PR:

  • Tests and rubocop should be passing: bundle exec rake
  • Github should not be reporting conflicts; you should have recently run git rebase main.
  • The standards in the Git Workflow document on Confluence should be followed
  • There should be no unnecessary whitespace changes. These make diffs harder to read and conflicts more likely.
  • The PR description should say what you changed and why, with a link to the JIRA story.
  • You should have looked at the diff against main and ensured that nothing unexpected is included in your changes.
  • You should have checked that the commit messages say why the change was made.

Comment on lines 20 to 21
# Transfer provider LLARNI from firm POTTER DERBY LTD to WACE MORGAN SOLICITORS
Rake::Task["pda:provider_transfer_firm"].invoke("701c89c5-8672-4fd3-997c-a08a08a1cc7c", "2eee972d-4697-480f-be61-29e339bf9945")
Copy link
Contributor

@jsugarman jsugarman Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already looks like llarni is in the firm WACE MORGAN SOLICITORS on production

laa-apply-for-legal-aid(prod)> Provider.find_by(id: "701c89c5-8672-4fd3-997c-a08a08a1cc7c").firm.name
=> "WACE MORGAN SOLICITORS"

Rake::Task["pda:laa_transfer_office"].invoke("992c3763-6087-405d-bb0f-be46c24e0b57", "2a7babf2-d080-4181-b395-0244542ff54a")

# Transfer provider DSYKES from firm CAROLE BURGHER SOLICITORS to BUTCHER & BARLOW LLP
Rake::Task["pda:provider_transfer_firm"].invoke("992c3763-6087-405d-bb0f-be46c24e0b57", "2a7babf2-d080-4181-b395-0244542ff54a")
Copy link
Contributor

@jsugarman jsugarman Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this provider is already in the correct firm

Provider.find_by(id: "992c3763-6087-405d-bb0f-be46c24e0b57").firm.name
=> "BUTCHER & BARLOW LLP"

Copy link
Contributor

@jsugarman jsugarman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So some unnecessary albeit unharmful actions are in there, but also some ids are wrong and will fail.

It might be good to have a dry run argument that defaults to true so that it cannot be run by mistake.

@naseberry naseberry force-pushed the ap-5699-incorrect-pda-data branch 3 times, most recently from 101e676 to 0643d8a Compare January 23, 2025 10:15
Copy link
Contributor

@jsugarman jsugarman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon the dry_run naming needs some clarity but, for safety, it might be better to use != "false" as you have done

dry_run = args[:dry_run].to_s.downcase.strip != "false"
# rathar than
dry_run = args[:dry_run].to_s.downcase.strip == "true" 

But the actual updates need to use unless not if gaurd clauses, for example

laa.update!(office: office) unless dry_run

Might be good to test the reusable tasks as discussed in tech time

if laa
Rails.logger.info "LegalAidApplication (#{laa.application_ref}) current office code: #{laa.office.code}"

laa.update!(office: office) if dry_run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming wise I would expect do_something unless dry_run

namespace :fixes do
desc "Fixes for AP-5699"
task :ap_5699, [:dry_run] => :environment do |_task, args|
args.with_defaults(dry_run: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All args are strings in rake i believe

Suggested change
args.with_defaults(dry_run: true)
args.with_defaults(dry_run: "true")

desc "Fixes for AP-5699"
task :ap_5699, [:dry_run] => :environment do |_task, args|
args.with_defaults(dry_run: true)
dry_run = args[:dry_run] != "false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 dry_run = args[:dry_run].to_s.downcase.strip == "true"


# Transfer applications from POTTER DERBY LTD office 0M434D to WACE MORGAN SOLICITORS office 0H036Y
potter_derby_application_ids.each do |appid|
Rake::Task["pda:laa_transfer_office"].execute(dry_run: dry_run.to_s, appid: appid, officeid: "c2d4f6df-0a06-4ade-b1c8-1bba1406a874")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be needed once dry run default is set i think

Suggested change
Rake::Task["pda:laa_transfer_office"].execute(dry_run: dry_run.to_s, appid: appid, officeid: "c2d4f6df-0a06-4ade-b1c8-1bba1406a874")
Rake::Task["pda:laa_transfer_office"].execute(dry_run: dry_run, appid: appid, officeid: "c2d4f6df-0a06-4ade-b1c8-1bba1406a874")

Rake::Task["pda:laa_transfer_office"].execute(dry_run: dry_run.to_s, appid: "6db37c7a-7350-4384-aa2d-c6a6ccfc22e9", officeid: "fe5dfac8-baa6-4a22-b0c9-681d97068508")

# Delete the firm and offices of CAROLE BURGHER SOLICITORS
Rake::Task["pda:delete_firm_office"].execute(dry_run: dry_run.to_s, firmid: "29bbd5ca-5820-4502-b74a-76b11e8bff64")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_s not be needed once dry run default is set to a string i think

Rails.logger.info "Start of HAZELBACON"

# Transfer provider HAZELBACON from firm MCARAS to CANTER LEVIN & BERG LTD, Office: 5T620Z
Rake::Task["pda:provider_transfer_firm"].execute(dry_run: dry_run.to_s, providerid: "03ec8aa6-56a4-494d-91e6-88d4974671db", firmid: "02e2f920-c5fd-4e6c-9d6c-af1a16dfe7fc")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_s not be needed once dry run default is set to a string i think

namespace :pda do
desc "Transfer a LegalAidApplication from one Office to another"
task :laa_transfer_office, %i[dry_run appid officeid] => :environment do |_task, args|
args.with_defaults(dry_run: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args.with_defaults(dry_run: true)
args.with_defaults(dry_run: "true")

desc "Transfer a LegalAidApplication from one Office to another"
task :laa_transfer_office, %i[dry_run appid officeid] => :environment do |_task, args|
args.with_defaults(dry_run: true)
dry_run = args[:dry_run] != "false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dry_run = args[:dry_run] != "false"
dry_run = args[:dry_run].to_s.downcase.strip == "true"


desc "Transfer a Provider from one Firm to another"
task :provider_transfer_firm, %i[dry_run providerid firmid] => :environment do |_task, args|
args.with_defaults(dry_run: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args.with_defaults(dry_run: true)
args.with_defaults(dry_run: "true")

desc "Transfer a Provider from one Firm to another"
task :provider_transfer_firm, %i[dry_run providerid firmid] => :environment do |_task, args|
args.with_defaults(dry_run: true)
dry_run = args[:dry_run] != "false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dry_run = args[:dry_run] != "false"
dry_run = args[:dry_run].to_s.downcase.strip == "true"

@naseberry naseberry force-pushed the ap-5699-incorrect-pda-data branch from e267472 to 82613ee Compare January 24, 2025 16:26
- Task to transfer the selected office of an application
- Task to transfer a provider to a different firm
- Task to remove unused Firm
@naseberry naseberry force-pushed the ap-5699-incorrect-pda-data branch 3 times, most recently from 236061b to 60a820a Compare January 27, 2025 12:35
@naseberry naseberry marked this pull request as ready for review January 27, 2025 13:03
@naseberry naseberry requested a review from a team as a code owner January 27, 2025 13:03
@naseberry naseberry force-pushed the ap-5699-incorrect-pda-data branch from 60a820a to 7f4ab3a Compare January 27, 2025 13:19
Copy link
Contributor

@agoldstone93 agoldstone93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some nits and some other comments

firm = Firm.find_by(id: args[:firmid])

if firm.nil?
Rails.logger.info "FIRM does not exists"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: exists should say exist

end
end

context "when LegalAidApplication does not exist" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding an expect to verify that office doesn't change in these scenarios?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say yes, it's worth it - this could be destructive if it goes wrong! 😬

end
end

context "when Provider does not exist" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding an expect to verify that provider doesn't change in these scenarios?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines +14 to +15
let(:firm) { create(:firm) }
let(:office) { create(:office) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: As these are only used in the final spec, could they be defined within it?

@@ -0,0 +1,86 @@
namespace :ptr_migrations do
desc "Transfer a LegalAidApplication from one Office to another"
task :laa_transfer_office, %i[mock appid officeid] => :environment do |_task, args|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could these be called app_id and office_id for readability?


it "skips deleting the Office and logs a message" do
expect(Rails.logger).to receive(:info).with("Firm (#{firm.name}), Office (#{office.code}) has 1 legal aid application associated with it. Skipping!")
expect(Rails.logger).to receive(:info).with("Firm (#{firm.name}) has 1 office associated with it. Skipping!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to work when there are multiple offices? Could there a be a test for this scenario?


if applications_in_office.positive?
Rails.logger.info "Firm (#{firm.name}), Office (#{office.code}) has #{applications_in_office} legal aid application associated with it. Skipping!"
# next
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out next

end

desc "Transfer a Provider from one Firm to another"
task :provider_transfer_firm, %i[mock providerid firmid] => :environment do |_task, args|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto nit: clarity of names

Suggested change
task :provider_transfer_firm, %i[mock providerid firmid] => :environment do |_task, args|
task :provider_transfer_firm, %i[mock provider_id firm_id] => :environment do |_task, args|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants