Browse Source

Remove new_data_protection_confirmation? flag

pull/1766/head
Jack S 3 years ago
parent
commit
64093e5794
  1. 1
      app/components/create_log_actions_component.rb
  2. 1
      app/components/data_protection_confirmation_banner_component.rb
  3. 1
      app/controllers/bulk_upload_lettings_logs_controller.rb
  4. 1
      app/controllers/bulk_upload_sales_logs_controller.rb
  5. 3
      app/controllers/organisations_controller.rb
  6. 10
      app/models/organisation.rb
  7. 1
      app/models/user.rb
  8. 2
      app/models/validations/setup_validations.rb
  9. 2
      app/models/validations/shared_validations.rb
  10. 4
      app/services/feature_toggle.rb
  11. 2
      app/views/logs/_create_for_org_actions.html.erb
  12. 4
      app/views/organisations/show.html.erb
  13. 71
      spec/components/create_log_actions_component_spec.rb
  14. 54
      spec/components/data_protection_confirmation_banner_component_spec.rb
  15. 54
      spec/models/organisation_spec.rb
  16. 10
      spec/models/user_spec.rb
  17. 28
      spec/models/validations/setup_validations_spec.rb
  18. 28
      spec/models/validations/shared_validations_spec.rb
  19. 12
      spec/requests/bulk_upload_lettings_logs_controller_spec.rb
  20. 12
      spec/requests/bulk_upload_sales_logs_controller_spec.rb
  21. 94
      spec/requests/organisations_controller_spec.rb
  22. 35
      spec/views/logs/_create_for_org_actions.html.erb_spec.rb
  23. 14
      spec/views/organisations/show.html.erb_spec.rb

1
app/components/create_log_actions_component.rb

@ -13,7 +13,6 @@ class CreateLogActionsComponent < ViewComponent::Base
def display_actions?
return false if bulk_upload.present?
return true unless FeatureToggle.new_data_protection_confirmation?
return true if user.support?
user.organisation.data_protection_confirmed?

1
app/components/data_protection_confirmation_banner_component.rb

@ -13,7 +13,6 @@ class DataProtectionConfirmationBannerComponent < ViewComponent::Base
end
def display_banner?
return false unless FeatureToggle.new_data_protection_confirmation?
return false if user.support? && organisation.blank?
return true if org_without_dpo?

1
app/controllers/bulk_upload_lettings_logs_controller.rb

@ -25,7 +25,6 @@ class BulkUploadLettingsLogsController < ApplicationController
private
def validate_data_protection_agrement_signed!
return unless FeatureToggle.new_data_protection_confirmation?
return if @current_user.organisation.data_protection_confirmed?
redirect_to lettings_logs_path

1
app/controllers/bulk_upload_sales_logs_controller.rb

@ -25,7 +25,6 @@ class BulkUploadSalesLogsController < ApplicationController
private
def validate_data_protection_agrement_signed!
return unless FeatureToggle.new_data_protection_confirmation?
return if @current_user.organisation.data_protection_confirmed?
redirect_to sales_logs_path

3
app/controllers/organisations_controller.rb

@ -159,13 +159,10 @@ class OrganisationsController < ApplicationController
end
def data_sharing_agreement
return render_not_found unless FeatureToggle.new_data_protection_confirmation?
@data_protection_confirmation = current_user.organisation.data_protection_confirmation
end
def confirm_data_sharing_agreement
return render_not_found unless FeatureToggle.new_data_protection_confirmation?
return render_not_found unless current_user.is_dpo?
return render_not_found if @organisation.data_protection_confirmed?

10
app/models/organisation.rb

