Browse Source

Remove merge organisatiions toggle

pull/2228/head
Kat 2 years ago
parent
commit
feead350cf
  1. 10
      app/models/form/lettings/pages/stock_owner.rb
  2. 6
      app/models/form/lettings/questions/stock_owner.rb
  3. 10
      app/models/form/sales/pages/owning_organisation.rb
  4. 73
      app/models/form/sales/questions/owning_organisation_id.rb
  5. 4
      app/services/feature_toggle.rb
  6. 4
      app/views/organisations/show.html.erb
  7. 24
      spec/requests/sales_logs_controller_spec.rb

10
app/models/form/lettings/pages/stock_owner.rb

@ -14,16 +14,10 @@ class Form::Lettings::Pages::StockOwner < ::Form::Page
return false unless current_user
return true if current_user.support?
stock_owners = if FeatureToggle.merge_organisations_enabled?
current_user.organisation.stock_owners + current_user.organisation.absorbed_organisations.where(holds_own_stock: true)
else
current_user.organisation.stock_owners
end
stock_owners = current_user.organisation.stock_owners + current_user.organisation.absorbed_organisations.where(holds_own_stock: true)
if current_user.organisation.holds_own_stock?
if FeatureToggle.merge_organisations_enabled? && current_user.organisation.absorbed_organisations.any?(&:holds_own_stock?)
return true
end
return true if current_user.organisation.absorbed_organisations.any?(&:holds_own_stock?)
return true if stock_owners.count >= 1
log.update!(owning_organisation: current_user.organisation)

6
app/models/form/lettings/questions/stock_owner.rb

@ -67,11 +67,7 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question
def hidden_in_check_answers?(_log, user = nil)
return false if user.support?
stock_owners = if FeatureToggle.merge_organisations_enabled?
user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true)
else
user.organisation.stock_owners
end
stock_owners = user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true)
if user.organisation.holds_own_stock?
stock_owners.count.zero?

10
app/models/form/sales/pages/owning_organisation.rb

@ -15,16 +15,10 @@ class Form::Sales::Pages::OwningOrganisation < ::Form::Page
return true if current_user.support?
return true if has_multiple_stock_owners_with_own_stock?(current_user)
stock_owners = if FeatureToggle.merge_organisations_enabled?
current_user.organisation.stock_owners.where(holds_own_stock: true) + current_user.organisation.absorbed_organisations.where(holds_own_stock: true)
else
current_user.organisation.stock_owners.where(holds_own_stock: true)
end
stock_owners = current_user.organisation.stock_owners.where(holds_own_stock: true) + current_user.organisation.absorbed_organisations.where(holds_own_stock: true)
if current_user.organisation.holds_own_stock?
if FeatureToggle.merge_organisations_enabled? && current_user.organisation.absorbed_organisations.any?(&:holds_own_stock?)
return true
end
return true if current_user.organisation.absorbed_organisations.any?(&:holds_own_stock?)
return true if stock_owners.count >= 1
log.update!(owning_organisation: current_user.organisation)

73
app/models/form/sales/questions/owning_organisation_id.rb

