15 changed files with 481 additions and 39 deletions
@ -0,0 +1,10 @@ |
|||||||
|
<% if display_actions? %> |
||||||
|
<div class="govuk-button-group app-filter-toggle govuk-!-margin-bottom-6"> |
||||||
|
<% if create_button_href.present? %> |
||||||
|
<%= govuk_button_to create_button_copy, create_button_href, class: "govuk-!-margin-right-6" %> |
||||||
|
<% end %> |
||||||
|
<% if upload_button_href.present? %> |
||||||
|
<%= govuk_button_to upload_button_copy, upload_button_href, secondary: true %> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
<% end %> |
||||||
@ -0,0 +1,55 @@ |
|||||||
|
class CreateLogActionsComponent < ViewComponent::Base |
||||||
|
include Rails.application.routes.url_helpers |
||||||
|
|
||||||
|
attr_reader :bulk_upload, :user, :log_type |
||||||
|
|
||||||
|
def initialize(user:, log_type:, bulk_upload: nil) |
||||||
|
@bulk_upload = bulk_upload |
||||||
|
@user = user |
||||||
|
@log_type = log_type |
||||||
|
|
||||||
|
super |
||||||
|
end |
||||||
|
|
||||||
|
def display_actions? |
||||||
|
return false if bulk_upload.present? |
||||||
|
return true unless FeatureToggle.new_data_sharing_agreement? |
||||||
|
return true if user.support? |
||||||
|
|
||||||
|
user.organisation.data_sharing_agreement.present? |
||||||
|
end |
||||||
|
|
||||||
|
def create_button_href |
||||||
|
case log_type |
||||||
|
when "lettings" |
||||||
|
lettings_logs_path |
||||||
|
when "sales" |
||||||
|
sales_logs_path |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def create_button_copy |
||||||
|
case log_type |
||||||
|
when "lettings" |
||||||
|
"Create a new lettings log" |
||||||
|
when "sales" |
||||||
|
"Create a new sales log" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def upload_button_copy |
||||||
|
if log_type == "lettings" |
||||||
|
"Upload lettings logs in bulk" |
||||||
|
elsif FeatureToggle.bulk_upload_sales_logs? && log_type == "sales" |
||||||
|
"Upload sales logs in bulk" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def upload_button_href |
||||||
|
if log_type == "lettings" |
||||||
|
bulk_upload_lettings_log_path(id: "start") |
||||||
|
elsif FeatureToggle.bulk_upload_sales_logs? && log_type == "sales" |
||||||
|
bulk_upload_sales_log_path(id: "start") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
<% if display_banner? %> |
||||||
|
<%= govuk_notification_banner(title_text: "Important") do %> |
||||||
|
<p class="govuk-notification-banner__heading govuk-!-width-full" style="max-width: fit-content"> |
||||||
|
Your organisation must accept the Data Sharing Agreement before you can create any logs. |
||||||
|
<p> |
||||||
|
<%= govuk_link_to( |
||||||
|
"Read the Data Sharing Agreement", |
||||||
|
data_sharing_agreement_href, |
||||||
|
class: "govuk-notification-banner__link govuk-!-font-weight-bold" |
||||||
|
) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
class DataSharingAgreementBannerComponent < ViewComponent::Base |
||||||
|
include Rails.application.routes.url_helpers |
||||||
|
|
||||||
|
attr_reader :user, :organisation |
||||||
|
|
||||||
|
def initialize(user:, organisation: nil) |
||||||
|
@user = user |
||||||
|
@organisation = organisation |
||||||
|
|
||||||
|
super |
||||||
|
end |
||||||
|
|
||||||
|
def display_banner? |
||||||
|
return false unless FeatureToggle.new_data_sharing_agreement? |
||||||
|
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 |
||||||
|
end |
||||||
|
|
||||||
|
def data_sharing_agreement_href |
||||||
|
data_sharing_agreement_organisation_path(organisation.presence || user.organisation) |
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,10 @@ |
|||||||
|
<div class="govuk-button-group app-filter-toggle"> |
||||||
|
<% if !FeatureToggle.new_data_sharing_agreement? || @organisation.data_sharing_agreement.present? %> |
||||||
|
<% if current_page?(controller: 'organisations', action: 'lettings_logs') %> |
||||||
|
<%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %> |
||||||
|
<% end %> |
||||||
|
<% if current_page?(controller: 'organisations', action: 'sales_logs') %> |
||||||
|
<%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
@ -0,0 +1,170 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe CreateLogActionsComponent, type: :component do |
||||||
|
include GovukComponentsHelper |
||||||
|
include GovukLinkHelper |
||||||
|
let(:component) { described_class.new(user:, log_type:, bulk_upload:) } |
||||||
|
let(:render) { render_inline(component) } |
||||||
|
|
||||||
|
let(:log_type) { "lettings" } |
||||||
|
let(:user) { create(:user) } |
||||||
|
|
||||||
|
context "when bulk upload present" do |
||||||
|
let(:bulk_upload) { true } |
||||||
|
|
||||||
|
it "does not render actions" do |
||||||
|
expect(component.display_actions?).to eq(false) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when bulk upload nil" do |
||||||
|
let(:bulk_upload) { nil } |
||||||
|
|
||||||
|
context "when flag disabled" do |
||||||
|
before do |
||||||
|
allow(FeatureToggle).to receive(:new_data_sharing_agreement?).and_return(false) |
||||||
|
end |
||||||
|
|
||||||
|
it "renders actions" do |
||||||
|
expect(component.display_actions?).to eq(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button copy" do |
||||||
|
expect(component.create_button_copy).to eq("Create a new lettings log") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button href" do |
||||||
|
render |
||||||
|
expect(component.create_button_href).to eq("/lettings-logs") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns upload button copy" do |
||||||
|
expect(component.upload_button_copy).to eq("Upload lettings logs in bulk") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns upload button href" do |
||||||
|
render |
||||||
|
expect(component.upload_button_href).to eq("/lettings-logs/bulk-upload-logs/start") |
||||||
|
end |
||||||
|
|
||||||
|
context "when sales log type" do |
||||||
|
let(:log_type) { "sales" } |
||||||
|
|
||||||
|
it "renders actions" do |
||||||
|
expect(component.display_actions?).to eq(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button copy" do |
||||||
|
expect(component.create_button_copy).to eq("Create a new sales log") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button href" do |
||||||
|
render |
||||||
|
expect(component.create_button_href).to eq("/sales-logs") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when flag enabled" do |
||||||
|
before do |
||||||
|
allow(FeatureToggle).to receive(:new_data_sharing_agreement?).and_return(true) |
||||||
|
end |
||||||
|
|
||||||
|
context "when support user" do |
||||||
|
let(:user) { create(:user, :support) } |
||||||
|
|
||||||
|
it "renders actions" do |
||||||
|
expect(component.display_actions?).to eq(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button copy" do |
||||||
|
expect(component.create_button_copy).to eq("Create a new lettings log") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button href" do |
||||||
|
render |
||||||
|
expect(component.create_button_href).to eq("/lettings-logs") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns upload button copy" do |
||||||
|
expect(component.upload_button_copy).to eq("Upload lettings logs in bulk") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns upload button href" do |
||||||
|
render |
||||||
|
expect(component.upload_button_href).to eq("/lettings-logs/bulk-upload-logs/start") |
||||||
|
end |
||||||
|
|
||||||
|
context "when sales log type" do |
||||||
|
let(:log_type) { "sales" } |
||||||
|
|
||||||
|
it "renders actions" do |
||||||
|
expect(component.display_actions?).to eq(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button copy" do |
||||||
|
expect(component.create_button_copy).to eq("Create a new sales log") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button href" do |
||||||
|
render |
||||||
|
expect(component.create_button_href).to eq("/sales-logs") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when not support user" do |
||||||
|
context "without data sharing agreement" do |
||||||
|
let(:user) { create(:user, organisation: create(:organisation, :without_dsa)) } |
||||||
|
|
||||||
|
it "does not render actions" do |
||||||
|
expect(component.display_actions?).to eq(false) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when has data sharing agremeent" do |
||||||
|
let(:user) { create(:user, :support) } |
||||||
|
|
||||||
|
it "renders actions" do |
||||||
|
expect(component.display_actions?).to eq(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button copy" do |
||||||
|
expect(component.create_button_copy).to eq("Create a new lettings log") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button href" do |
||||||
|
render |
||||||
|
expect(component.create_button_href).to eq("/lettings-logs") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns upload button copy" do |
||||||
|
expect(component.upload_button_copy).to eq("Upload lettings logs in bulk") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns upload button href" do |
||||||
|
render |
||||||
|
expect(component.upload_button_href).to eq("/lettings-logs/bulk-upload-logs/start") |
||||||
|
end |
||||||
|
|
||||||
|
context "when sales log type" do |
||||||
|
let(:log_type) { "sales" } |
||||||
|
|
||||||
|
it "renders actions" do |
||||||
|
expect(component.display_actions?).to eq(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button copy" do |
||||||
|
expect(component.create_button_copy).to eq("Create a new sales log") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns create button href" do |
||||||
|
render |
||||||
|
expect(component.create_button_href).to eq("/sales-logs") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,120 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe DataSharingAgreementBannerComponent, type: :component do |
||||||
|
let(:component) { described_class.new(user:, organisation:) } |
||||||
|
let(:render) { render_inline(component) } |
||||||
|
let(:user) { create(:user) } |
||||||
|
let(:organisation) { user.organisation } |
||||||
|
|
||||||
|
context "when flag disabled" do |
||||||
|
before do |
||||||
|
allow(FeatureToggle).to receive(:new_data_sharing_agreement?).and_return(false) |
||||||
|
end |
||||||
|
|
||||||
|
it "does not display banner" do |
||||||
|
expect(component.display_banner?).to eq(false) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when flag enabled" do |
||||||
|
before do |
||||||
|
allow(FeatureToggle).to receive(:new_data_sharing_agreement?).and_return(true) |
||||||
|
end |
||||||
|
|
||||||
|
context "when user is dpo" do |
||||||
|
let(:user) { create(:user, is_dpo: true) } |
||||||
|
|
||||||
|
it "does not display banner" do |
||||||
|
expect(component.display_banner?).to eq(false) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when user is not support and not dpo" do |
||||||
|
let(:user) { create(:user) } |
||||||
|
|
||||||
|
context "when org blank" do |
||||||
|
let(:organisation) { nil } |
||||||
|
|
||||||
|
before do |
||||||
|
allow(DataSharingAgreement).to receive(:exists?).and_call_original |
||||||
|
end |
||||||
|
|
||||||
|
context "when data sharing agreement present" do |
||||||
|
it "does not display banner" do |
||||||
|
expect(component.display_banner?).to eq(false) |
||||||
|
end |
||||||
|
|
||||||
|
it "verifies DSA exists for organisation" do |
||||||
|
render |
||||||
|
expect(DataSharingAgreement).to have_received(:exists?).with(organisation: user.organisation) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when data sharing agreement not present" do |
||||||
|
let(:user) { create(:user, organisation: create(:organisation, :without_dsa)) } |
||||||
|
|
||||||
|
it "displays the banner" do |
||||||
|
expect(component.display_banner?).to eq(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "produces the correct link" do |
||||||
|
render |
||||||
|
expect(component.data_sharing_agreement_href).to eq("/organisations/#{user.organisation.id}/data-sharing-agreement") |
||||||
|
end |
||||||
|
|
||||||
|
it "verifies DSA exists for organisation" do |
||||||
|
render |
||||||
|
expect(DataSharingAgreement).to have_received(:exists?).with(organisation: user.organisation) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when user is support" do |
||||||
|
let(:user) { create(:user, :support) } |
||||||
|
|
||||||
|
context "when org blank" do |
||||||
|
let(:organisation) { nil } |
||||||
|
|
||||||
|
it "does not display banner" do |
||||||
|
expect(component.display_banner?).to eq(false) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when org present" do |
||||||
|
before do |
||||||
|
allow(DataSharingAgreement).to receive(:exists?).and_call_original |
||||||
|
end |
||||||
|
|
||||||
|
context "when data sharing agreement present" do |
||||||
|
it "does not display banner" do |
||||||
|
expect(component.display_banner?).to eq(false) |
||||||
|
end |
||||||
|
|
||||||
|
it "verifies DSA exists for organisation" do |
||||||
|
render |
||||||
|
expect(DataSharingAgreement).to have_received(:exists?).with(organisation:) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when data sharing agreement not present" do |
||||||
|
let(:organisation) { create(:organisation, :without_dsa) } |
||||||
|
|
||||||
|
it "displays the banner" do |
||||||
|
expect(component.display_banner?).to eq(true) |
||||||
|
end |
||||||
|
|
||||||
|
it "produces the correct link" do |
||||||
|
render |
||||||
|
expect(component.data_sharing_agreement_href).to eq("/organisations/#{organisation.id}/data-sharing-agreement") |
||||||
|
end |
||||||
|
|
||||||
|
it "verifies DSA exists for organisation" do |
||||||
|
render |
||||||
|
expect(DataSharingAgreement).to have_received(:exists?).with(organisation:) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,50 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe "logs/_create_for_org_actions.html.erb" do |
||||||
|
before do |
||||||
|
allow(view).to receive(:current_user).and_return(user) |
||||||
|
allow(view).to receive(:current_page?).and_return(true) |
||||||
|
assign(:organisation, user.organisation) |
||||||
|
end |
||||||
|
|
||||||
|
let(:fragment) { Capybara::Node::Simple.new(rendered) } |
||||||
|
|
||||||
|
let(:user) { create(:user) } |
||||||
|
|
||||||
|
context "when flag disabled" do |
||||||
|
before do |
||||||
|
allow(FeatureToggle).to receive(:new_data_sharing_agreement?).and_return(false) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows create buttons" do |
||||||
|
render |
||||||
|
|
||||||
|
expect(fragment).to have_button("Create a new lettings log for this organisation") |
||||||
|
expect(fragment).to have_button("Create a new sales log for this organisation") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when flag enabled" do |
||||||
|
before do |
||||||
|
allow(FeatureToggle).to receive(:new_data_sharing_agreement?).and_return(true) |
||||||
|
end |
||||||
|
|
||||||
|
context "with data sharing agreement" do |
||||||
|
it "does include create log buttons" do |
||||||
|
render |
||||||
|
expect(fragment).to have_button("Create a new lettings log for this organisation") |
||||||
|
expect(fragment).to have_button("Create a new sales log for this organisation") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "without data sharing agreement" do |
||||||
|
let(:user) { create(:user, organisation: create(:organisation, :without_dsa)) } |
||||||
|
|
||||||
|
it "does not include create log buttons" do |
||||||
|
render |
||||||
|
expect(fragment).not_to have_button("Create a new lettings log for this organisation") |
||||||
|
expect(fragment).not_to have_button("Create a new sales log for this organisation") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
Loading…
Reference in new issue