Bladeren bron

fix devise model name (example - administarator)

Ermolaev Andrey 9 jaren geleden
bovenliggende
commit
04c19ebf7e
4 gewijzigde bestanden met toevoegingen van 16 en 8 verwijderingen
  1. 8 2
      app/controllers/blazer/queries_controller.rb
  2. 1 1
      app/views/blazer/queries/index.html.erb
  3. 1 4
      lib/blazer.rb
  4. 6 1
      lib/blazer/engine.rb

+ 8 - 2
app/controllers/blazer/queries_controller.rb

@@ -26,7 +26,7 @@ module Blazer
 
     def create
       @query = Blazer::Query.new(query_params)
-      @query.creator = current_user if respond_to?(:current_user) && Blazer.user_class
+      @query.creator = blazer_user
 
       if @query.save
         redirect_to query_path(@query, variable_params)
@@ -65,7 +65,7 @@ module Blazer
         if Blazer.audit
           audit = Blazer::Audit.new(statement: @statement)
           audit.query = @query
-          audit.user = current_user if respond_to?(:current_user) && Blazer.user_class
+          audit.user = blazer_user
           audit.save!
         end
 
@@ -226,5 +226,11 @@ module Blazer
     def postgresql?
       Blazer::Connection.connection.adapter_name == "PostgreSQL"
     end
+
+    def blazer_user
+      send(Blazer.current_user_name) if Blazer.current_user_name
+    end
+    helper_method :blazer_user
+
   end
 end

+ 1 - 1
app/views/blazer/queries/index.html.erb

@@ -30,7 +30,7 @@
           <td class="creator text-right text-muted">
             <% if query.respond_to?(:creator) && (creator = query.creator) && creator.respond_to?(Blazer.user_name) %>
               <% name = creator.send(Blazer.user_name) %>
-              <% if respond_to?(:current_user) and creator == current_user %>
+              <% if creator == blazer_user %>
                 You
                 <div class="hide">me <%= name %></div>
               <% else %>

+ 1 - 4
lib/blazer.rb

@@ -5,11 +5,8 @@ require "blazer/engine"
 
 module Blazer
   class << self
-    attr_accessor :audit
     attr_reader :time_zone
-    attr_accessor :user_name
-    attr_accessor :user_class
-    attr_accessor :timeout
+    attr_accessor :audit, :user_name, :user_class, :timeout, :current_user_name
   end
   self.audit = true
   self.user_name = :name

+ 6 - 1
lib/blazer/engine.rb

@@ -7,7 +7,12 @@ module Blazer
       app.config.assets.precompile << proc { |path| path =~ /\Ablazer\/application\.(js|css)\z/ }
 
       Blazer.time_zone ||= Time.zone
-      Blazer.user_class ||= User rescue nil
+      Blazer.user_class ||= Devise.mappings.values[0].class_name rescue nil
+
+      if Blazer.user_class
+        Blazer.current_user_name = "current_#{Blazer.user_class.downcase.singularize}"
+      end
+
       Blazer::Query.belongs_to :creator, class_name: Blazer.user_class.to_s if Blazer.user_class
     end
   end