Skip to content

Business intelligence made simple

Added creator to dashboards and checks

Andrew Kane25a50f9f51f2
diff --git a/app/controllers/blazer/checks_controller.rb b/app/controllers/blazer/checks_controller.rb
index 673de010..695c314c 100644
--- a/app/controllers/blazer/checks_controller.rb
+++ b/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)
diff --git a/app/controllers/blazer/dashboards_controller.rb b/app/controllers/blazer/dashboards_controller.rb
index 368612a6..cdc1eb7b 100644
--- a/app/controllers/blazer/dashboards_controller.rb
+++ b/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)
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rb
index 50f49ef0..855ce0aa 100644
--- a/app/controllers/blazer/queries_controller.rb
+++ b/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
}
diff --git a/lib/blazer/engine.rb b/lib/blazer/engine.rb
index 597c9e03..bb307ce3 100644
--- a/lib/blazer/engine.rb
+++ b/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
diff --git a/lib/generators/blazer/templates/install.rb b/lib/generators/blazer/templates/install.rb
index 568551fe..f463f6a9 100644
--- a/lib/generators/blazer/templates/install.rb
+++ b/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