Ver código fonte

Merge pull request #46 from markrebec/auth_filter

Adds optional before_action configuration for blazer controller authentication/authorization
Andrew Kane 8 anos atrás
pai
commit
99b58a3f64

+ 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.before_action
+      before_action Blazer.before_action
+    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 :before_action
     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.before_action = Blazer.settings["before_action"] if Blazer.settings["before_action"]
 
       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)
+# before_action: :authenticate!
+
 # email to send checks from
 # from_email: blazer@example.org