-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2961 from DFE-Digital/CAPT-1527/keep-irp-national…
…-insurance-and-name-for-2-years Capt 1527/keep irp national insurance and name for 2 years
- Loading branch information
Showing
32 changed files
with
696 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Removes attributes from a claim and its amendments | ||
class Claim | ||
class Scrubber | ||
def self.scrub!(claim, attributes_to_delete) | ||
new(claim, attributes_to_delete).scrub! | ||
end | ||
|
||
attr_reader :claim, :attributes_to_delete | ||
|
||
def initialize(claim, attributes_to_delete) | ||
@claim = claim | ||
@attributes_to_delete = attributes_to_delete.map(&:to_s) | ||
end | ||
|
||
def scrub! | ||
ApplicationRecord.transaction do | ||
claim.amendments.each { |amendment| scrub_amendment!(amendment) } | ||
scrub_claim! | ||
scrub_session! | ||
end | ||
end | ||
|
||
private | ||
|
||
def scrub_amendment!(amendment) | ||
amendment_data_to_scrub = attributes_to_delete & amendment.claim_changes.keys.map(&:to_s) | ||
personal_data_mask = amendment_data_to_scrub.to_h { |attr| [attr, nil] } | ||
amendment.claim_changes.merge!(personal_data_mask) | ||
amendment.personal_data_removed_at = Time.zone.now | ||
amendment.save! | ||
end | ||
|
||
def scrub_claim! | ||
personal_data_mask = attributes_to_delete.to_h { |attr| [attr, nil] } | ||
attributes_to_set = personal_data_mask.merge( | ||
personal_data_removed_at: Time.zone.now | ||
) | ||
claim.update!(attributes_to_set) | ||
end | ||
|
||
def scrub_session! | ||
return unless claim.journey_session | ||
|
||
claim.journey_session.update!(answers: {}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
app/models/policies/early_career_payments/claim_personal_data_scrubber.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Policies | ||
module EarlyCareerPayments | ||
class ClaimPersonalDataScrubber < Policies::ClaimPersonalDataScrubber | ||
end | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
app/models/policies/further_education_payments/claim_personal_data_scrubber.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Policies | ||
module FurtherEducationPayments | ||
class ClaimPersonalDataScrubber < Policies::ClaimPersonalDataScrubber | ||
end | ||
end | ||
end |
61 changes: 61 additions & 0 deletions
61
app/models/policies/international_relocation_payments/claim_personal_data_scrubber.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module Policies | ||
module InternationalRelocationPayments | ||
class ClaimPersonalDataScrubber < Policies::ClaimPersonalDataScrubber | ||
PERSONAL_DATA_ATTRIBUTES_TO_DELETE = [ | ||
:date_of_birth, | ||
:address_line_1, | ||
:address_line_2, | ||
:address_line_3, | ||
:address_line_4, | ||
:postcode, | ||
:payroll_gender, | ||
:bank_sort_code, | ||
:bank_account_number, | ||
:building_society_roll_number, | ||
:banking_name, | ||
:hmrc_bank_validation_responses, | ||
:mobile_number, | ||
:teacher_id_user_info, | ||
:dqt_teacher_status | ||
] | ||
|
||
PERSONAL_DATA_ATTRIBUTES_TO_RETAIN_FOR_EXTENDED_PERIOD = [ | ||
:first_name, | ||
:middle_name, | ||
:surname, | ||
:national_insurance_number | ||
] | ||
|
||
ANY_NON_NULL_EXTENDED_PERIOD_ATTRIBUTES = | ||
PERSONAL_DATA_ATTRIBUTES_TO_RETAIN_FOR_EXTENDED_PERIOD.map do |attr| | ||
"#{attr} IS NOT NULL" | ||
end.join(" OR ") | ||
|
||
def scrub_completed_claims | ||
super | ||
|
||
claims_rejected_before(extended_period_end_date).where( | ||
ANY_NON_NULL_EXTENDED_PERIOD_ATTRIBUTES | ||
).each do |claim| | ||
Claim::Scrubber.scrub!( | ||
claim, | ||
PERSONAL_DATA_ATTRIBUTES_TO_RETAIN_FOR_EXTENDED_PERIOD | ||
) | ||
end | ||
|
||
claims_paid_before(extended_period_end_date).where( | ||
ANY_NON_NULL_EXTENDED_PERIOD_ATTRIBUTES | ||
).each do |claim| | ||
Claim::Scrubber.scrub!( | ||
claim, | ||
PERSONAL_DATA_ATTRIBUTES_TO_RETAIN_FOR_EXTENDED_PERIOD | ||
) | ||
end | ||
end | ||
|
||
def extended_period_end_date | ||
minimum_time - 2.years | ||
end | ||
end | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
app/models/policies/levelling_up_premium_payments/claim_personal_data_scrubber.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Policies | ||
module LevellingUpPremiumPayments | ||
class ClaimPersonalDataScrubber < Policies::ClaimPersonalDataScrubber | ||
end | ||
end | ||
end |
Oops, something went wrong.