Class: PgSqlTriggers::TriggersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pg_sql_triggers/triggers_controller.rb

Overview

Controller for managing individual triggers via web UI Provides actions to enable and disable triggers

Instance Method Summary collapse

Methods included from PermissionsHelper

#can?, #can_apply_triggers?, #can_drop_triggers?, #can_enable_disable_triggers?, #can_execute_sql_operations?, #can_generate_triggers?, #can_view_triggers?

Methods included from ErrorHandling

#format_error_for_flash, #handle_kill_switch_error, #handle_standard_error, #rescue_pg_sql_triggers_error

Methods included from PermissionChecking

#can_apply_triggers?, #can_drop_triggers?, #can_enable_disable_triggers?, #can_execute_sql_operations?, #can_generate_triggers?, #can_view_triggers?, #check_admin_permission, #check_operator_permission, #check_viewer_permission, #current_actor, #current_user_id, #current_user_type

Methods included from KillSwitchProtection

#check_kill_switch, #current_environment, #expected_confirmation_text, #kill_switch_active?, #require_kill_switch_override

Instance Method Details

#disableObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/pg_sql_triggers/triggers_controller.rb', line 34

def disable
  # Check kill switch before disabling trigger
  check_kill_switch(operation: :ui_trigger_disable, confirmation: params[:confirmation_text])

  @trigger.disable!(confirmation: params[:confirmation_text], actor: current_actor)
  flash[:success] = "Trigger '#{@trigger.trigger_name}' disabled successfully."
  redirect_to redirect_path
rescue PgSqlTriggers::KillSwitchError => e
  flash[:error] = e.message
  redirect_to redirect_path
rescue StandardError => e
  Rails.logger.error("Disable failed: #{e.message}\n#{e.backtrace.join("\n")}")
  flash[:error] = "Failed to disable trigger: #{e.message}"
  redirect_to redirect_path
end

#dropObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/pg_sql_triggers/triggers_controller.rb', line 50

def drop
  # Validate required parameters
  if params[:reason].blank?
    flash[:error] = "Reason is required for dropping a trigger."
    redirect_to redirect_path
    return
  end

  # Check kill switch before dropping trigger
  check_kill_switch(operation: :trigger_drop, confirmation: params[:confirmation_text])

  # Drop the trigger
  @trigger.drop!(
    reason: params[:reason],
    confirmation: params[:confirmation_text],
    actor: current_actor
  )

  flash[:success] = "Trigger '#{@trigger.trigger_name}' dropped successfully."
  redirect_to dashboard_path
rescue PgSqlTriggers::KillSwitchError => e
  flash[:error] = e.message
  redirect_to redirect_path
rescue ArgumentError => e
  flash[:error] = "Invalid request: #{e.message}"
  redirect_to redirect_path
rescue StandardError => e
  Rails.logger.error("Drop failed: #{e.message}\n#{e.backtrace.join("\n")}")
  flash[:error] = "Failed to drop trigger: #{e.message}"
  redirect_to redirect_path
end

#enableObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/pg_sql_triggers/triggers_controller.rb', line 18

def enable
  # Check kill switch before enabling trigger
  check_kill_switch(operation: :ui_trigger_enable, confirmation: params[:confirmation_text])

  @trigger.enable!(confirmation: params[:confirmation_text], actor: current_actor)
  flash[:success] = "Trigger '#{@trigger.trigger_name}' enabled successfully."
  redirect_to redirect_path
rescue PgSqlTriggers::KillSwitchError => e
  flash[:error] = e.message
  redirect_to redirect_path
rescue StandardError => e
  Rails.logger.error("Enable failed: #{e.message}\n#{e.backtrace.join("\n")}")
  flash[:error] = "Failed to enable trigger: #{e.message}"
  redirect_to redirect_path
end

#re_executeObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/pg_sql_triggers/triggers_controller.rb', line 82

def re_execute
  # Validate required parameters
  if params[:reason].blank?
    flash[:error] = "Reason is required for re-executing a trigger."
    redirect_to redirect_path
    return
  end

  # Check kill switch before re-executing trigger
  check_kill_switch(operation: :trigger_re_execute, confirmation: params[:confirmation_text])

  # Re-execute the trigger
  @trigger.re_execute!(
    reason: params[:reason],
    confirmation: params[:confirmation_text],
    actor: current_actor
  )

  flash[:success] = "Trigger '#{@trigger.trigger_name}' re-executed successfully."
  redirect_to redirect_path
rescue PgSqlTriggers::KillSwitchError => e
  flash[:error] = e.message
  redirect_to redirect_path
rescue ArgumentError => e
  flash[:error] = "Invalid request: #{e.message}"
  redirect_to redirect_path
rescue StandardError => e
  Rails.logger.error("Re-execute failed: #{e.message}\n#{e.backtrace.join("\n")}")
  flash[:error] = "Failed to re-execute trigger: #{e.message}"
  redirect_to redirect_path
end

#showObject



12
13
14
15
16
# File 'app/controllers/pg_sql_triggers/triggers_controller.rb', line 12

def show
  # Load trigger details and drift information
  @drift_info = calculate_drift_info
  @dependency_related = PgSqlTriggers::Registry::Validator.related_triggers_for_show(@trigger)
end