Sfoglia il codice sorgente

Added creator to dashboards and checks

Andrew Kane 9 anni fa
parent
commit
25a50f9f51

+ 3 - 0
app/controllers/blazer/checks_controller.rb

@@ -13,6 +13,9 @@ module Blazer
 
     def create
       @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=)
 
       if @check.save
         redirect_to run_check_path(@check)

+ 3 - 0
app/controllers/blazer/dashboards_controller.rb

@@ -12,6 +12,9 @@ module Blazer
 
     def create
       @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=)
 
       if update_dashboard(@dashboard)
         redirect_to dashboard_path(@dashboard)

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

@@ -8,7 +8,7 @@ module Blazer
         Blazer::Dashboard.order(:name).map do |d|
           {
             name: "<strong>#{view_context.link_to(d.name, d)}</strong>",
-            creator: nil,
+            creator: d.respond_to?(:creator) && d.creator == blazer_user ? "You" : d.try(:creator).try(Blazer.user_name),
             hide: d.name.gsub(/\s+/, ""),
             vars: nil
           }

+ 5 - 1
lib/blazer/engine.rb

@@ -21,7 +21,11 @@ module Blazer
 
       Blazer.check_schedules = Blazer.settings["check_schedules"] if Blazer.settings.key?("check_schedules")
 
-      Blazer::Query.belongs_to :creator, class_name: Blazer.user_class.to_s if Blazer.user_class
+      if Blazer.user_class
+        Blazer::Query.belongs_to :creator, class_name: Blazer.user_class.to_s
+        Blazer::Dashboard.belongs_to :creator, class_name: Blazer.user_class.to_s
+        Blazer::Check.belongs_to :creator, class_name: Blazer.user_class.to_s
+      end
 
       Blazer.cache ||= Rails.cache
     end

+ 2 - 0
lib/generators/blazer/templates/install.rb

@@ -18,6 +18,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration
     end
 
     create_table :blazer_dashboards do |t|
+      t.refrences :creator
       t.text :name
       t.timestamps
     end
@@ -30,6 +31,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration
     end
 
     create_table :blazer_checks do |t|
+      t.references :creator
       t.references :query
       t.string :state
       t.string :schedule