@ -28,43 +28,36 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
end
end
if FeatureToggle.merge_organisations_enabled?
if log.owning_organisation_id.present?
answer_opts[log.owning_organisation.id] = log.owning_organisation.name
end
if log.owning_organisation_id.present?
answer_opts[log.owning_organisation.id] = log.owning_organisation.name
end
recently_absorbed_organisations = user.organisation.absorbed_organisations.merged_during_open_collection_period
if !user.support? && user.organisation.holds_own_stock?
answer_opts[user.organisation.id] = if recently_absorbed_organisations.exists? && user.organisation.available_from.present?
"#{user.organisation.name} (Your organisation, active as of #{user.organisation.available_from.to_fs(:govuk_date)})"
else
"#{user.organisation.name} (Your organisation)"
end
end
recently_absorbed_organisations = user.organisation.absorbed_organisations.merged_during_open_collection_period
if !user.support? && user.organisation.holds_own_stock?
answer_opts[user.organisation.id] = if recently_absorbed_organisations.exists? && user.organisation.available_from.present?
"#{user.organisation.name} (Your organisation, active as of #{user.organisation.available_from.to_fs(:govuk_date)})"
else
"#{user.organisation.name} (Your organisation)"
end
end
if user.support?
Organisation.where(holds_own_stock: true).find_each do |org|
if org.merge_date.present?
answer_opts[org.id] = "#{org.name} (inactive as of #{org.merge_date.to_fs(:govuk_date)})" if org.merge_date >= FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period
elsif org.absorbed_organisations.merged_during_open_collection_period.exists? && org.available_from.present?
answer_opts[org.id] = "#{org.name} (active as of #{org.available_from.to_fs(:govuk_date)})"
else
answer_opts[org.id] = org.name
end
end
else
recently_absorbed_organisations.each do |absorbed_org|
answer_opts[absorbed_org.id] = merged_organisation_label(absorbed_org.name, absorbed_org.merge_date) if absorbed_org.holds_own_stock?
if user.support?
Organisation.where(holds_own_stock: true).find_each do |org|
if org.merge_date.present?
answer_opts[org.id] = "#{org.name} (inactive as of #{org.merge_date.to_fs(:govuk_date)})" if org.merge_date >= FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period
elsif org.absorbed_organisations.merged_during_open_collection_period.exists? && org.available_from.present?
answer_opts[org.id] = "#{org.name} (active as of #{org.available_from.to_fs(:govuk_date)})"
else
answer_opts[org.id] = org.name
end
end
answer_opts
else
Organisation.select(:id, :name).each_with_object(answer_opts) do |organisation, hsh|
hsh[organisation.id] = organisation.name
hsh
recently_absorbed_organisations.each do |absorbed_org|
answer_opts[absorbed_org.id] = merged_organisation_label(absorbed_org.name, absorbed_org.merge_date) if absorbed_org.holds_own_stock?
end
end
answer_opts
end
def displayed_answer_options(log, user = nil)
@ -82,18 +75,14 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
end
def hidden_in_check_answers?(_log, user = nil)
if FeatureToggle.merge_organisations_enabled?
return false if user.support?
return false if user.support?
stock_owners = user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true)
stock_owners = user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true)
if user.organisation.holds_own_stock?
stock_owners.count.zero?
else
stock_owners.count <= 1
end
if user.organisation.holds_own_stock?
stock_owners.count.zero?
else
!current_user.support?
stock_owners.count <= 1
end
end
@ -104,11 +93,7 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
private
def selected_answer_option_is_derived?(_log)
if FeatureToggle.merge_organisations_enabled?
true
else
false
end
true
end
def merged_organisation_label(name, merge_date)

4
app/services/feature_toggle.rb

@ -28,10 +28,6 @@ class FeatureToggle
false
end
def self.merge_organisations_enabled?
true
end
def self.deduplication_flow_enabled?
true
end

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

@ -36,9 +36,7 @@
<% end %>
<%= data_sharing_agreement_row(organisation: @organisation, user: current_user, summary_list:) %>
<% end %>
<% if FeatureToggle.merge_organisations_enabled? %>
<p>To report a merge or update your organisation details, <%= govuk_link_to "contact the helpdesk", GlobalConstants::HELPDESK_URL %>.</p>
<% end %>
<p>To report a merge or update your organisation details, <%= govuk_link_to "contact the helpdesk", GlobalConstants::HELPDESK_URL %>.</p>
<%= render partial: "organisations/merged_organisation_details" %>
</div>
</div>

24
spec/requests/sales_logs_controller_spec.rb

@ -161,30 +161,6 @@ RSpec.describe SalesLogsController, type: :request do
expect(sales_log.managing_organisation.name).to eq("User org")
end
end
context "when the user's org doesn't hold stock and merge_organisations_enabled is false" do
let(:organisation) { FactoryBot.create(:organisation, name: "User org", holds_own_stock: false) }
let(:user) { FactoryBot.create(:user, :data_coordinator, organisation:) }
before do
RequestHelper.stub_http_requests
sign_in user
allow(FeatureToggle).to receive(:merge_organisations_enabled?).and_return(false)
post "/sales-logs", headers:
end
it "does not set owning organisation" do
created_id = response.location.match(/[0-9]+/)[0]
sales_log = SalesLog.find_by(id: created_id)
expect(sales_log.owning_organisation).to be_nil
end
it "sets managing organisation as the user organisation" do
created_id = response.location.match(/[0-9]+/)[0]
sales_log = SalesLog.find_by(id: created_id)
expect(sales_log.managing_organisation.name).to eq("User org")
end
end
end
end
end

Loading…
Cancel
Save