@ -103,7 +103,7 @@ class Organisation < ApplicationRecord
end
def display_organisation_attributes
attrs = [
[
{ name: "Name", value: name, editable: true },
{ name: "Organisation ID", value: "ORG#{id}", editable: false },
{ name: "Address", value: address_string, editable: true },
@ -112,13 +112,7 @@ class Organisation < ApplicationRecord
{ name: "Registration number", value: housing_registration_no || "", editable: false },
{ name: "Rent periods", value: rent_period_labels, editable: false, format: :bullet },
{ name: "Owns housing stock", value: holds_own_stock ? "Yes" : "No", editable: false },
].compact
unless FeatureToggle.new_data_protection_confirmation?
attrs << { name: "Data protection agreement", value: data_protection_agreement_string, editable: false }
end
attrs
]
end
def has_managing_agents?

1
app/models/user.rb

@ -186,7 +186,6 @@ protected
private
def send_data_protection_confirmation_reminder
return unless FeatureToggle.new_data_protection_confirmation?
return unless persisted?
return unless is_dpo?

2
app/models/validations/setup_validations.rb

@ -49,8 +49,6 @@ module Validations::SetupValidations
end
def validate_managing_organisation_data_sharing_agremeent_signed(record)
return unless FeatureToggle.new_data_protection_confirmation?
if record.managing_organisation_id_changed? && record.managing_organisation.present? && !record.managing_organisation.data_protection_confirmed?
record.errors.add :managing_organisation_id, I18n.t("validations.setup.managing_organisation.data_sharing_agreement_not_signed")
end

2
app/models/validations/shared_validations.rb

@ -118,8 +118,6 @@ module Validations::SharedValidations
end
def validate_owning_organisation_data_sharing_agremeent_signed(record)
return unless FeatureToggle.new_data_protection_confirmation?
if record.owning_organisation_id_changed? && record.owning_organisation.present? && !record.owning_organisation.data_protection_confirmed?
record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.data_sharing_agreement_not_signed")
end

4
app/services/feature_toggle.rb

@ -30,10 +30,6 @@ class FeatureToggle
!Rails.env.production?
end
def self.new_data_protection_confirmation?
true
end
def self.deduplication_flow_enabled?
!Rails.env.production?
end

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

@ -1,5 +1,5 @@
<div class="govuk-button-group app-filter-toggle">
<% if !FeatureToggle.new_data_protection_confirmation? || @organisation.data_protection_confirmed? %>
<% if @organisation.data_protection_confirmed? %>
<% 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 %>

4
app/views/organisations/show.html.erb

@ -33,9 +33,7 @@
<% end %>
<% end %>
<% end %>
<% if FeatureToggle.new_data_protection_confirmation? %>
<%= data_sharing_agreement_row(organisation: @organisation, user: current_user, summary_list:) %>
<% end %>
<%= data_sharing_agreement_row(organisation: @organisation, user: current_user, summary_list:) %>
<% end %>
<% if FeatureToggle.merge_organisations_enabled? %>
<p>Is your organisation merging with another? <%= govuk_link_to "Let us know using this form", merge_request_organisation_path(@organisation) %></p>

71
spec/components/create_log_actions_component_spec.rb

@ -20,10 +20,8 @@ RSpec.describe CreateLogActionsComponent, type: :component do
context "when bulk upload nil" do
let(:bulk_upload) { nil }
context "when flag disabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
context "when support user" do
let(:user) { create(:user, :support) }
it "renders actions" do
expect(component.display_actions?).to eq(true)
@ -65,12 +63,16 @@ RSpec.describe CreateLogActionsComponent, type: :component do
end
end
context "when flag enabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(true)
context "when not support user" do
context "without data sharing agreement" do
let(:user) { create(:user, organisation: create(:organisation, :without_dpc)) }
it "does not render actions" do
expect(component).not_to be_display_actions
end
end
context "when support user" do
context "when has data sharing agremeent" do
let(:user) { create(:user, :support) }
it "renders actions" do
@ -112,59 +114,6 @@ RSpec.describe CreateLogActionsComponent, type: :component do
end
end
end
context "when not support user" do
context "without data sharing agreement" do
let(:user) { create(:user, organisation: create(:organisation, :without_dpc)) }
it "does not render actions" do
expect(component).not_to be_display_actions
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

54
spec/components/data_protection_confirmation_banner_component_spec.rb

