Andrew Kane 9 лет назад
Родитель
Сommit
08a489281f

+ 1 - 1
app/controllers/blazer/checks_controller.rb

@@ -15,7 +15,7 @@ module Blazer
       @check = Blazer::Check.new(check_params)
       # use creator_id instead of creator
       # since we setup association without checking if column exists
-      @check.creator = blazer_user if @check.respond_to?(:creator_id=)
+      @check.creator = blazer_user if @check.respond_to?(:creator_id=) && blazer_user
 
       if @check.save
         redirect_to run_check_path(@check)

+ 1 - 1
app/controllers/blazer/dashboards_controller.rb

@@ -14,7 +14,7 @@ module Blazer
       @dashboard = Blazer::Dashboard.new
       # use creator_id instead of creator
       # since we setup association without checking if column exists
-      @dashboard.creator = blazer_user if @dashboard.respond_to?(:creator_id=)
+      @dashboard.creator = blazer_user if @dashboard.respond_to?(:creator_id=) && blazer_user
 
       if update_dashboard(@dashboard)
         redirect_to dashboard_path(@dashboard)

+ 5 - 6
app/controllers/blazer/queries_controller.rb

@@ -162,7 +162,7 @@ module Blazer
           render layout: false
         end
         format.csv do
-          send_data csv_data(@columns, @rows), type: "text/csv; charset=utf-8; header=present", disposition: "attachment; filename=\"#{@query.try(:name).try(:parameterize).presence || 'query'}.csv\""
+          send_data csv_data(@columns, @rows, @data_source), type: "text/csv; charset=utf-8; header=present", disposition: "attachment; filename=\"#{@query.try(:name).try(:parameterize).presence || 'query'}.csv\""
         end
       end
     end
@@ -240,18 +240,17 @@ module Blazer
       params.require(:query).permit(:name, :description, :statement, :data_source)
     end
 
-    def csv_data(columns, rows)
+    def csv_data(columns, rows, data_source)
       CSV.generate do |csv|
         csv << columns
         rows.each do |row|
-          csv << row.each_with_index.map { |v, i| v.is_a?(Time) ? blazer_time_value(columns[i], v) : v }
+          csv << row.each_with_index.map { |v, i| v.is_a?(Time) ? blazer_time_value(data_source, columns[i], v) : v }
         end
       end
     end
 
-    def blazer_time_value(k, v)
-      # yuck, instance var
-      @data_source.local_time_suffix.any? { |s| k.ends_with?(s) } ? v.to_s.sub(" UTC", "") : v.in_time_zone(Blazer.time_zone)
+    def blazer_time_value(data_source, k, v)
+      data_source.local_time_suffix.any? { |s| k.ends_with?(s) } ? v.to_s.sub(" UTC", "") : v.in_time_zone(Blazer.time_zone)
     end
     helper_method :blazer_time_value
   end

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

@@ -105,7 +105,7 @@
                     <% k = @columns[i] %>
                     <td>
                       <% if v.is_a?(Time) %>
-                        <% v = blazer_time_value(k, v) %>
+                        <% v = blazer_time_value(@data_source, k, v) %>
                       <% end %>
 
                       <% unless v.nil? %>