diff --git a/app/components/data_sharing_agreement_banner_component.html.erb b/app/components/data_protection_confirmation_banner_component.html.erb similarity index 51% rename from app/components/data_sharing_agreement_banner_component.html.erb rename to app/components/data_protection_confirmation_banner_component.html.erb index 3b0a82450..8f75081a1 100644 --- a/app/components/data_sharing_agreement_banner_component.html.erb +++ b/app/components/data_protection_confirmation_banner_component.html.erb @@ -3,10 +3,14 @@
- <%= govuk_link_to( - "Read the Data Sharing Agreement", - data_sharing_agreement_href, - class: "govuk-notification-banner__link govuk-!-font-weight-bold", - ) %> + <% if user.is_dpo? %> + <%= govuk_link_to( + "Read the Data Sharing Agreement", + data_sharing_agreement_href, + class: "govuk-notification-banner__link govuk-!-font-weight-bold", + ) %> + <% else %> + <%= data_protection_officers_text %> + <% end %> <% end %> <% end %> diff --git a/app/components/data_sharing_agreement_banner_component.rb b/app/components/data_protection_confirmation_banner_component.rb similarity index 51% rename from app/components/data_sharing_agreement_banner_component.rb rename to app/components/data_protection_confirmation_banner_component.rb index a9d15bdc9..b1dc61152 100644 --- a/app/components/data_sharing_agreement_banner_component.rb +++ b/app/components/data_protection_confirmation_banner_component.rb @@ -1,4 +1,4 @@ -class DataSharingAgreementBannerComponent < ViewComponent::Base +class DataProtectionConfirmationBannerComponent < ViewComponent::Base include Rails.application.routes.url_helpers attr_reader :user, :organisation @@ -12,16 +12,27 @@ class DataSharingAgreementBannerComponent < ViewComponent::Base def display_banner? return false unless FeatureToggle.new_data_protection_confirmation? - return false if user.is_dpo? return false if user.support? && organisation.blank? !DataProtectionConfirmation.exists?( - organisation: (organisation.presence || user.organisation), + organisation: org_or_user_org, confirmed: true, ) end + def data_protection_officers_text + if org_or_user_org.data_protection_officers.any? + "You can ask: #{org_or_user_org.data_protection_officers.map(&:name).join(', ')}" + end + end + def data_sharing_agreement_href - data_sharing_agreement_organisation_path(organisation.presence || user.organisation) + data_sharing_agreement_organisation_path(org_or_user_org) + end + +private + + def org_or_user_org + organisation.presence || user.organisation end end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 2096d71d1..150f3c69b 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -1,5 +1,6 @@ class Organisation < ApplicationRecord has_many :users, dependent: :delete_all + has_many :data_protection_officers, -> { where(is_dpo: true) }, class_name: "User" 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 diff --git a/app/views/logs/index.html.erb b/app/views/logs/index.html.erb index 9f29f7244..e2cc2e0d1 100644 --- a/app/views/logs/index.html.erb +++ b/app/views/logs/index.html.erb @@ -3,7 +3,7 @@ <% content_for :title, title %> -<%= render DataSharingAgreementBannerComponent.new( +<%= render DataProtectionConfirmationBannerComponent.new( user: current_user, organisation: @organisation, ) %> diff --git a/app/views/organisations/logs.html.erb b/app/views/organisations/logs.html.erb index 100aeba39..6b269590c 100644 --- a/app/views/organisations/logs.html.erb +++ b/app/views/organisations/logs.html.erb @@ -5,7 +5,7 @@ <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> -<%= render DataSharingAgreementBannerComponent.new( +<%= render DataProtectionConfirmationBannerComponent.new( user: current_user, organisation: @organisation, ) %> diff --git a/spec/components/data_sharing_agreement_banner_component_spec.rb b/spec/components/data_protection_confirmation_banner_component_spec.rb similarity index 86% rename from spec/components/data_sharing_agreement_banner_component_spec.rb rename to spec/components/data_protection_confirmation_banner_component_spec.rb index 19b9f4f60..a76db4435 100644 --- a/spec/components/data_sharing_agreement_banner_component_spec.rb +++ b/spec/components/data_protection_confirmation_banner_component_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe DataSharingAgreementBannerComponent, type: :component do +RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do let(:component) { described_class.new(user:, organisation:) } let(:render) { render_inline(component) } let(:user) { create(:user) } @@ -21,11 +21,19 @@ RSpec.describe DataSharingAgreementBannerComponent, type: :component do allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(true) end - context "when user is dpo" do - let(:user) { create(:user, is_dpo: true) } + describe "#data_protection_officers_text" do + it "returns the correct text" do + expect(component.data_protection_officers_text).to eq("You can ask: Danny Rojas") + end - it "does not display banner" do - expect(component.display_banner?).to eq(false) + context "with two DPOs" do + before do + create(:user, organisation:, is_dpo: true, name: "Test McTest") + end + + it "returns the correct text" do + expect(component.data_protection_officers_text).to eq("You can ask: Danny Rojas, Test McTest") + end end end