mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Rename data sanitize task to data anonymize
This commit is contained in:
61
lib/tasks/data/anonymize_data.rake
Normal file
61
lib/tasks/data/anonymize_data.rake
Normal file
@@ -0,0 +1,61 @@
|
||||
require 'highline'
|
||||
|
||||
namespace :ofn do
|
||||
namespace :data do
|
||||
desc 'Anonymize data'
|
||||
task anonymize: :environment do
|
||||
guard_and_warn
|
||||
|
||||
Spree::User.update_all("email = concat(id, '_ofn_user@example.com'),
|
||||
login = concat(id, '_ofn_user@example.com'),
|
||||
unconfirmed_email = concat(id, '_ofn_user@example.com')")
|
||||
Customer.where("user_id IS NULL")
|
||||
.update_all("email = concat(id, '_ofn_customer@example.com'),
|
||||
name = concat('Customer Number ', id, ' (without connected User)')")
|
||||
Customer.where("user_id IS NOT NULL")
|
||||
.update_all("email = concat(user_id, '_ofn_user@example.com'),
|
||||
name = concat('Customer Number ', id, ' - User ', user_id)")
|
||||
|
||||
Spree::Order.update_all("email = concat(id, '_ofn_order@example.com')")
|
||||
Spree::Address.update_all("
|
||||
firstname = concat('Ms. Number', id), lastname = 'Jones', phone = '01234567890',
|
||||
alternative_phone = '01234567890', address1 = 'Dummy address',
|
||||
address2 = 'Dummy address continuation',
|
||||
company = null, latitude = null, longitude = null")
|
||||
Spree::TokenizedPermission.update_all("token = null")
|
||||
|
||||
# Anonymize payments related entities
|
||||
Spree::PaymentMethod.update_all("name = concat('Dummy Payment Method', id),
|
||||
description = name")
|
||||
Spree::CreditCard.update_all("
|
||||
month = 12, year = 2020, start_month = 12, start_year = 2000,
|
||||
cc_type = 'VISA', first_name = 'Dummy', last_name = 'Dummy', last_digits = '2543'")
|
||||
Spree::Payment.update_all("response_code = null, avs_response = null,
|
||||
cvv_response_code = null, identifier = null,
|
||||
cvv_response_message = null")
|
||||
Spree::PaypalExpressCheckout.update_all("token = null")
|
||||
StripeAccount.delete_all
|
||||
ActiveRecord::Base.connection.execute("delete from spree_paypal_accounts")
|
||||
|
||||
# Update environment in mail methods and payment methods
|
||||
ActiveRecord::Base.connection.execute("update spree_mail_methods set environment = '#{Rails.env}'")
|
||||
Spree::PaymentMethod.update_all("environment = '#{Rails.env}'")
|
||||
|
||||
# Delete all preferences that may contain sensitive information
|
||||
Spree::Preference
|
||||
.where("key like '%gateway%' OR key like '%billing_integration%' OR key like '%s3%'")
|
||||
.delete_all
|
||||
end
|
||||
|
||||
def guard_and_warn
|
||||
if Rails.env.production?
|
||||
Rails.logger.info("This task cannot be executed in production")
|
||||
exit
|
||||
end
|
||||
|
||||
message = "\n <%= color('This will permanently change DB contents', :yellow) %>,
|
||||
are you sure you want to proceed? (y/N)"
|
||||
exit unless HighLine.new.agree(message) { |q| q.default = "n" }
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user