From a89c1ce42f7b21fe24f62966546b33a718ac2d59 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 29 Feb 2024 09:23:16 +0000 Subject: [PATCH] Display banner when org holds no stock --- .../create_log_actions_component.rb | 10 +----- ...rotection_confirmation_banner_component.rb | 17 ++++++++-- app/models/organisation.rb | 8 +++++ ...tion_confirmation_banner_component_spec.rb | 34 +++++++++++++++++++ 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/app/components/create_log_actions_component.rb b/app/components/create_log_actions_component.rb index c975dc73b..80124e22e 100644 --- a/app/components/create_log_actions_component.rb +++ b/app/components/create_log_actions_component.rb @@ -15,7 +15,7 @@ class CreateLogActionsComponent < ViewComponent::Base return false if bulk_upload.present? return true if user.support? - organisation_or_stock_owner_signed_dsa_and_holds_own_stock?(user.organisation) + user.organisation.organisation_or_stock_owner_signed_dsa_and_holds_own_stock? end def create_button_href @@ -53,12 +53,4 @@ class CreateLogActionsComponent < ViewComponent::Base bulk_upload_sales_log_path(id: "start") end end - - def organisation_or_stock_owner_signed_dsa_and_holds_own_stock?(organisation) - return true if organisation.data_protection_confirmed? && organisation.holds_own_stock? - return true if organisation.stock_owners.any? { |stock_owner| stock_owner.data_protection_confirmed? && stock_owner.holds_own_stock? } - return true if organisation.absorbed_organisations.any? { |stock_owner| stock_owner.data_protection_confirmed? && stock_owner.holds_own_stock? } - - false - end end diff --git a/app/components/data_protection_confirmation_banner_component.rb b/app/components/data_protection_confirmation_banner_component.rb index 745c79e20..195df3580 100644 --- a/app/components/data_protection_confirmation_banner_component.rb +++ b/app/components/data_protection_confirmation_banner_component.rb @@ -13,13 +13,16 @@ class DataProtectionConfirmationBannerComponent < ViewComponent::Base def display_banner? return false if user.support? && organisation.blank? return true if org_without_dpo? + return false if !org_or_user_org.holds_own_stock? && org_or_user_org.stock_owners.empty? && org_or_user_org.absorbed_organisations.empty? - !org_or_user_org.data_protection_confirmed? + !org_or_user_org.organisation_or_stock_owner_signed_dsa_and_holds_own_stock? end def header_text if org_without_dpo? "To create logs your organisation must state a data protection officer. They must sign the Data Sharing Agreement." + elsif !org_or_user_org.holds_own_stock? + "Your organisation does not own stock. To create logs your stock owner(s) must accept the Data Sharing Agreement on CORE." elsif user.is_dpo? "Your organisation must accept the Data Sharing Agreement before you can create any logs." else @@ -28,7 +31,7 @@ class DataProtectionConfirmationBannerComponent < ViewComponent::Base end def banner_text - if org_without_dpo? || user.is_dpo? + if org_without_dpo? || user.is_dpo? || !org_or_user_org.holds_own_stock? govuk_link_to( link_text, link_href, @@ -50,13 +53,21 @@ private def link_text if dpo_required? "Contact helpdesk to assign a data protection officer" + elsif !org_or_user_org.holds_own_stock? + "View or add stock owners" else "Read the Data Sharing Agreement" end end def link_href - dpo_required? ? GlobalConstants::HELPDESK_URL : data_sharing_agreement_organisation_path(org_or_user_org) + if dpo_required? + GlobalConstants::HELPDESK_URL + elsif !org_or_user_org.holds_own_stock? + stock_owners_organisation_path(org_or_user_org) + else + data_sharing_agreement_organisation_path(org_or_user_org) + end end def dpo_required? diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 76d14dfde..0a852d2fd 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -159,4 +159,12 @@ class Organisation < ApplicationRecord def has_recent_absorbed_organisations? absorbed_organisations&.merged_during_open_collection_period.present? end + + def organisation_or_stock_owner_signed_dsa_and_holds_own_stock? + return true if data_protection_confirmed? && holds_own_stock? + return true if stock_owners.any? { |stock_owner| stock_owner.data_protection_confirmed? && stock_owner.holds_own_stock? } + return true if absorbed_organisations.any? { |stock_owner| stock_owner.data_protection_confirmed? && stock_owner.holds_own_stock? } + + false + end end diff --git a/spec/components/data_protection_confirmation_banner_component_spec.rb b/spec/components/data_protection_confirmation_banner_component_spec.rb index be10f9689..faab1d169 100644 --- a/spec/components/data_protection_confirmation_banner_component_spec.rb +++ b/spec/components/data_protection_confirmation_banner_component_spec.rb @@ -68,6 +68,40 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do expect(component.display_banner?).to eq(false) expect(render.content).to be_empty end + + context "and doesn't own stock" do + before do + organisation.update!(holds_own_stock: false) + end + + context "and has a parent organisation that owns stock and has signed DSA" do + before do + parent_organisation = create(:organisation, holds_own_stock: true) + create(:organisation_relationship, child_organisation: organisation, parent_organisation:) + end + + it "does not display banner" do + expect(component.display_banner?).to eq(false) + expect(render.content).to be_empty + end + end + + context "and has a parent organisation that hasn't signed DSA" do + before do + parent_organisation = create(:organisation, :without_dpc, holds_own_stock: true) + create(:organisation_relationship, child_organisation: organisation, parent_organisation:) + end + + it "displays the banner and asks to create stock owners" do + expect(component.display_banner?).to eq(true) + expect(render).to have_link( + "View or add stock owners", + href: "/organisations/#{organisation.id}/stock-owners", + ) + expect(render).to have_selector("p", text: "Your organisation does not own stock. To create logs your stock owner(s) must accept the Data Sharing Agreement on CORE.") + end + end + end end context "when org does not have a DPO" do