Browse Source

feat: put merge orgs behaviour behind feature flag

pull/1830/head
natdeanlewissoftwire 3 years ago
parent
commit
b7e40a6965
  1. 8
      app/models/form/lettings/pages/stock_owner.rb
  2. 6
      app/models/form/lettings/questions/stock_owner.rb
  3. 4
      app/models/form/sales/pages/organisation.rb
  4. 14
      app/models/form/sales/questions/owning_organisation_id.rb

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

@ -14,10 +14,14 @@ class Form::Lettings::Pages::StockOwner < ::Form::Page
return false unless current_user return false unless current_user
return true if current_user.support? return true if current_user.support?
stock_owners = current_user.organisation.stock_owners + current_user.organisation.absorbed_organisations.where(holds_own_stock: true) 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
if current_user.organisation.holds_own_stock? if current_user.organisation.holds_own_stock?
if current_user.organisation.absorbed_organisations.any?(&:holds_own_stock?) if FeatureToggle.merge_organisations_enabled? && current_user.organisation.absorbed_organisations.any?(&:holds_own_stock?)
return true return true
end end
return true if stock_owners.count >= 1 return true if stock_owners.count >= 1

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

@ -49,7 +49,11 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question
def hidden_in_check_answers?(_log, user = nil) def hidden_in_check_answers?(_log, user = nil)
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 = if FeatureToggle.merge_organisations_enabled?
user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true)
else
user.organisation.stock_owners
end
if user.organisation.holds_own_stock? if user.organisation.holds_own_stock?
stock_owners.count.zero? stock_owners.count.zero?

4
app/models/form/sales/pages/organisation.rb

@ -11,6 +11,7 @@ class Form::Sales::Pages::Organisation < ::Form::Page
end end
def routed_to?(log, current_user) def routed_to?(log, current_user)
if FeatureToggle.merge_organisations_enabled?
return false unless current_user return false unless current_user
return true if current_user.support? return true if current_user.support?
@ -31,5 +32,8 @@ class Form::Sales::Pages::Organisation < ::Form::Page
end end
false false
else
!!current_user&.support?
end
end end
end end

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

@ -11,6 +11,8 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
answer_opts = { "" => "Select an option" } answer_opts = { "" => "Select an option" }
return answer_opts unless ActiveRecord::Base.connected? return answer_opts unless ActiveRecord::Base.connected?
if FeatureToggle.merge_organisations_enabled?
return answer_opts unless user return answer_opts unless user
return answer_opts unless log return answer_opts unless log
@ -29,6 +31,12 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
end.pluck(:id, :name).to_h end.pluck(:id, :name).to_h
answer_opts.merge(user_answer_options) answer_opts.merge(user_answer_options)
else
Organisation.select(:id, :name).each_with_object(answer_opts) do |organisation, hsh|
hsh[organisation.id] = organisation.name
hsh
end
end
end end
def displayed_answer_options(log, user = nil) def displayed_answer_options(log, user = nil)
@ -46,6 +54,7 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
end end
def hidden_in_check_answers?(_log, user = nil) 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)
@ -55,6 +64,9 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
else else
stock_owners.count <= 1 stock_owners.count <= 1
end end
else
!current_user.support?
end
end end
def enabled def enabled
@ -64,6 +76,6 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
private private
def selected_answer_option_is_derived?(_log) def selected_answer_option_is_derived?(_log)
true FeatureToggle.merge_organisations_enabled? ? true : false
end end
end end

Loading…
Cancel
Save