Browse Source

CLDC-3235 Update how we display create new logs actions (#2273)

* Update display_actions

* Display banner when org holds no stock

* Check if current org DSA is signed
pull/2318/head
kosiakkatrina 9 months ago committed by GitHub
parent
commit
b48706acac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      app/components/create_log_actions_component.rb
  2. 17
      app/components/data_protection_confirmation_banner_component.rb
  3. 8
      app/models/organisation.rb
  4. 42
      spec/components/create_log_actions_component_spec.rb
  5. 82
      spec/components/data_protection_confirmation_banner_component_spec.rb

3
app/components/create_log_actions_component.rb

@ -14,9 +14,8 @@ class CreateLogActionsComponent < ViewComponent::Base
def display_actions?
return false if bulk_upload.present?
return true if user.support?
return false if !user.organisation.holds_own_stock? && user.organisation.stock_owners.empty? && user.organisation.absorbed_organisations.empty?
user.organisation.data_protection_confirmed?
user.organisation.data_protection_confirmed? && user.organisation.organisation_or_stock_owner_signed_dsa_and_holds_own_stock?
end
def create_button_href

17
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.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? && org_or_user_org.data_protection_confirmed?
"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? && org_or_user_org.data_protection_confirmed?
"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? && org_or_user_org.data_protection_confirmed?
stock_owners_organisation_path(org_or_user_org)
else
data_sharing_agreement_organisation_path(org_or_user_org)
end
end
def dpo_required?

8
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

42
spec/components/create_log_actions_component_spec.rb

@ -74,7 +74,7 @@ RSpec.describe CreateLogActionsComponent, type: :component do
end
context "when has data sharing agremeent" do
let(:user) { create(:user, :support) }
let(:user) { create(:user) }
it "renders actions" do
expect(component.display_actions?).to eq(true)
@ -114,6 +114,46 @@ RSpec.describe CreateLogActionsComponent, type: :component do
expect(component.create_button_href).to eq("/sales-logs")
end
end
context "when organisation doesn't own stock" do
before do
user.organisation.update!(holds_own_stock: false)
end
context "and has signed DSA and stock owners have signed DSA" do
before do
parent_organisation = create(:organisation)
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation:)
end
it "renders actions" do
expect(component.display_actions?).to eq(true)
end
end
context "and hasn't signed DSA and and stock owners have signed DSA" do
before do
user.organisation.data_protection_confirmation.update!(confirmed: false)
parent_organisation = create(:organisation)
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation:)
end
it "renders actions" do
expect(component.display_actions?).to eq(false)
end
end
context "and no stock owners have signed data sharing agreement" do
before do
parent_organisation = create(:organisation, :without_dpc)
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation:)
end
it "does not render actions" do
expect(component.display_actions?).to eq(false)
end
end
end
end
end
end

82
spec/components/data_protection_confirmation_banner_component_spec.rb

@ -61,6 +61,24 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
expect(render).to have_selector("p", text: "Your organisation must accept the Data Sharing Agreement before you can create any logs.")
end
end
context "and org doesn't own stock and has a parent organisation that hasn't signed DSA" do
before do
organisation.data_protection_confirmation.update!(confirmed: false)
organisation.update!(holds_own_stock: false)
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 sign" do
expect(component.display_banner?).to eq(true)
expect(render).to have_link(
"Read the Data Sharing Agreement",
href: "/organisations/#{organisation.id}/data-sharing-agreement",
)
expect(render).to have_selector("p", text: "Your data protection officer must accept the Data Sharing Agreement on CORE before you can create any logs.")
end
end
end
context "when org has a signed data sharing agremeent" do
@ -68,6 +86,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
@ -98,6 +150,20 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
expect(render).to have_selector("p", text: "Your data protection officer must accept the Data Sharing Agreement on CORE before you can create any logs.")
expect(render).to have_selector("p", text: "You can ask: #{dpo.name}")
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 "displays the banner and shows DPOs" do
expect(component.display_banner?).to eq(true)
expect(render.css("a")).to be_empty
expect(render).to have_selector("p", text: "Your data protection officer must accept the Data Sharing Agreement on CORE before you can create any logs.")
expect(render).to have_selector("p", text: "You can ask: #{dpo.name}")
end
end
end
context "when user is a DPO" do
@ -112,6 +178,22 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
)
expect(render).to have_selector("p", text: "Your organisation must accept the Data Sharing Agreement before you can create any logs.")
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 "displays the banner and asks to sign" do
expect(component.display_banner?).to eq(true)
expect(render).to have_link(
"Read the Data Sharing Agreement",
href: "/organisations/#{organisation.id}/data-sharing-agreement",
)
expect(render).to have_selector("p", text: "Your organisation must accept the Data Sharing Agreement before you can create any logs.")
end
end
end
end

Loading…
Cancel
Save