Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/v3/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
message = DomainsListMessage.from_params(query_params)
invalid_param!(message.errors.full_messages) unless message.valid?

dataset = DomainFetcher.fetch(message, permission_queryer.readable_org_guids_for_domains_query)
dataset = DomainFetcher.fetch(message, permission_queryer.readable_org_ids_for_domains_query)

render status: :ok, json: Presenters::V3::PaginatedListPresenter.new(
presenter: Presenters::V3::DomainPresenter,
Expand Down Expand Up @@ -164,7 +164,7 @@ def to_route_list_params(query_params, domain)
def find_domain(message)
DomainFetcher.fetch(
message,
permission_queryer.readable_org_guids_for_domains_query
permission_queryer.readable_org_ids_for_domains_query
).first
end

Expand Down Expand Up @@ -249,7 +249,7 @@ def presenter_args
if permission_queryer.can_read_globally?
{ all_orgs_visible: true }
else
{ visible_org_guids_query: permission_queryer.readable_org_guids_query }
{ visible_org_ids_query: permission_queryer.readable_org_ids_query }
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/v3/isolation_segments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def relationships_orgs
organizations = if permission_queryer.can_read_globally?
fetcher.fetch_all
else
fetcher.fetch_for_organizations(org_guids_query: permission_queryer.readable_org_guids_query)
fetcher.fetch_for_organizations(org_ids_query: permission_queryer.readable_org_ids_query)
end

render status: :ok, json: Presenters::V3::ToManyRelationshipPresenter.new(
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/v3/organization_quotas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def index
dataset = if permission_queryer.can_read_globally?
OrganizationQuotaListFetcher.fetch_all(message:)
else
OrganizationQuotaListFetcher.fetch(message: message, readable_org_guids_query: permission_queryer.readable_org_guids_query)
OrganizationQuotaListFetcher.fetch(message: message, readable_org_ids_query: permission_queryer.readable_org_ids_query)
end

render status: :ok, json: Presenters::V3::PaginatedListPresenter.new(
Expand Down Expand Up @@ -110,7 +110,7 @@ def presenter_args
if permission_queryer.can_read_globally?
{ all_orgs_visible: true }
else
{ visible_org_guids_query: permission_queryer.readable_org_guids_query }
{ visible_org_ids_query: permission_queryer.readable_org_ids_query }
end
end
end
11 changes: 6 additions & 5 deletions app/controllers/v3/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def index_org_domains
message = DomainsListMessage.from_params(query_params.except(:guid))
invalid_param!(message.errors.full_messages) unless message.valid?

domains = DomainFetcher.fetch(message, permission_queryer.readable_org_guids_for_domains_query.where(guid: org.guid))
readable_org_ids = Organization.where(id: org.id).where(id: permission_queryer.readable_org_ids_for_domains_query).select(:id)
domains = DomainFetcher.fetch(message, readable_org_ids)

render status: :ok, json: Presenters::V3::PaginatedListPresenter.new(
presenter: Presenters::V3::DomainPresenter,
Expand All @@ -166,7 +167,7 @@ def show_default_domain
domain = org.default_domain

domain_not_found! unless domain
domain_not_found! if domain.private? && permission_queryer.readable_org_guids_for_domains_query.where(guid: org.guid).empty?
domain_not_found! if domain.private? && Organization.where(id: org.id).where(id: permission_queryer.readable_org_ids_for_domains_query).empty?

render status: :ok, json: Presenters::V3::DomainPresenter.new(domain, **presenter_args)
end
Expand Down Expand Up @@ -245,7 +246,7 @@ def fetch_orgs(message)
else
OrgListFetcher.fetch(
message: message,
guids: permission_queryer.readable_org_guids_query,
ids: permission_queryer.readable_org_ids_query,
eager_loaded_associations: Presenters::V3::OrganizationPresenter.associated_resources
)
end
Expand All @@ -260,7 +261,7 @@ def fetch_orgs_for_isolation_segment(message)
else
isolation_segment, dataset = OrgListFetcher.fetch_for_isolation_segment(
message: message,
guids: permission_queryer.readable_org_guids_query,
ids: permission_queryer.readable_org_ids_query,
eager_loaded_associations: Presenters::V3::OrganizationPresenter.associated_resources
)
end
Expand All @@ -272,7 +273,7 @@ def presenter_args
if permission_queryer.can_read_globally?
{ all_orgs_visible: true }
else
{ visible_org_guids_query: permission_queryer.readable_org_guids_query }
{ visible_org_ids_query: permission_queryer.readable_org_ids_query }
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/v3/security_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
dataset = if permission_queryer.can_read_globally?
SecurityGroupListFetcher.fetch_all(message)
else
SecurityGroupListFetcher.fetch(message, permission_queryer.readable_security_group_guids_query)
SecurityGroupListFetcher.fetch(message, permission_queryer.readable_security_group_ids_query)
end

render status: :ok, json: Presenters::V3::PaginatedListPresenter.new(
Expand All @@ -31,7 +31,7 @@ def index
end

def show
security_group = SecurityGroupFetcher.fetch(hashed_params[:guid], permission_queryer.readable_security_group_guids_query)
security_group = SecurityGroupFetcher.fetch(hashed_params[:guid], permission_queryer.readable_security_group_ids_query)
resource_not_found!(:security_group) unless security_group

render status: :ok, json: Presenters::V3::SecurityGroupPresenter.new(
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/v3/spaces_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def running_security_groups
space = SpaceFetcher.new.fetch(hashed_params[:guid])
space_not_found! unless space && permission_queryer.can_read_from_space?(space.id, space.organization_id)

unfiltered_group_guids = fetch_running_security_group_guids(space)
dataset = SecurityGroupListFetcher.fetch(message, unfiltered_group_guids)
unfiltered_group_ids = fetch_running_security_group_ids(space)
dataset = SecurityGroupListFetcher.fetch(message, unfiltered_group_ids)

render status: :ok, json: Presenters::V3::PaginatedListPresenter.new(
presenter: Presenters::V3::SecurityGroupPresenter,
Expand All @@ -125,8 +125,8 @@ def staging_security_groups
space = SpaceFetcher.new.fetch(hashed_params[:guid])
space_not_found! unless space && permission_queryer.can_read_from_space?(space.id, space.organization_id)

unfiltered_group_guids = fetch_staging_security_group_guids(space)
dataset = SecurityGroupListFetcher.fetch(message, unfiltered_group_guids)
unfiltered_group_ids = fetch_staging_security_group_ids(space)
dataset = SecurityGroupListFetcher.fetch(message, unfiltered_group_ids)

render status: :ok, json: Presenters::V3::PaginatedListPresenter.new(
presenter: Presenters::V3::SecurityGroupPresenter,
Expand Down Expand Up @@ -243,16 +243,16 @@ def fetch_isolation_segment(guid)
IsolationSegmentModel.where(guid:).first
end

def fetch_running_security_group_guids(space)
def fetch_running_security_group_ids(space)
space_level_groups = SecurityGroup.where(spaces: space)
global_groups = SecurityGroup.where(running_default: true)
space_level_groups.union(global_groups).select_map(:guid)
space_level_groups.union(global_groups).select_map(:id)
end

def fetch_staging_security_group_guids(space)
def fetch_staging_security_group_ids(space)
space_level_groups = SecurityGroup.where(staging_spaces: space)
global_groups = SecurityGroup.where(staging_default: true)
space_level_groups.union(global_groups).distinct.select_map(:guid)
space_level_groups.union(global_groups).distinct.select_map(:id)
end

def space_not_found!
Expand Down
8 changes: 4 additions & 4 deletions app/fetchers/domain_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
module VCAP::CloudController
class DomainFetcher < BaseListFetcher
class << self
def fetch_all_for_orgs(readable_org_guids)
def fetch_all_for_orgs(readable_org_ids)
# Q: The "Domain" in Domain.dataset is arbitrary -- just a way to get access to any database table.
# If there's a way to use a more generic way to access the database, maybe this can be revised.
#
readable_orgs_filter = Domain.dataset.db[:organizations].where(guid: readable_org_guids).select(:id)
readable_orgs_filter = Domain.dataset.db[:organizations].where(id: readable_org_ids).select(:id)

readable_shared_private_domains_filter = Domain.dataset.db[:organizations_private_domains].where(
organization_id: readable_orgs_filter
Expand All @@ -22,8 +22,8 @@ def fetch_all_for_orgs(readable_org_guids)
Domain.where(user_visible_domains).qualify
end

def fetch(message, readable_org_guids)
dataset = fetch_all_for_orgs(readable_org_guids)
def fetch(message, readable_org_ids)
dataset = fetch_all_for_orgs(readable_org_ids)
filter(message, dataset)
end

Expand Down
4 changes: 2 additions & 2 deletions app/fetchers/isolation_segment_organizations_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def fetch_all
@isolation_segment.organizations
end

def fetch_for_organizations(org_guids_query:)
Organization.where(guid: org_guids_query, isolation_segment_models: @isolation_segment).all
def fetch_for_organizations(org_ids_query:)
Organization.where(id: org_ids_query, isolation_segment_models: @isolation_segment).all
end
end
end
8 changes: 4 additions & 4 deletions app/fetchers/org_list_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
module VCAP::CloudController
class OrgListFetcher < BaseListFetcher
class << self
def fetch(message:, guids:, eager_loaded_associations: [])
dataset = Organization.where(guid: guids)
def fetch(message:, ids:, eager_loaded_associations: [])
dataset = Organization.where(id: ids)
dataset = eager_load(dataset, eager_loaded_associations)
filter(message, dataset)
end
Expand All @@ -17,11 +17,11 @@ def fetch_all(message:, eager_loaded_associations: [])
filter(message, dataset)
end

def fetch_for_isolation_segment(message:, guids:, eager_loaded_associations: [])
def fetch_for_isolation_segment(message:, ids:, eager_loaded_associations: [])
isolation_segment = IsolationSegmentModel.where(guid: message.isolation_segment_guid).first
return nil unless isolation_segment

dataset = isolation_segment.organizations_dataset.where(guid: guids)
dataset = isolation_segment.organizations_dataset.where(id: ids)
dataset = eager_load(dataset, eager_loaded_associations)
[isolation_segment, filter(message, dataset)]
end
Expand Down
8 changes: 4 additions & 4 deletions app/fetchers/organization_quota_list_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
module VCAP::CloudController
class OrganizationQuotaListFetcher < BaseListFetcher
class << self
def fetch(message:, readable_org_guids_query:)
def fetch(message:, readable_org_ids_query:)
dataset = QuotaDefinition.dataset
filter(message, dataset, readable_org_guids_query)
filter(message, dataset, readable_org_ids_query)
end

def fetch_all(message:)
Expand All @@ -17,7 +17,7 @@ def fetch_all(message:)

private

def filter(message, dataset, readable_org_guids_query=nil)
def filter(message, dataset, readable_org_ids_query=nil)
dataset = dataset.where(name: message.names) if message.requested? :names

if message.requested? :organization_guids
Expand All @@ -26,7 +26,7 @@ def filter(message, dataset, readable_org_guids_query=nil)
where(organizations__guid: message.organization_guids).distinct(:id).
qualify(:quota_definitions)

dataset = dataset.where(organizations__guid: readable_org_guids_query) if readable_org_guids_query
dataset = dataset.where(organizations__id: readable_org_ids_query) if readable_org_ids_query
end

super(message, dataset, QuotaDefinition)
Expand Down
4 changes: 2 additions & 2 deletions app/fetchers/security_group_fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module VCAP::CloudController
class SecurityGroupFetcher
class << self
def fetch(guid, visible_security_group_guids=nil)
def fetch(guid, visible_security_group_ids=nil)
dataset = SecurityGroup.where(guid:)
dataset = dataset.where(guid: visible_security_group_guids) if visible_security_group_guids
dataset = dataset.where(id: visible_security_group_ids) if visible_security_group_ids
dataset = eager_load_running_and_staging_space_guids(dataset)
dataset.all.first
end
Expand Down
4 changes: 2 additions & 2 deletions app/fetchers/security_group_list_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def fetch_all(message)
filter(message, dataset)
end

def fetch(message, visible_security_group_guids)
dataset = SecurityGroup.where(guid: visible_security_group_guids)
def fetch(message, visible_security_group_ids)
dataset = SecurityGroup.where(id: visible_security_group_ids)
dataset = SecurityGroupFetcher.eager_load_running_and_staging_space_guids(dataset)
filter(message, dataset)
end
Expand Down
2 changes: 1 addition & 1 deletion app/fetchers/service_plan_visibility_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def base_query(service_plan_guids:)
join(:service_plans, id: :service_plan_visibilities__service_plan_id).
where(service_plans__guid: service_plan_guids)

dataset = dataset.where(organizations__guid: @permission_queryer.readable_org_guids_query) unless @permission_queryer.can_read_globally?
dataset = dataset.where(organizations__id: @permission_queryer.readable_org_ids_query) unless @permission_queryer.can_read_globally?

dataset
end
Expand Down
8 changes: 4 additions & 4 deletions app/presenters/v3/domain_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def initialize(
resource,
show_secrets: false,
censored_message: VCAP::CloudController::Presenters::Censorship::REDACTED_CREDENTIAL,
visible_org_guids_query: nil,
visible_org_ids_query: nil,
all_orgs_visible: false
)
@visible_org_guids_query = visible_org_guids_query
@visible_org_ids_query = visible_org_ids_query
@all_orgs_visible = all_orgs_visible

super(resource, show_secrets:, censored_message:)
Expand Down Expand Up @@ -53,11 +53,11 @@ def to_hash

private

attr_reader :visible_org_guids_query, :all_orgs_visible
attr_reader :visible_org_ids_query, :all_orgs_visible

def shared_org_guids
ds = domain.shared_organizations_dataset
ds = ds.where(guid: @visible_org_guids_query) unless @all_orgs_visible
ds = ds.where(id: @visible_org_ids_query) unless @all_orgs_visible
ds.select_map(:guid).map { |g| { guid: g } }
end

Expand Down
8 changes: 4 additions & 4 deletions app/presenters/v3/domain_shared_orgs_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module VCAP::CloudController::Presenters::V3
class DomainSharedOrgsPresenter < BasePresenter
def initialize(
resource,
visible_org_guids_query: nil,
visible_org_ids_query: nil,
all_orgs_visible: false
)
@visible_org_guids_query = visible_org_guids_query
@visible_org_ids_query = visible_org_ids_query
@all_orgs_visible = all_orgs_visible

super(resource)
Expand All @@ -23,11 +23,11 @@ def to_hash

private

attr_reader :visible_org_guids_query, :all_orgs_visible
attr_reader :visible_org_ids_query, :all_orgs_visible

def shared_org_guids
ds = domain.shared_organizations_dataset
ds = ds.where(guid: @visible_org_guids_query) unless @all_orgs_visible
ds = ds.where(id: @visible_org_ids_query) unless @all_orgs_visible
ds.select_map(:guid).map { |g| { guid: g } }
end

Expand Down
6 changes: 3 additions & 3 deletions app/presenters/v3/organization_quota_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def initialize(
show_secrets: false,
censored_message: VCAP::CloudController::Presenters::Censorship::REDACTED_CREDENTIAL,
all_orgs_visible: false,
visible_org_guids_query: nil
visible_org_ids_query: nil
)
super(resource, show_secrets:, censored_message:)
@all_orgs_visible = all_orgs_visible
@visible_org_guids_query = visible_org_guids_query
@visible_org_ids_query = visible_org_ids_query
end

def to_hash
Expand Down Expand Up @@ -53,7 +53,7 @@ def to_hash

def filtered_visible_orgs
ds = organization_quota.organizations_dataset
ds = ds.where(guid: @visible_org_guids_query) unless @all_orgs_visible
ds = ds.where(id: @visible_org_ids_query) unless @all_orgs_visible
ds.select_map(:guid).map { |g| { guid: g } }
end

Expand Down
Loading
Loading