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. 32
      app/models/form/sales/pages/organisation.rb
  4. 52
      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?

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

@ -11,25 +11,29 @@ class Form::Sales::Pages::Organisation < ::Form::Page
end end
def routed_to?(log, current_user) def routed_to?(log, current_user)
return false unless current_user if FeatureToggle.merge_organisations_enabled?
return true if current_user.support? return false unless current_user
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 = current_user.organisation.stock_owners + current_user.organisation.absorbed_organisations.where(holds_own_stock: true)
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 current_user.organisation.absorbed_organisations.any?(&:holds_own_stock?)
return true return true
end
return true if stock_owners.count >= 1
log.update!(owning_organisation: current_user.organisation)
else
return false if stock_owners.count.zero?
return true if stock_owners.count > 1
log.update!(owning_organisation: stock_owners.first)
end end
return true if stock_owners.count >= 1
log.update!(owning_organisation: current_user.organisation) false
else else
return false if stock_owners.count.zero? !!current_user&.support?
return true if stock_owners.count > 1
log.update!(owning_organisation: stock_owners.first)
end end
false
end end
end end

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

@ -11,24 +11,32 @@ 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?
return answer_opts unless user
return answer_opts unless log
if log.owning_organisation_id.present? if FeatureToggle.merge_organisations_enabled?
answer_opts = answer_opts.merge({ log.owning_organisation.id => log.owning_organisation.name }) return answer_opts unless user
end return answer_opts unless log
if !user.support? && user.organisation.holds_own_stock? if log.owning_organisation_id.present?
answer_opts[user.organisation.id] = "#{user.organisation.name} (Your organisation)" answer_opts = answer_opts.merge({ log.owning_organisation.id => log.owning_organisation.name })
end end
if !user.support? && user.organisation.holds_own_stock?
answer_opts[user.organisation.id] = "#{user.organisation.name} (Your organisation)"
end
user_answer_options = if user.support? user_answer_options = if user.support?
Organisation.where(holds_own_stock: true) Organisation.where(holds_own_stock: true)
else else
user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true) user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true)
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,14 +54,18 @@ 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)
return false if user.support? if FeatureToggle.merge_organisations_enabled?
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? if user.organisation.holds_own_stock?
stock_owners.count.zero? stock_owners.count.zero?
else
stock_owners.count <= 1
end
else else
stock_owners.count <= 1 !current_user.support?
end end
end end
@ -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