@ -8,10 +8,9 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
let(:user) { create(:user) }
let(:organisation) { user.organisation }
context "when flag disabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
context "when user is support and organisation is blank" do
let(:user) { create(:user, :support) }
let(:organisation) { nil }
it "does not display banner" do
expect(component.display_banner?).to eq(false)
@ -19,15 +18,52 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
end
end
context "when flag enabled", :aggregate_failures do
context "when org does not have a DPO" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(true)
organisation.users.where(is_dpo: true).destroy_all
end
context "when user is support and organisation is blank" do
let(:user) { create(:user, :support) }
let(:organisation) { nil }
it "displays the banner" do
expect(component.display_banner?).to eq(true)
expect(render).to have_link(
"Contact helpdesk to assign a data protection officer",
href: "https://digital.dclg.gov.uk/jira/servicedesk/customer/portal/4/group/21",
)
expect(render).to have_selector("p", text: "To create logs your organisation must state a data protection officer. They must sign the Data Sharing Agreement.")
end
end
context "when org has a DPO" do
context "when org does not have a signed data sharing agreement" do
context "when user is not a DPO" do
let(:organisation) { create(:organisation, :without_dpc) }
let(:user) { create(:user, organisation:) }
let!(:dpo) { create(:user, :data_protection_officer, organisation:) }
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
context "when user is a DPO" do
let(:organisation) { create(:organisation, :without_dpc) }
let(:user) { create(:user, :data_protection_officer, organisation:) }
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
context "when org has a signed data sharing agremeent" do
it "does not display banner" do
expect(component.display_banner?).to eq(false)
expect(render.content).to be_empty

54
spec/models/organisation_spec.rb

@ -234,47 +234,19 @@ RSpec.describe Organisation, type: :model do
describe "display_organisation_attributes" do
let(:organisation) { create(:organisation) }
context "when new_data_protection_confirmation flag enabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(true)
end
it "does not include data protection agreement" do
expect(organisation.display_organisation_attributes).to eq(
[{ editable: true, name: "Name", value: "DLUHC" },
{ editable: false, name: "Organisation ID", value: "ORG#{organisation.id}" },
{ editable: true,
name: "Address",
value: "2 Marsham Street\nLondon\nSW1P 4DF" },
{ editable: true, name: "Telephone number", value: nil },
{ editable: false, name: "Type of provider", value: "Local authority" },
{ editable: false, name: "Registration number", value: "1234" },
{ editable: false, format: :bullet, name: "Rent periods", value: %w[All] },
{ editable: false, name: "Owns housing stock", value: "Yes" }],
)
end
end
context "when new_data_protection_confirmation flag disabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "includes data protection agreement" do
expect(organisation.display_organisation_attributes).to eq(
[{ editable: true, name: "Name", value: "DLUHC" },
{ editable: false, name: "Organisation ID", value: "ORG#{organisation.id}" },
{ editable: true,
name: "Address",
value: "2 Marsham Street\nLondon\nSW1P 4DF" },
{ editable: true, name: "Telephone number", value: nil },
{ editable: false, name: "Type of provider", value: "Local authority" },
{ editable: false, name: "Registration number", value: "1234" },
{ editable: false, format: :bullet, name: "Rent periods", value: %w[All] },
{ editable: false, name: "Owns housing stock", value: "Yes" },
{ editable: false, name: "Data protection agreement", value: "Accepted" }],
)
end
it "does not include data protection agreement" do
expect(organisation.display_organisation_attributes).to eq(
[{ editable: true, name: "Name", value: "DLUHC" },
{ editable: false, name: "Organisation ID", value: "ORG#{organisation.id}" },
{ editable: true,
name: "Address",
value: "2 Marsham Street\nLondon\nSW1P 4DF" },
{ editable: true, name: "Telephone number", value: nil },
{ editable: false, name: "Type of provider", value: "Local authority" },
{ editable: false, name: "Registration number", value: "1234" },
{ editable: false, format: :bullet, name: "Rent periods", value: %w[All] },
{ editable: false, name: "Owns housing stock", value: "Yes" }],
)
end
end
end

