Lots of updates
This commit is contained in:
@@ -2,19 +2,12 @@
|
||||
|
||||
class DsnsController < ApplicationController
|
||||
before_action :require_authentication
|
||||
before_action :set_dsn, only: [:show, :edit, :update, :disable, :enable]
|
||||
before_action :set_dsn, only: [:show, :edit, :update, :disable, :enable, :destroy]
|
||||
before_action :authorize_dsn_management, except: [:index, :show]
|
||||
|
||||
# GET /dsns
|
||||
def index
|
||||
@dsns = policy_scope(Dsn).order(created_at: :desc)
|
||||
|
||||
# Generate environment DSNs using default DSN key or first enabled DSN
|
||||
default_dsn = Dsn.enabled.first
|
||||
if default_dsn
|
||||
@external_dsn = generate_external_dsn(default_dsn.key)
|
||||
@internal_dsn = generate_internal_dsn(default_dsn.key)
|
||||
end
|
||||
end
|
||||
|
||||
# GET /dsns/new
|
||||
@@ -64,6 +57,20 @@ class DsnsController < ApplicationController
|
||||
redirect_to @dsn, notice: 'DSN was enabled.'
|
||||
end
|
||||
|
||||
# DELETE /dsns/:id
|
||||
def destroy
|
||||
# Only allow deletion of disabled DSNs for safety
|
||||
if @dsn.enabled?
|
||||
redirect_to @dsn, alert: 'Cannot delete an enabled DSN. Please disable it first.'
|
||||
return
|
||||
end
|
||||
|
||||
dsn_name = @dsn.name
|
||||
@dsn.destroy
|
||||
|
||||
redirect_to dsns_path, notice: "DSN '#{dsn_name}' was successfully deleted."
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_dsn
|
||||
@@ -78,18 +85,4 @@ class DsnsController < ApplicationController
|
||||
# Only allow admins to manage DSNs
|
||||
redirect_to root_path, alert: 'Access denied' unless Current.user&.admin?
|
||||
end
|
||||
|
||||
def generate_external_dsn(key)
|
||||
host = ENV.fetch("BAFFLE_HOST", "localhost:3000")
|
||||
protocol = host.include?("localhost") ? "http" : "https"
|
||||
"#{protocol}://#{key}@#{host}"
|
||||
end
|
||||
|
||||
def generate_internal_dsn(key)
|
||||
internal_host = ENV.fetch("BAFFLE_INTERNAL_HOST", nil)
|
||||
return nil unless internal_host.present?
|
||||
|
||||
protocol = "http" # Internal connections use HTTP
|
||||
"#{protocol}://#{key}@#{internal_host}"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user