Files
ubicloud/helpers/private_subnet.rb
Jeremy Evans 6123351b74 Simplify private subnet authorization check when disconnecting private subnets
With disconnect, the ubid is passed in the path, but we still want
to use authorized_private_subnet, so have it and authorized_object
accept an id keyword argument, to use the id directly instead of
looking in the params for it.
2025-05-14 07:04:53 +09:00

65 lines
2.0 KiB
Ruby

# frozen_string_literal: true
class Clover
def authorized_private_subnet(perm: "PrivateSubnet:view", location_id: nil, key: "private_subnet_id", id: nil)
authorized_object(association: :private_subnets, key:, perm:, location_id:, id:)
end
def private_subnet_list
dataset = dataset_authorize(@project.private_subnets_dataset, "PrivateSubnet:view")
if api?
dataset = dataset.where(location: @location) if @location
result = dataset.eager(nics: [:private_subnet]).paginated_result(
start_after: request.params["start_after"],
page_size: request.params["page_size"],
order_column: request.params["order_column"]
)
{
items: Serializers::PrivateSubnet.serialize(result[:records]),
count: result[:count]
}
else
@pss = Serializers::PrivateSubnet.serialize(dataset.all, {include_path: true})
view "networking/private_subnet/index"
end
end
def private_subnet_post(name)
authorize("PrivateSubnet:create", @project.id)
params = check_required_web_params(%w[name location])
if params["firewall_id"]
unless (firewall = authorized_firewall(location_id: @location.id))
fail Validation::ValidationFailed.new(firewall_id: "Firewall with id \"#{params["firewall_id"]}\" and location \"#{@location.display_name}\" is not found")
end
end
ps = nil
DB.transaction do
ps = Prog::Vnet::SubnetNexus.assemble(
@project.id,
name:,
location_id: @location.id,
firewall_id: firewall&.id
).subject
audit_log(ps, "create")
end
if api?
Serializers::PrivateSubnet.serialize(ps)
else
flash["notice"] = "'#{name}' will be ready in a few seconds"
request.redirect "#{@project.path}#{ps.path}"
end
end
def generate_private_subnet_options
options = OptionTreeGenerator.new
options.add_option(name: "name")
options.add_option(name: "location", values: Option.locations)
options.serialize
end
end