Browse Source

Address PO review

pull/1684/head
Jack S 3 years ago
parent
commit
c4b2548e63
  1. 14
      app/components/data_protection_confirmation_banner_component.html.erb
  2. 19
      app/components/data_protection_confirmation_banner_component.rb
  3. 1
      app/models/organisation.rb
  4. 2
      app/views/logs/index.html.erb
  5. 2
      app/views/organisations/logs.html.erb
  6. 18
      spec/components/data_protection_confirmation_banner_component_spec.rb

14
app/components/data_sharing_agreement_banner_component.html.erb → app/components/data_protection_confirmation_banner_component.html.erb

@ -3,10 +3,14 @@
<p class="govuk-notification-banner__heading govuk-!-width-full" style="max-width: fit-content"> <p class="govuk-notification-banner__heading govuk-!-width-full" style="max-width: fit-content">
<%= I18n.t("validations.organisation.data_sharing_agreement_not_signed") %> <%= I18n.t("validations.organisation.data_sharing_agreement_not_signed") %>
<p> <p>
<%= govuk_link_to( <% if user.is_dpo? %>
"Read the Data Sharing Agreement", <%= govuk_link_to(
data_sharing_agreement_href, "Read the Data Sharing Agreement",
class: "govuk-notification-banner__link govuk-!-font-weight-bold", data_sharing_agreement_href,
) %> class: "govuk-notification-banner__link govuk-!-font-weight-bold",
) %>
<% else %>
<%= data_protection_officers_text %>
<% end %>
<% end %> <% end %>
<% end %> <% end %>

19
app/components/data_sharing_agreement_banner_component.rb → 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 include Rails.application.routes.url_helpers
attr_reader :user, :organisation attr_reader :user, :organisation
@ -12,16 +12,27 @@ class DataSharingAgreementBannerComponent < ViewComponent::Base
def display_banner? def display_banner?
return false unless FeatureToggle.new_data_protection_confirmation? return false unless FeatureToggle.new_data_protection_confirmation?
return false if user.is_dpo?
return false if user.support? && organisation.blank? return false if user.support? && organisation.blank?
!DataProtectionConfirmation.exists?( !DataProtectionConfirmation.exists?(
organisation: (organisation.presence || user.organisation), organisation: org_or_user_org,
confirmed: true, confirmed: true,
) )
end 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 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
end end

1
app/models/organisation.rb

@ -1,5 +1,6 @@
class Organisation < ApplicationRecord class Organisation < ApplicationRecord
has_many :users, dependent: :delete_all 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 :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 :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 :owned_sales_logs, class_name: "SalesLog", foreign_key: "owning_organisation_id", dependent: :delete_all

2
app/views/logs/index.html.erb

@ -3,7 +3,7 @@
<% content_for :title, title %> <% content_for :title, title %>
<%= render DataSharingAgreementBannerComponent.new( <%= render DataProtectionConfirmationBannerComponent.new(
user: current_user, user: current_user,
organisation: @organisation, organisation: @organisation,
) %> ) %>

2
app/views/organisations/logs.html.erb

@ -5,7 +5,7 @@
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= render DataSharingAgreementBannerComponent.new( <%= render DataProtectionConfirmationBannerComponent.new(
user: current_user, user: current_user,
organisation: @organisation, organisation: @organisation,
) %> ) %>

18
spec/components/data_sharing_agreement_banner_component_spec.rb → spec/components/data_protection_confirmation_banner_component_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe DataSharingAgreementBannerComponent, type: :component do RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
let(:component) { described_class.new(user:, organisation:) } let(:component) { described_class.new(user:, organisation:) }
let(:render) { render_inline(component) } let(:render) { render_inline(component) }
let(:user) { create(:user) } 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) allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(true)
end end
context "when user is dpo" do describe "#data_protection_officers_text" do
let(:user) { create(:user, is_dpo: true) } 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 context "with two DPOs" do
expect(component.display_banner?).to eq(false) 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
end end
Loading…
Cancel
Save