Browse Source

Correctly route to sales owning organisation page

pull/2049/head
Kat 3 years ago
parent
commit
731bad89ff
  1. 18
      app/models/form/sales/pages/organisation.rb
  2. 4
      app/services/feature_toggle.rb
  3. 8
      spec/models/form/sales/pages/organisation_spec.rb

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

@ -11,11 +11,15 @@ 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 true if current_user.support?
return false unless current_user if FeatureToggle.sales_managing_organisation_enabled?
return true if current_user.support? return true if stock_owners_with_own_stock_count(current_user) > 1
return true if current_user.organisation.holds_own_stock? && stock_owners_with_own_stock_count(current_user) >= 1
end
if FeatureToggle.merge_organisations_enabled?
absorbed_stock_owners = current_user.organisation.absorbed_organisations.where(holds_own_stock: true) absorbed_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?
@ -27,7 +31,13 @@ class Form::Sales::Pages::Organisation < ::Form::Page
false false
else else
!!current_user&.support? !current_user&.support?.nil?
end end
end end
private
def stock_owners_with_own_stock_count(user)
user.organisation.stock_owners.where(holds_own_stock: true).count
end
end end

4
app/services/feature_toggle.rb

@ -43,4 +43,8 @@ class FeatureToggle
def self.service_moved? def self.service_moved?
false false
end end
def self.sales_managing_organisation_enabled?
Rails.env.test? || Rails.env.review? || Rails.env.development?
end
end end

8
spec/models/form/sales/pages/organisation_spec.rb

@ -110,8 +110,8 @@ RSpec.describe Form::Sales::Pages::Organisation, type: :model do
) )
end end
it "is not shown" do it "is shown" do
expect(page.routed_to?(log, user)).to eq(false) expect(page.routed_to?(log, user)).to eq(true)
end end
end end
end end
@ -133,8 +133,8 @@ RSpec.describe Form::Sales::Pages::Organisation, type: :model do
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)
end end
it "is not shown" do it "is shown" do
expect(page.routed_to?(log, user)).to eq(false) expect(page.routed_to?(log, user)).to eq(true)
end end
end end

Loading…
Cancel
Save