ubicloud/routes/project/usage_alert.rb
Jeremy Evans 4b819d3cb2 Change all create_with_id to create
It hasn't been necessary to use create_with_id since
ebc79622df, in December 2024.

I have plans to introduce:

```ruby
def create_with_id(id, values)
  obj = new(values)
  obj.id = id
  obj.save_changes
end
```

This will make it easier to use the same id when creating
multiple objects.  The first step is removing the existing
uses of create_with_id.
2025-08-06 01:55:51 +09:00

34 lines
905 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(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