Browse Source

Use DPC persisted data and signed_at (#1771)

pull/1773/head v0.3.38
Jack 1 year ago committed by GitHub
parent
commit
d5b02ddee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/controllers/organisations_controller.rb
  2. 16
      app/helpers/data_sharing_agreement_helper.rb
  3. 1
      app/services/imports/data_protection_confirmation_import_service.rb
  4. 4
      app/views/organisations/data_sharing_agreement.html.erb
  5. 17
      lib/tasks/data_import.rake
  6. 7
      spec/factories/data_protection_confirmation.rb
  7. 2
      spec/services/imports/data_protection_confirmation_import_service_spec.rb
  8. 6
      spec/views/organisations/data_sharing_agreement.html.erb_spec.rb

1
app/controllers/organisations_controller.rb

@ -170,7 +170,6 @@ class OrganisationsController < ApplicationController
@organisation.data_protection_confirmation.update!( @organisation.data_protection_confirmation.update!(
confirmed: true, confirmed: true,
data_protection_officer: current_user, data_protection_officer: current_user,
created_at: Time.zone.now,
signed_at: Time.zone.now, signed_at: Time.zone.now,
organisation_name: @organisation.name, organisation_name: @organisation.name,
organisation_address: @organisation.address_row, organisation_address: @organisation.address_row,

16
app/helpers/data_sharing_agreement_helper.rb

@ -23,7 +23,7 @@ module DataSharingAgreementHelper
def name_for_data_sharing_agreement(data_protection_confirmation, user) def name_for_data_sharing_agreement(data_protection_confirmation, user)
if data_protection_confirmation&.confirmed? if data_protection_confirmation&.confirmed?
data_protection_confirmation.data_protection_officer.name data_protection_confirmation.data_protection_officer_name
elsif user.is_dpo? elsif user.is_dpo?
user.name user.name
else else
@ -33,7 +33,7 @@ module DataSharingAgreementHelper
def org_name_for_data_sharing_agreement(data_protection_confirmation, user) def org_name_for_data_sharing_agreement(data_protection_confirmation, user)
if data_protection_confirmation&.confirmed? if data_protection_confirmation&.confirmed?
data_protection_confirmation.organisation.name data_protection_confirmation.organisation_name
else else
user.organisation.name user.organisation.name
end end
@ -42,11 +42,11 @@ module DataSharingAgreementHelper
# rubocop:disable Rails/HelperInstanceVariable # rubocop:disable Rails/HelperInstanceVariable
def present_section_12_2(data_protection_confirmation:, user:, organisation:) def present_section_12_2(data_protection_confirmation:, user:, organisation:)
if data_protection_confirmation&.confirmed? if data_protection_confirmation&.confirmed?
@org_address = data_protection_confirmation.organisation.address_row @org_address = data_protection_confirmation.organisation_address
@org_name = data_protection_confirmation.organisation.name @org_name = data_protection_confirmation.organisation_name
@org_phone = data_protection_confirmation.organisation.phone @org_phone = data_protection_confirmation.organisation_phone_number
@dpo_name = data_protection_confirmation.data_protection_officer.name @dpo_name = data_protection_confirmation.data_protection_officer_name
@dpo_email = data_protection_confirmation.data_protection_officer.email @dpo_email = data_protection_confirmation.data_protection_officer_email
else else
@org_name = organisation.name @org_name = organisation.name
@org_address = organisation.address_row @org_address = organisation.address_row
@ -83,7 +83,7 @@ private
def data_sharing_agreement_second_line(organisation:, user:) def data_sharing_agreement_second_line(organisation:, user:)
if organisation.data_protection_confirmed? if organisation.data_protection_confirmed?
organisation.data_protection_confirmation.data_protection_officer.name if user.support? organisation.data_protection_confirmation.data_protection_officer_name if user.support?
else else
"Data protection officer must sign" unless user.is_dpo? "Data protection officer must sign" unless user.is_dpo?
end end

1
app/services/imports/data_protection_confirmation_import_service.rb

@ -37,7 +37,6 @@ module Imports
data_protection_officer: dp_officer, data_protection_officer: dp_officer,
old_id: record_field_value(xml_document, "id"), old_id: record_field_value(xml_document, "id"),
old_org_id: record_field_value(xml_document, "institution"), old_org_id: record_field_value(xml_document, "institution"),
created_at: record_field_value(xml_document, "change-date").to_time(:utc),
signed_at: record_field_value(xml_document, "change-date").to_time(:utc), signed_at: record_field_value(xml_document, "change-date").to_time(:utc),
organisation_name: org.name, organisation_name: org.name,
organisation_address: org.address_row, organisation_address: org.address_row,

4
app/views/organisations/data_sharing_agreement.html.erb

@ -7,7 +7,7 @@
</h2> </h2>
<p class="govuk-body-m"> <p class="govuk-body-m">
<% if @data_protection_confirmation&.confirmed? %> <% if @data_protection_confirmation&.confirmed? %>
This agreement is made the <%= @data_protection_confirmation.created_at.day.ordinalize %> day of <%= @data_protection_confirmation.created_at.strftime("%B") %> <%= @data_protection_confirmation.created_at.year %> This agreement is made the <%= @data_protection_confirmation.signed_at.day.ordinalize %> day of <%= @data_protection_confirmation.signed_at.strftime("%B") %> <%= @data_protection_confirmation.signed_at.year %>
<% elsif current_user.is_dpo? %> <% elsif current_user.is_dpo? %>
This agreement is made the <%= Time.zone.now.day.ordinalize %> day of <%= Time.zone.now.strftime("%B") %> <%= Time.zone.now.year %> This agreement is made the <%= Time.zone.now.day.ordinalize %> day of <%= Time.zone.now.strftime("%B") %> <%= Time.zone.now.year %>
<% else %> <% else %>
@ -16,7 +16,7 @@
</p> </p>
<p class="govuk-body-m"><strong>between</strong></p> <p class="govuk-body-m"><strong>between</strong></p>
<% if @data_protection_confirmation&.confirmed? %> <% if @data_protection_confirmation&.confirmed? %>
<p class="govuk-body-m">1) <%= @data_protection_confirmation.organisation.name %> of <%= @data_protection_confirmation.organisation.address_row %> (“CORE Data Provider”)</p> <p class="govuk-body-m">1) <%= @data_protection_confirmation.organisation_name %> of <%= @data_protection_confirmation.organisation_address %> (“CORE Data Provider”)</p>
<% else %> <% else %>
<p class="govuk-body-m">1) <%= @organisation.name %> of <%= @organisation.address_row %> (“CORE Data Provider”)</p> <p class="govuk-body-m">1) <%= @organisation.name %> of <%= @organisation.address_row %> (“CORE Data Provider”)</p>
<% end %> <% end %>