10
spec/models/user_spec.rb

@ -382,16 +382,6 @@ RSpec.describe User, type: :model do
args: [user],
)
end
context "when feature flag disabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "does not send the email" do
expect { user.update!(is_dpo: true) }.not_to enqueue_job(ActionMailer::MailDeliveryJob)
end
end
end
context "when updating to non dpo" do

28
spec/models/validations/setup_validations_spec.rb

@ -444,34 +444,6 @@ RSpec.describe Validations::SetupValidations do
end
describe "#validate_managing_organisation_data_sharing_agremeent_signed" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "is valid if the DSA is signed" do
log = build(:lettings_log, :in_progress, owning_organisation: create(:organisation))
expect(log).to be_valid
end
it "is valid when owning_organisation nil" do
log = build(:lettings_log, owning_organisation: nil)
expect(log).to be_valid
end
it "is not valid if the DSA is not signed" do
log = build(:lettings_log, owning_organisation: create(:organisation, :without_dpc))
expect(log).to be_valid
end
end
context "when flag enabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(true)
end
it "is valid if the Data Protection Confirmation is signed" do
log = build(:lettings_log, :in_progress, managing_organisation: create(:organisation))

28
spec/models/validations/shared_validations_spec.rb

@ -177,34 +177,6 @@ RSpec.describe Validations::SharedValidations do
%i[sales_log lettings_log].each do |log_type|
describe "validate_owning_organisation_data_sharing_agremeent_signed" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "is valid if the DSA is signed" do
log = build(log_type, :in_progress, owning_organisation: create(:organisation))
expect(log).to be_valid
end
it "is valid when owning_organisation nil" do
log = build(log_type, owning_organisation: nil)
expect(log).to be_valid
end
it "is not valid if the DSA is not signed" do
log = build(log_type, owning_organisation: create(:organisation, :without_dpc))
expect(log).to be_valid
end
end
context "when flag enabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(true)
end
it "is valid if the Data Protection Confirmation is signed" do
log = build(log_type, :in_progress, owning_organisation: create(:organisation))

12
spec/requests/bulk_upload_lettings_logs_controller_spec.rb

@ -18,18 +18,6 @@ RSpec.describe BulkUploadLettingsLogsController, type: :request do
expect(response).to redirect_to("/lettings-logs")
end
context "when feature flag disabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "does not redirect to lettings index page" do
get "/lettings-logs/bulk-upload-logs/start", params: {}
expect(response).not_to redirect_to("/lettings-logs")
end
end
end
context "when not in crossover period" do

12
spec/requests/bulk_upload_sales_logs_controller_spec.rb

@ -18,18 +18,6 @@ RSpec.describe BulkUploadSalesLogsController, type: :request do
expect(response).to redirect_to("/sales-logs")
end
context "when feature flag disabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "does not redirect to lettings index page" do
get "/lettings-logs/bulk-upload-logs/start", params: {}
expect(response).not_to redirect_to("/sales-logs")
end
end
end
context "when not in crossover period" do

94
spec/requests/organisations_controller_spec.rb

