Files
ubicloud/routes/project/usage_alert.rb
Jeremy Evans d10bfc7af9 Remove unnecessary route nesting or true matchers
For routes inside r.is blocks, a fully routed path has
already been checked, so a true argument is not needed.
2025-06-20 05:14:52 +09:00

35 lines
913 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 = typecast_params.nonempty_str("alert_name")
Validation.validate_short_text(name, "name")
limit = typecast_params.pos_int!("limit")
DB.transaction do
ua = UsageAlert.create_with_id(project_id: @project.id, user_id: current_account_id, name:, limit:)
audit_log(ua, "create")
end
r.redirect "#{@project.path}/billing"
end
r.delete :ubid_uuid do |id|
next unless (usage_alert = @project.usage_alerts_dataset[id:])
DB.transaction do
usage_alert.destroy
audit_log(usage_alert, "destroy")
end
flash["notice"] = "Usage alert #{usage_alert.name} is deleted."
204
end
end
end
end