diff --git a/lib/tasks/data_import.rake b/lib/tasks/data_import.rake index ea19d96b5..6e0fdd4b9 100644 --- a/lib/tasks/data_import.rake +++ b/lib/tasks/data_import.rake @@ -29,26 +29,20 @@ namespace :core do end end - desc "Import missing data sharing agreement XMLs from legacy CORE" - task :data_protection_confirmation_import, %i[type path] => :environment do |_task| - orgs_without_dpc = Organisation.includes(:data_protection_confirmation) - .where.not(id: DataProtectionConfirmation.all.select(:organisation_id)) - .where.not(old_org_id: nil) - - puts "Processing #{orgs_without_dpc.count} orgs without data protection confirmation" - s3_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"]) - - orgs_without_dpc.each do |org| - archive_path = "#{org.old_org_id}.zip" - archive_io = s3_service.get_file_io(archive_path) - archive_service = Storage::ArchiveService.new(archive_io) - if archive_service.folder_present?("dataprotect") - Rails.logger.info("Start importing folder dataprotect") - Imports::DataProtectionConfirmationImportService.new(archive_service).create_data_protection_confirmations("dataprotect") - Rails.logger.info("Imported") - else - Rails.logger.info("dataprotect does not exist, skipping import") - end + desc "Persist user and org data on data sharing confirmations" + task persist_user_and_org_data_on_data_sharing_confirmations: :environment do |_task| + DataProtectionConfirmation.all.includes(:data_protection_officer, :organisation).each do |dpc| + dpc.update!( + organisation_name: dpc.organisation.name, + organisation_address: dpc.organisation.address_row, + signed_at: dpc.created_at, + organisation_phone_number: dpc.organisation.phone, + data_protection_officer_email: dpc.data_protection_officer.email, + data_protection_officer_name: dpc.data_protection_officer.name, + ) + print "." end + + puts "done" end end diff --git a/spec/lib/tasks/data_import_spec.rb b/spec/lib/tasks/data_import_spec.rb index c251477b9..b8b56801a 100644 --- a/spec/lib/tasks/data_import_spec.rb +++ b/spec/lib/tasks/data_import_spec.rb @@ -176,42 +176,4 @@ describe "data import", type: :task do expect { task.invoke("unknown_type", "my_path") }.to raise_error(/Type unknown_type is not supported/) end end - - describe "core:data_protection_confirmation_import" do - subject(:task) { Rake::Task["core:data_protection_confirmation_import"] } - - let(:import_service) { instance_double(Imports::DataProtectionConfirmationImportService) } - # let(:fixture_path) { "spec/fixtures/imports/data_protection_confirmations" } - let(:storage_service) { instance_double(Storage::S3Service) } - let(:archive_service) { instance_double(Storage::ArchiveService) } - - let!(:organisation_without_dpc_with_old_org_id) { create(:organisation, :without_dpc, old_org_id: 1) } - - before do - Rake.application.rake_require("tasks/data_import") - Rake::Task.define_task(:environment) - task.reenable - - allow(Storage::S3Service).to receive(:new).and_return(storage_service) - allow(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_service) - allow(ENV).to receive(:[]) - allow(ENV).to receive(:[]).with("IMPORT_PAAS_INSTANCE").and_return(instance_name) - allow(Imports::DataProtectionConfirmationImportService).to receive(:new).and_return(import_service) - - allow(Storage::ArchiveService).to receive(:new).and_return(archive_service) - allow(archive_service).to receive(:folder_present?).with("dataprotect").and_return(true) - - _org_without_old_org_id = create(:organisation, old_org_id: nil) - _organisation_without_dp = create(:organisation, :without_dpc, old_org_id: nil) - end - - it "creates an organisation from the given XML file" do - expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) - expect(storage_service).to receive(:get_file_io).with("#{organisation_without_dpc_with_old_org_id.old_org_id}.zip") - expect(Imports::DataProtectionConfirmationImportService).to receive(:new).with(archive_service) - expect(import_service).to receive(:create_data_protection_confirmations).with("dataprotect") - - task.invoke - end - end end