17
lib/tasks/data_import.rake

@ -28,21 +28,4 @@ namespace :core do
raise "Type #{type} is not supported by data_import" raise "Type #{type} is not supported by data_import"
end end
end 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 end

7
spec/factories/data_protection_confirmation.rb

@ -3,11 +3,18 @@ FactoryBot.define do
organisation { association :organisation, data_protection_confirmation: instance } organisation { association :organisation, data_protection_confirmation: instance }
data_protection_officer { association :user, :data_protection_officer, organisation: (instance.organisation || organisation) } data_protection_officer { association :user, :data_protection_officer, organisation: (instance.organisation || organisation) }
organisation_name { organisation.name }
organisation_address { organisation.address_row }
organisation_phone_number { organisation.phone }
data_protection_officer_name { data_protection_officer.name }
data_protection_officer_email { data_protection_officer.email }
confirmed { true } confirmed { true }
old_org_id { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" } old_org_id { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" }
old_id { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" } old_id { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" }
created_at { Time.zone.now } created_at { Time.zone.now }
updated_at { Time.zone.now } updated_at { Time.zone.now }
signed_at { Time.zone.now }
end end
end end

2
spec/services/imports/data_protection_confirmation_import_service_spec.rb

@ -50,7 +50,6 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do
expect(confirmation.organisation_address).to eq("2 Marsham Street, London, SW1P 4DF") expect(confirmation.organisation_address).to eq("2 Marsham Street, London, SW1P 4DF")
expect(confirmation.organisation_name).to eq("DLUHC") expect(confirmation.organisation_name).to eq("DLUHC")
expect(confirmation.organisation_phone_number).to eq("123") expect(confirmation.organisation_phone_number).to eq("123")
expect(Time.zone.local_to_utc(confirmation.created_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49))
expect(Time.zone.local_to_utc(confirmation.signed_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49)) expect(Time.zone.local_to_utc(confirmation.signed_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49))
end end
end end
@ -73,7 +72,6 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do
expect(confirmation.organisation_address).to eq("2 Marsham Street, London, SW1P 4DF") expect(confirmation.organisation_address).to eq("2 Marsham Street, London, SW1P 4DF")
expect(confirmation.organisation_name).to eq("DLUHC") expect(confirmation.organisation_name).to eq("DLUHC")
expect(confirmation.organisation_phone_number).to eq("123") expect(confirmation.organisation_phone_number).to eq("123")
expect(Time.zone.local_to_utc(confirmation.created_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49))
expect(Time.zone.local_to_utc(confirmation.signed_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49)) expect(Time.zone.local_to_utc(confirmation.signed_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49))
end end

6
spec/views/organisations/data_sharing_agreement.html.erb_spec.rb

@ -41,7 +41,7 @@ RSpec.describe "organisations/data_sharing_agreement.html.erb", :aggregate_failu
create( create(
:data_protection_confirmation, :data_protection_confirmation,
organisation:, organisation:,
created_at: Time.zone.now - 1.day, signed_at: Time.zone.now - 1.day,
) )
end end
@ -85,7 +85,7 @@ RSpec.describe "organisations/data_sharing_agreement.html.erb", :aggregate_failu
create( create(
:data_protection_confirmation, :data_protection_confirmation,
organisation:, organisation:,
created_at: Time.zone.now - 1.day, signed_at: Time.zone.now - 1.day,
data_protection_officer: dpo, data_protection_officer: dpo,
) )
end end
@ -137,7 +137,7 @@ RSpec.describe "organisations/data_sharing_agreement.html.erb", :aggregate_failu
create( create(
:data_protection_confirmation, :data_protection_confirmation,
organisation:, organisation:,
created_at: Time.zone.now - 1.day, signed_at: Time.zone.now - 1.day,
) )
end end

Loading…
Cancel
Save