app/controllers/blazer/checks_controller.rb in sql-jarvis-2.1.6 vs app/controllers/blazer/checks_controller.rb in sql-jarvis-2.1.7
- old
+ new
@@ -1,18 +1,18 @@
module Blazer
class ChecksController < BaseController
before_action :set_check, only: [:edit, :update, :destroy, :run]
+ before_action :set_new_check, only: [:new]
before_action :set_accessible, only: [:new, :edit]
def index
state_order = [nil, "disabled", "error", "timed out", "failing", "passing"]
@checks = Blazer::Check.joins(:query).includes(:query).order("blazer_queries.name, blazer_checks.id").to_a.sort_by { |q| state_order.index(q.state) || 99 }
@checks.select! { |c| "#{c.query.name} #{c.emails}".downcase.include?(params[:q]) } if params[:q]
end
def new
- @check = Blazer::Check.new(query_id: params[:query_id])
end
def create
@check = Blazer::Check.new(check_params)
# use creator_id instead of creator
@@ -52,18 +52,23 @@
def set_check
@check = Blazer::Check.find(params[:id])
end
+ def set_new_check
+ @check = Blazer::Check.new(query_id: params[:query_id])
+ end
+
def set_accessible
- @slack_mentions ||= get_slack_mentions + @check.slack_members.each_with_object([]) { |m, list| list << [m, m] if m.present? }
+ existed_members = @check&.slack_members.presence || []
+ @slack_mentions ||= get_slack_mentions + existed_members.each_with_object([]) { |m, list| list << [m, m] if m.present? }
ensure
@slack_mentions ||= []
end
def get_slack_mentions
return [] unless Blazer.settings.key?('slack_mentions')
- Blazer::RunStatement.new.perform(Blazer.data_sources[@check.query.data_source], Blazer.settings['slack_mentions'], {}).rows.map do |row|
+ Blazer::RunStatement.new.perform(Blazer.data_sources[@check.query&.data_source], Blazer.settings['slack_mentions'], {}).rows.map do |row|
[row.last, "[#{row.first}] #{row.second} - ##{row.last}"]
end
rescue
[]
end