Skip to content

Commit

Permalink
Fix select query for service offerings
Browse files Browse the repository at this point in the history
The service offerings list fetcher returned duplicates in case an
offering had both a public plan and another plan that was org
restricted. Thus a DISTINCT has been added to the outer select query.
  • Loading branch information
philippthun authored and johha committed May 21, 2024
1 parent 269c885 commit 173ff49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/fetchers/service_offering_list_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ module VCAP::CloudController
class ServiceOfferingListFetcher < BaseServiceListFetcher
class << self
def fetch(message, omniscient: false, readable_orgs_query: nil, readable_spaces_query: nil, eager_loaded_associations: [])
super(Service,
message,
omniscient:,
readable_orgs_query:,
readable_spaces_query:,
eager_loaded_associations:)
dataset = super(Service,
message,
omniscient:,
readable_orgs_query:,
readable_spaces_query:,
eager_loaded_associations:)
# for service offerings there might be an overlap between the UNIONed subqueries (i.e. one plan is public and another one is org restricted)
dataset.distinct
end

private
Expand Down
15 changes: 15 additions & 0 deletions spec/unit/fetchers/service_offering_list_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ module VCAP::CloudController
end
end

context 'service offering with both public and org restricted plans' do
let(:org) { Organization.make }
let(:readable_orgs) { [org] }

it 'shows unique results' do
service_offering = Service.make(label: "with-public-and-org-restricted-plans-#{Sham.name}")
ServicePlan.make(public: true, active: true, service: service_offering)
service_plan = ServicePlan.make(public: false, service: service_offering)
ServicePlanVisibility.make(organization: org, service_plan: service_plan)

service_offerings = fetcher.fetch(message, readable_orgs_query:).all
expect(service_offerings).to contain_exactly(service_offering)
end
end

describe 'visibility of offerings' do
let!(:public_offering_1) { make_public_offering }
let!(:public_offering_2) { make_public_offering(number_of_plans: 2) }
Expand Down

0 comments on commit 173ff49

Please sign in to comment.