@ -1501,26 +1501,9 @@ RSpec.describe OrganisationsController, type: :request do
sign_in user
end
context "when flag not enabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "returns not found" do
get "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers
expect(response).to have_http_status(:not_found)
end
end
context "when flag enabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(true)
end
it "returns ok" do
get "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers
expect(response).to have_http_status(:ok)
end
it "returns ok" do
get "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers
expect(response).to have_http_status(:ok)
end
end
end
@ -1541,10 +1524,8 @@ RSpec.describe OrganisationsController, type: :request do
sign_in user
end
context "when flag not enabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
context "when user not dpo" do
let(:user) { create(:user, is_dpo: false) }
it "returns not found" do
post "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers
@ -1552,12 +1533,8 @@ RSpec.describe OrganisationsController, type: :request do
end
end
context "when flag enabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(true)
end
context "when user not dpo" do
context "when user is dpo" do
context "when the organisation has a non-confirmed confirmation" do
let(:user) { create(:user, is_dpo: false) }
it "returns not found" do
@ -1566,49 +1543,38 @@ RSpec.describe OrganisationsController, type: :request do
end
end
context "when user is dpo" do
context "when the organisation has a non-confirmed confirmation" do
let(:user) { create(:user, is_dpo: false) }
context "when the organisation does not have a confirmation" do
let(:user) { create(:user, is_dpo: true, organisation:) }
it "returns not found" do
post "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers
expect(response).to have_http_status(:not_found)
end
end
it "returns redirects to details page" do
post "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers
context "when the organisation does not have a confirmation" do
let(:user) { create(:user, is_dpo: true, organisation:) }
expect(response).to redirect_to("/organisations/#{organisation.id}/details")
expect(flash[:notice]).to eq("You have accepted the Data Sharing Agreement")
expect(flash[:notification_banner_body]).to eq("Your organisation can now submit logs.")
end
it "returns redirects to details page" do
post "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers
it "creates a data sharing agreement" do
expect(organisation.reload.data_protection_confirmation).to be_nil
expect(response).to redirect_to("/organisations/#{organisation.id}/details")
expect(flash[:notice]).to eq("You have accepted the Data Sharing Agreement")
expect(flash[:notification_banner_body]).to eq("Your organisation can now submit logs.")
end
post("/organisations/#{organisation.id}/data-sharing-agreement", headers:)
it "creates a data sharing agreement" do
expect(organisation.reload.data_protection_confirmation).to be_nil
data_protection_confirmation = organisation.reload.data_protection_confirmation
post("/organisations/#{organisation.id}/data-sharing-agreement", headers:)
data_protection_confirmation = organisation.reload.data_protection_confirmation
expect(data_protection_confirmation.organisation.address_row).to eq(organisation.address_row)
expect(data_protection_confirmation.organisation.name).to eq(organisation.name)
expect(data_protection_confirmation.organisation.phone).to eq(organisation.phone)
expect(data_protection_confirmation.data_protection_officer).to eq(user)
end
expect(data_protection_confirmation.organisation.address_row).to eq(organisation.address_row)
expect(data_protection_confirmation.organisation.name).to eq(organisation.name)
expect(data_protection_confirmation.organisation.phone).to eq(organisation.phone)
expect(data_protection_confirmation.data_protection_officer).to eq(user)
context "when the user has already accepted the agreement" do
before do
create(:data_protection_confirmation, data_protection_officer: user, organisation: user.organisation)
end
context "when the user has already accepted the agreement" do
before do
create(:data_protection_confirmation, data_protection_officer: user, organisation: user.organisation)
end
it "returns not found" do
post "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers
expect(response).to have_http_status(:not_found)
end
it "returns not found" do
post "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers
expect(response).to have_http_status(:not_found)
end
end
end

35
spec/views/logs/_create_for_org_actions.html.erb_spec.rb

@ -11,40 +11,21 @@ RSpec.describe "logs/_create_for_org_actions.html.erb" do
let(:user) { create(:user) }
context "when flag disabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "shows create buttons" do
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 "when flag enabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).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_dpc)) }
context "without data sharing agreement" do
let(:user) { create(:user, organisation: create(:organisation, :without_dpc)) }
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
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

14
spec/views/organisations/show.html.erb_spec.rb

@ -15,20 +15,6 @@ RSpec.describe "organisations/show.html.erb" do
let(:organisation_without_dpc) { create(:organisation, :without_dpc) }
let(:organisation_with_dsa) { create(:organisation) }
context "when flag disabled" do
let(:user) { create(:user, organisation: organisation_without_dpc) }
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "does not include data sharing agreement row" do
render
expect(fragment).not_to have_content("Data Sharing Agreement")
end
end
context "when dpo" do
let(:user) { create(:user, is_dpo: true, organisation: organisation_without_dpc) }

Loading…
Cancel
Save