Jelajahi Sumber

adds auth_filter config directive to provide an optional before_action for blazer controllers

Mark Rebec 8 tahun lalu
induk
melakukan
070f5fe020

+ 4 - 0
app/controllers/blazer/base_controller.rb

@@ -9,6 +9,10 @@ module Blazer
       http_basic_authenticate_with name: ENV["BLAZER_USERNAME"], password: ENV["BLAZER_PASSWORD"]
     end
 
+    if Blazer.auth_filter
+      before_action Blazer.auth_filter
+    end
+
     layout "blazer/application"
 
     before_action :ensure_database_url

+ 1 - 0
lib/blazer.rb

@@ -13,6 +13,7 @@ module Blazer
     attr_accessor :user_name
     attr_accessor :user_class
     attr_accessor :user_method
+    attr_accessor :auth_filter
     attr_accessor :from_email
     attr_accessor :cache
     attr_accessor :transform_statement

+ 1 - 0
lib/blazer/engine.rb

@@ -11,6 +11,7 @@ module Blazer
       Blazer.audit = Blazer.settings.key?("audit") ? Blazer.settings["audit"] : true
       Blazer.user_name = Blazer.settings["user_name"] if Blazer.settings["user_name"]
       Blazer.from_email = Blazer.settings["from_email"] if Blazer.settings["from_email"]
+      Blazer.auth_filter = Blazer.settings["auth_filter"] if Blazer.settings["auth_filter"]
 
       Blazer.user_class ||= Blazer.settings.key?("user_class") ? Blazer.settings["user_class"] : (User rescue nil)
       Blazer.user_method = Blazer.settings["user_method"]

+ 3 - 0
lib/generators/blazer/templates/config.yml

@@ -40,5 +40,8 @@ audit: true
 # method name for the user model
 # user_name: name
 
+# optional auth method to use as a before_action (default: nil)
+# auth_filter: :authenticate!
+
 # email to send checks from
 # from_email: blazer@example.org