Files
ubicloud/routes/project/usage_alert.rb
Jeremy Evans a02b5e060a Use r.web and r.api
These are faster and simpler equivalents of r.on web? and r.on api?
that are supported by the host_routing plugin.
2024-12-18 11:04:28 -08:00

33 lines
900 B
Ruby

# frozen_string_literal: true
class Clover
hash_branch(:project_prefix, "usage-alert") do |r|
r.web do
authorize("Project:billing", @project.id)
r.post true do
name = r.params["alert_name"]
Validation.validate_short_text(name, "name")
limit = Validation.validate_usage_limit(r.params["limit"])
UsageAlert.create_with_id(project_id: @project.id, user_id: current_account_id, name: name, limit: limit)
r.redirect "#{@project.path}/billing"
end
r.is String do |usage_alert_ubid|
usage_alert = UsageAlert.from_ubid(usage_alert_ubid)
unless usage_alert
response.status = 404
next {message: "Usage alert is not found."}
end
r.delete true do
usage_alert.destroy
{message: "Usage alert #{usage_alert.name} is deleted."}
end
end
end
end
end