mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-04 22:02:18 +08:00
Previously, project_id and subject_id needed to be a uuid, and object_id could be a uuid or ubid. This allows accepting an object for all three. This simplifies almost all callers of these methods. It also doesn't require either parsing a ubid or generating a ubid. Previously, even if a uuid was given, it would turn it into a ubid in order to extract the class, and guess ApiKey if it was an et ubid.
35 lines
941 B
Ruby
35 lines
941 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Clover
|
|
hash_branch(:project_prefix, "usage-alert") do |r|
|
|
r.web do
|
|
authorize("Project:billing", @project)
|
|
|
|
r.post true do
|
|
handle_validation_failure("project/billing")
|
|
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 billing_path
|
|
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
|