Class: Findbug::AlertsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Findbug::AlertsController
- Defined in:
- app/controllers/findbug/alerts_controller.rb
Overview
AlertsController manages alert channel configuration via the dashboard.
Users can create, edit, enable/disable, delete, and test alert channels directly from the UI instead of editing the Rails initializer.
Instance Method Summary collapse
-
#create ⇒ Object
POST /findbug/alerts.
-
#destroy ⇒ Object
DELETE /findbug/alerts/:id.
-
#edit ⇒ Object
GET /findbug/alerts/:id/edit.
-
#index ⇒ Object
GET /findbug/alerts.
-
#new ⇒ Object
GET /findbug/alerts/new.
-
#test ⇒ Object
POST /findbug/alerts/:id/test.
-
#toggle ⇒ Object
POST /findbug/alerts/:id/toggle.
-
#update ⇒ Object
PATCH /findbug/alerts/:id.
Instance Method Details
#create ⇒ Object
POST /findbug/alerts
Save a new alert channel.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/findbug/alerts_controller.rb', line 38 def create @channel = Findbug::AlertChannel.new(channel_params) @channel.config = build_config_from_params if @channel.save flash_success "#{@channel.display_type} alert channel created" redirect_to findbug.alerts_path else flash_error @channel.errors..join(", ") render template: "findbug/alerts/new", layout: "findbug/application", status: :unprocessable_entity end end |
#destroy ⇒ Object
DELETE /findbug/alerts/:id
Delete an alert channel.
80 81 82 83 84 85 |
# File 'app/controllers/findbug/alerts_controller.rb', line 80 def destroy name = @channel.name @channel.destroy flash_success "Alert channel \"#{name}\" deleted" redirect_to findbug.alerts_path end |
#edit ⇒ Object
GET /findbug/alerts/:id/edit
Form to edit an existing alert channel.
55 56 57 |
# File 'app/controllers/findbug/alerts_controller.rb', line 55 def edit render template: "findbug/alerts/edit", layout: "findbug/application" end |
#index ⇒ Object
GET /findbug/alerts
List all configured alert channels.
18 19 20 21 22 23 |
# File 'app/controllers/findbug/alerts_controller.rb', line 18 def index @channels = Findbug::AlertChannel.order(created_at: :asc) @enabled_count = @channels.count(&:enabled?) render template: "findbug/alerts/index", layout: "findbug/application" end |
#new ⇒ Object
GET /findbug/alerts/new
Form to create a new alert channel.
29 30 31 32 |
# File 'app/controllers/findbug/alerts_controller.rb', line 29 def new @channel = Findbug::AlertChannel.new render template: "findbug/alerts/new", layout: "findbug/application" end |
#test ⇒ Object
POST /findbug/alerts/:id/test
Send a test alert to this channel.
Creates a synthetic error event (not persisted to DB) and sends it directly to the channel, bypassing throttling.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/findbug/alerts_controller.rb', line 111 def test unless @channel.enabled? flash_error "Cannot test a disabled channel. Enable it first." redirect_to findbug.alerts_path and return end error_event = build_test_error_event channel_instance = @channel.channel_class.new(@channel.config.symbolize_keys) begin channel_instance.send_alert(error_event) flash_success "Test alert sent to #{@channel.name} successfully!" rescue StandardError => e flash_error "Failed to send test alert: #{e.}" end redirect_to findbug.alerts_path end |
#toggle ⇒ Object
POST /findbug/alerts/:id/toggle
Toggle enable/disable for an alert channel.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/findbug/alerts_controller.rb', line 91 def toggle @channel.enabled = !@channel.enabled? if @channel.save status = @channel.enabled? ? "enabled" : "disabled" flash_success "#{@channel.name} #{status}" else flash_error @channel.errors..join(", ") end redirect_to findbug.alerts_path end |
#update ⇒ Object
PATCH /findbug/alerts/:id
Update an existing alert channel.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/findbug/alerts_controller.rb', line 63 def update @channel.assign_attributes(channel_params) @channel.config = build_config_from_params if @channel.save flash_success "#{@channel.display_type} alert channel updated" redirect_to findbug.alerts_path else flash_error @channel.errors..join(", ") render template: "findbug/alerts/edit", layout: "findbug/application", status: :unprocessable_entity end end |