mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-07 15:21:58 +08:00
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.
34 lines
905 B
Ruby
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
|