diff --git a/app/components/create_log_actions_component.rb b/app/components/create_log_actions_component.rb index 9ae37d67a..97b3e8ffa 100644 --- a/app/components/create_log_actions_component.rb +++ b/app/components/create_log_actions_component.rb @@ -13,10 +13,10 @@ class CreateLogActionsComponent < ViewComponent::Base def display_actions? return false if bulk_upload.present? - return true unless FeatureToggle.new_data_sharing_agreement? + return true unless FeatureToggle.new_data_protection_confirmation? return true if user.support? - user.organisation.data_sharing_agreement.present? + user.organisation.data_protection_confirmation&.confirmed? end def create_button_href diff --git a/app/components/data_sharing_agreement_banner_component.rb b/app/components/data_sharing_agreement_banner_component.rb index b47ae7fb3..a9d15bdc9 100644 --- a/app/components/data_sharing_agreement_banner_component.rb +++ b/app/components/data_sharing_agreement_banner_component.rb @@ -11,15 +11,14 @@ class DataSharingAgreementBannerComponent < ViewComponent::Base end def display_banner? - return false unless FeatureToggle.new_data_sharing_agreement? + return false unless FeatureToggle.new_data_protection_confirmation? return false if user.is_dpo? return false if user.support? && organisation.blank? - if organisation.present? - !DataSharingAgreement.exists?(organisation:) - else - !DataSharingAgreement.exists?(organisation: user.organisation) - end + !DataProtectionConfirmation.exists?( + organisation: (organisation.presence || user.organisation), + confirmed: true, + ) end def data_sharing_agreement_href diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index a1f8c595d..6fea6ec75 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -157,28 +157,36 @@ class OrganisationsController < ApplicationController end def data_sharing_agreement - return render_not_found unless FeatureToggle.new_data_sharing_agreement? + return render_not_found unless FeatureToggle.new_data_protection_confirmation? - @data_sharing_agreement = current_user.organisation.data_sharing_agreement + @data_protection_confirmation = current_user.organisation.data_protection_confirmation end def confirm_data_sharing_agreement - return render_not_found unless FeatureToggle.new_data_sharing_agreement? + return render_not_found unless FeatureToggle.new_data_protection_confirmation? return render_not_found unless current_user.is_dpo? - return render_not_found if @organisation.data_sharing_agreement.present? + return render_not_found if @organisation.latest_data_protection_confirmation&.confirmed? - data_sharing_agreement = DataSharingAgreement.new( + + if @organisation.latest_data_protection_confirmation + @organisation.latest_data_protection_confirmation.update!( + confirmed: true, + data_protection_officer: current_user, + # When it was signed + created_at: Time.zone.now, + + ) + dpo.confirmed = true + dpo.data_protection_officer = current_user + dpo.save! + + data_protection_confirmation = DataProtectionConfirmation.new( organisation: current_user.organisation, - signed_at: Time.zone.now, + confirmed: true, data_protection_officer: current_user, - organisation_name: @organisation.name, - organisation_address: @organisation.address_row, - organisation_phone_number: @organisation.phone, - dpo_email: current_user.email, - dpo_name: current_user.name, ) - if data_sharing_agreement.save + if data_protection_confirmation.save flash[:notice] = "You have accepted the Data Sharing Agreement" flash[:notification_banner_body] = "Your organisation can now submit logs." diff --git a/app/helpers/data_sharing_agreement_helper.rb b/app/helpers/data_sharing_agreement_helper.rb index 365bb20cc..e3750a5fa 100644 --- a/app/helpers/data_sharing_agreement_helper.rb +++ b/app/helpers/data_sharing_agreement_helper.rb @@ -31,22 +31,22 @@ module DataSharingAgreementHelper end end - def org_name_for_data_sharing_agreement(data_sharing_agreement, user) - if data_sharing_agreement.present? - data_sharing_agreement.organisation_name + def org_name_for_data_sharing_agreement(data_protection_confirmation, user) + if data_protection_confirmation&.confirmed? + data_protection_confirmation.organisation.name else user.organisation.name end end # rubocop:disable Rails/HelperInstanceVariable - def section_12_2(data_sharing_agreement:, user:, organisation:) - if data_sharing_agreement - @org_address = data_sharing_agreement.organisation_address - @org_name = data_sharing_agreement.organisation_name - @org_phone = data_sharing_agreement.organisation_phone_number - @dpo_name = data_sharing_agreement.dpo_name - @dpo_email = data_sharing_agreement.dpo_email + def section_12_2(data_protection_confirmation:, user:, organisation:) + if data_protection_confirmation&.confirmed? + @org_address = data_protection_confirmation.organisation.address_row + @org_name = data_protection_confirmation.organisation.name + @org_phone = data_protection_confirmation.organisation.phone + @dpo_name = data_protection_confirmation.data_protection_officer.name + @dpo_email = data_protection_confirmation.data_protection_officer.email else @org_name = organisation.name @org_address = organisation.address_row @@ -68,18 +68,18 @@ module DataSharingAgreementHelper private def data_sharing_agreement_first_line(organisation:, user:) - return "Not accepted" if organisation.data_sharing_agreement.blank? + return "Not accepted" if organisation.data_protection_confirmation&.confirmed? if user.support? - "Accepted #{organisation.data_sharing_agreement.signed_at.strftime('%d/%m/%Y')}" + "Accepted #{organisation.data_protection_confirmation.created_at.strftime('%d/%m/%Y')}" else "Accepted" end end def data_sharing_agreement_second_line(organisation:, user:) - if organisation.data_sharing_agreement.present? - organisation.data_sharing_agreement.dpo_name if user.support? + if organisation.data_protection_confirmation&.confirmed? + organisation.data_sharing_agreement.data_protection_officer.name if user.support? else "Data protection officer must sign" unless user.is_dpo? end diff --git a/app/models/log.rb b/app/models/log.rb index 3e37489b3..65f9c56e3 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -179,8 +179,9 @@ class Log < ApplicationRecord private def verify_dsa_signed + return unless FeatureToggle.new_data_protection_confirmation? return unless owning_organisation - return if owning_organisation.data_sharing_agreement.present? + return if owning_organisation.data_protection_confirmation&.confirmed? errors.add :owning_organisation, I18n.t("validations.organisation.data_sharing_agreement_not_signed") end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index cd2fd8c38..b11c07028 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -3,8 +3,7 @@ class Organisation < ApplicationRecord has_many :owned_lettings_logs, class_name: "LettingsLog", foreign_key: "owning_organisation_id", dependent: :delete_all has_many :managed_lettings_logs, class_name: "LettingsLog", foreign_key: "managing_organisation_id" has_many :owned_sales_logs, class_name: "SalesLog", foreign_key: "owning_organisation_id", dependent: :delete_all - has_many :data_protection_confirmations - has_one :data_sharing_agreement + has_one :data_protection_confirmation has_many :organisation_rent_periods has_many :owned_schemes, class_name: "Scheme", foreign_key: "owning_organisation_id", dependent: :delete_all has_many :parent_organisation_relationships, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" @@ -103,7 +102,7 @@ class Organisation < ApplicationRecord end def display_organisation_attributes - [ + attrs = [ { name: "Name", value: name, editable: true }, { name: "Address", value: address_string, editable: true }, { name: "Telephone_number", value: phone, editable: true }, @@ -111,8 +110,13 @@ class Organisation < ApplicationRecord { name: "Registration number", value: housing_registration_no || "", editable: false }, { name: "Rent_periods", value: rent_period_labels, editable: false, format: :bullet }, { name: "Owns housing stock", value: holds_own_stock ? "Yes" : "No", editable: false }, - { name: "Data protection agreement", value: data_protection_agreement_string, editable: false }, ].compact + + unless FeatureToggle.new_data_protection_confirmation? + attrs << { name: "Data protection agreement", value: data_protection_agreement_string, editable: false } + end + + attrs end def has_managing_agents? diff --git a/app/services/feature_toggle.rb b/app/services/feature_toggle.rb index f270f874b..edaa02fd7 100644 --- a/app/services/feature_toggle.rb +++ b/app/services/feature_toggle.rb @@ -42,7 +42,7 @@ class FeatureToggle !Rails.env.production? end - def self.new_data_sharing_agreement? + def self.new_data_protection_confirmation? !Rails.env.production? end end diff --git a/app/views/logs/_create_for_org_actions.html.erb b/app/views/logs/_create_for_org_actions.html.erb index 2320e7857..83cd1f27e 100644 --- a/app/views/logs/_create_for_org_actions.html.erb +++ b/app/views/logs/_create_for_org_actions.html.erb @@ -1,5 +1,5 @@