-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #22609 - customizable notifications per feature #318
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ class JobInvocation < ApplicationRecord | |
belongs_to :triggering, :class_name => 'ForemanTasks::Triggering' | ||
has_one :recurring_logic, :through => :triggering, :class_name => 'ForemanTasks::RecurringLogic' | ||
|
||
belongs_to :remote_execution_feature | ||
|
||
scope :with_task, -> { references(:task) } | ||
|
||
scoped_search :relation => :recurring_logic, :on => 'id', :rename => 'recurring_logic.id' | ||
|
@@ -87,7 +89,16 @@ def notification_recipients_ids | |
end | ||
|
||
def build_notification | ||
UINotifications::RemoteExecutionJobs::BaseJobFinish.new(self) | ||
klass = nil | ||
if self.remote_execution_feature && self.remote_execution_feature.notification_builder.present? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use safe navigation (&.) instead of checking if an object exists before calling the method. |
||
begin | ||
klass = remote_execution_feature.notification_builder.constantize | ||
rescue NameError => e | ||
logger.exception "REX feature defines unknown notification builder class", e | ||
end | ||
end | ||
klass ||= UINotifications::RemoteExecutionJobs::BaseJobFinish | ||
klass.new(self) | ||
end | ||
|
||
def status | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ def params | |
:targeting => ui_params.fetch(:targeting, {}).merge(:user_id => User.current.id), | ||
:triggering => triggering, | ||
:host_ids => ui_params[:host_ids], | ||
:remote_execution_feature_id => ui_params[:remote_execution_feature_id], | ||
:description_format => job_invocation_base[:description_format], | ||
:password => blank_to_nil(job_invocation_base[:password]), | ||
:key_passphrase => blank_to_nil(job_invocation_base[:key_passphrase]), | ||
|
@@ -94,6 +95,7 @@ def params | |
:targeting => targeting_params, | ||
:triggering => triggering_params, | ||
:description_format => api_params[:description_format], | ||
:remote_execution_feature_id => api_params[:remote_execution_feature_id], | ||
:concurrency_control => concurrency_control_params, | ||
:execution_timeout_interval => api_params[:execution_timeout_interval] || template.execution_timeout_interval, | ||
:template_invocations => template_invocations_params }.with_indifferent_access | ||
|
@@ -178,6 +180,7 @@ def params | |
:description_format => job_invocation.description_format, | ||
:concurrency_control => concurrency_control_params, | ||
:execution_timeout_interval => job_invocation.execution_timeout_interval, | ||
:remote_execution_feature_id => job_invocation.remote_execution_feature_id, | ||
:template_invocations => template_invocations_params }.with_indifferent_access | ||
end | ||
|
||
|
@@ -233,6 +236,7 @@ def params | |
:targeting => targeting_params, | ||
:triggering => {}, | ||
:concurrency_control => {}, | ||
:remote_execution_feature_id => @feature.id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
:template_invocations => template_invocations_params }.with_indifferent_access | ||
end | ||
|
||
|
@@ -281,7 +285,7 @@ def job_template | |
end | ||
|
||
attr_accessor :params, :job_invocation, :host_ids, :search_query | ||
delegate :job_category, :pattern_template_invocations, :template_invocations, :targeting, :triggering, :to => :job_invocation | ||
delegate :job_category, :remote_execution_feature_id, :pattern_template_invocations, :template_invocations, :targeting, :triggering, :to => :job_invocation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [157/80] |
||
|
||
def initialize(params, set_defaults = false) | ||
@params = params | ||
|
@@ -314,6 +318,7 @@ def self.for_feature(feature_label, hosts, provided_inputs = {}) | |
def compose | ||
job_invocation.job_category = validate_job_category(params[:job_category]) | ||
job_invocation.job_category ||= available_job_categories.first if @set_defaults | ||
job_invocation.remote_execution_feature_id = params[:remote_execution_feature_id] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [85/80] |
||
job_invocation.targeting = build_targeting | ||
job_invocation.triggering = build_triggering | ||
job_invocation.pattern_template_invocations = build_template_invocations | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class RemoteExecutionFeature < ApplicationRecord | ||
VALID_OPTIONS = [:provided_inputs, :description, :host_action_button].freeze | ||
VALID_OPTIONS = [:provided_inputs, :description, :host_action_button, :notification_builder].freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use %i or %I for an array of symbols. |
||
validates :label, :name, :presence => true, :uniqueness => true | ||
|
||
belongs_to :job_template | ||
|
@@ -27,11 +27,19 @@ def self.register(label, name, options = {}) | |
options[:host_action_button] = false unless options.key?(:host_action_button) | ||
|
||
feature = self.find_by(label: label) | ||
builder = options[:notification_builder] ? options[:notification_builder].to_s : nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [88/80] |
||
|
||
attributes = { :name => name, :provided_input_names => options[:provided_inputs], :description => options[:description], :host_action_button => options[:host_action_button] } | ||
attributes = { :name => name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
:provided_input_names => options[:provided_inputs], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
:description => options[:description], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
:host_action_button => options[:host_action_button], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
:notification_builder => builder } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
# in case DB does not have the attribute created yet but plugin initializer registers the feature, we need to skip this attribute | ||
unless self.attribute_names.include?('host_action_button') | ||
attributes.delete(:host_action_button) | ||
attrs = [ :host_action_button, :notification_builder ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use %i or %I for an array of symbols. |
||
attrs.each do |attr| | ||
unless self.attribute_names.include?(attr.to_s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. |
||
attributes.delete(attr) | ||
end | ||
end | ||
|
||
if feature.nil? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddNotificationBuilderToRemoteExecutionFeature < ActiveRecord::Migration[4.2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing top-level class documentation comment. |
||
def change | ||
add_column :remote_execution_features, :notification_builder, :string | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddFeatureIdToJobInvocation < ActiveRecord::Migration[4.2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing top-level class documentation comment. |
||
def change | ||
add_column :job_invocations, :remote_execution_feature_id, :integer, :index => true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
add_foreign_key :job_invocations, :remote_execution_features, :column => :remote_execution_feature_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use safe navigation (&.) instead of checking if an object exists before calling the method.