6 changed files with 79 additions and 12 deletions
@ -0,0 +1,36 @@ |
|||||||
|
module Imports |
||||||
|
class DataProtectionConfirmationImportService < ImportService |
||||||
|
def create_data_protection_confirmations(folder) |
||||||
|
import_from(folder, :create_data_protection_confirmation) |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def create_data_protection_confirmation(xml_document) |
||||||
|
org = Organisation.find_by(old_org_id: record_field_value(xml_document, "institution")) |
||||||
|
dp_officer = User.find_or_create_by( |
||||||
|
name: record_field_value(xml_document, "dp-user"), |
||||||
|
organisation: org, |
||||||
|
role: "data_protection_officer", |
||||||
|
) |
||||||
|
dp_officer.encrypted_password = SecureRandom.hex(10) |
||||||
|
dp_officer.save(validate: false) |
||||||
|
|
||||||
|
DataProtectionConfirmation.create!( |
||||||
|
organisation: org, |
||||||
|
confirmed: !!record_field_value(xml_document, "data-protection"), |
||||||
|
data_protection_officer: dp_officer, |
||||||
|
old_id: record_field_value(xml_document, "id"), |
||||||
|
old_org_id: record_field_value(xml_document, "institution"), |
||||||
|
) |
||||||
|
rescue ActiveRecord::RecordNotUnique |
||||||
|
id = record_field_value(xml_document, "id") |
||||||
|
dp_officer_name = record_field_value(xml_document, "dp-user") |
||||||
|
@logger.warn("Data protection confirmation #{id} created by #{dp_officer_name} for #{org.name} is already present, skipping.") |
||||||
|
end |
||||||
|
|
||||||
|
def record_field_value(xml_document, field) |
||||||
|
field_value(xml_document, "dataprotect", field) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,12 @@ |
|||||||
|
FactoryBot.define do |
||||||
|
factory :data_protection_confirmation do |
||||||
|
organisation |
||||||
|
data_protection_officer { FactoryBot.create(:user, :data_protection_officer) } |
||||||
|
confirmed { true } |
||||||
|
old_org_id { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" } |
||||||
|
old_id { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" } |
||||||
|
|
||||||
|
created_at { Time.zone.now } |
||||||
|
updated_at { Time.zone.now } |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue