Skip to content
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

Merged
merged 1 commit into from
Feb 26, 2018

Conversation

ares
Copy link
Member

@ares ares commented Feb 16, 2018

This allows defining a custom notification builder for feature, if you want to see example usage, see theforeman/foreman_openscap#326

the fact we now store the feature makes it easy in future to add more customization, e.g. job invocation page, based on it

class AddFeatureIdToJobInvocation < ActiveRecord::Migration[4.2]
def change
add_column :job_invocations, :remote_execution_feature_id, :integer, :index => true
add_foreign_key :job_invocations, :remote_execution_features, :column => :remote_execution_feature_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Line is too long. [105/80]

@@ -0,0 +1,6 @@
class AddFeatureIdToJobInvocation < ActiveRecord::Migration[4.2]
def change
add_column :job_invocations, :remote_execution_feature_id, :integer, :index => true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Line is too long. [87/80]

@@ -0,0 +1,6 @@
class AddFeatureIdToJobInvocation < ActiveRecord::Migration[4.2]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing top-level class documentation comment.
Missing magic comment # frozen_string_literal: true.

@@ -0,0 +1,5 @@
class AddNotificationBuilderToRemoteExecutionFeature < ActiveRecord::Migration[4.2]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing top-level class documentation comment.
Missing magic comment # frozen_string_literal: true.
Line is too long. [83/80]

attributes.delete(:host_action_button)
attrs = [ :host_action_button, :notification_builder ]
attrs.each do |attr|
unless self.attribute_names.include?(attr.to_s)

Choose a reason for hiding this comment

The 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 &&/||.
Redundant self detected.

@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [88/80]

@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %i or %I for an array of symbols.
Line is too long. [101/80]

@@ -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]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [85/80]

@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [157/80]
Use the new Ruby 1.9 hash syntax.

@@ -233,6 +236,7 @@ def params
:targeting => targeting_params,
:triggering => {},
:concurrency_control => {},
:remote_execution_feature_id => @feature.id,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

@@ -87,7 +89,17 @@ def notification_recipients_ids
end

def build_notification
UINotifications::RemoteExecutionJobs::BaseJobFinish.new(self)
# self.remote_execution_feature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this left here intentionally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, I'll remove when you'll add more comments :-)

Copy link
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good code-wise, but Jenkins is not happy

},
:targeting_type => 'static_query',
:search_query => 'some hosts',
:inputs => {input1.name => 'some_value'}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Space inside { missing.
Space inside } missing.

:time_span => time_span
},
:targeting_type => 'static_query',
:search_query => 'some hosts',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

:concurrency_level => level,
:time_span => time_span
},
:targeting_type => 'static_query',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

:remote_execution_feature_id => feature.id,
:concurrency_control => {
:concurrency_level => level,
:time_span => time_span

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

:job_template_id => trying_job_template_1.id,
:remote_execution_feature_id => feature.id,
:concurrency_control => {
:concurrency_level => level,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

{ :job_category => trying_job_template_1.job_category,
:job_template_id => trying_job_template_1.id,
:remote_execution_feature_id => feature.id,
:concurrency_control => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

let(:params) do
{ :job_category => trying_job_template_1.job_category,
:job_template_id => trying_job_template_1.id,
:remote_execution_feature_id => feature.id,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

let(:feature) { FacotryBot.create(:remote_execution_feature) }
let(:params) do
{ :job_category => trying_job_template_1.job_category,
:job_template_id => trying_job_template_1.id,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

context 'with rex feature defined' do
let(:feature) { FacotryBot.create(:remote_execution_feature) }
let(:params) do
{ :job_category => trying_job_template_1.job_category,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

},
:targeting_type => 'static_query',
:search_query => 'some hosts',
:inputs => {input1.name => 'some_value'}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Space inside { missing.
Space inside } missing.

:time_span => time_span
},
:targeting_type => 'static_query',
:search_query => 'some hosts',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

:concurrency_level => level,
:time_span => time_span
},
:targeting_type => 'static_query',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

:remote_execution_feature_id => feature.id,
:concurrency_control => {
:concurrency_level => level,
:time_span => time_span

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

:job_template_id => trying_job_template_1.id,
:remote_execution_feature_id => feature.id,
:concurrency_control => {
:concurrency_level => level,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

{ :job_category => trying_job_template_1.job_category,
:job_template_id => trying_job_template_1.id,
:remote_execution_feature_id => feature.id,
:concurrency_control => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

let(:params) do
{ :job_category => trying_job_template_1.job_category,
:job_template_id => trying_job_template_1.id,
:remote_execution_feature_id => feature.id,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

let(:feature) { FacotryBot.create(:remote_execution_feature) }
let(:params) do
{ :job_category => trying_job_template_1.job_category,
:job_template_id => trying_job_template_1.id,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

context 'with rex feature defined' do
let(:feature) { FacotryBot.create(:remote_execution_feature) }
let(:params) do
{ :job_category => trying_job_template_1.job_category,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

@ares ares force-pushed the fix/22609 branch 2 times, most recently from 3d9bf8b to 183f51d Compare February 23, 2018 09:57
:remote_execution_feature_id => feature.id,
:targeting_type => 'static_query',
:search_query => 'some hosts',
:inputs => {input1.name => 'some_value'}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Space inside { missing.
Space inside } missing.

@@ -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?

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.

@@ -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?

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.

@ares
Copy link
Member Author

ares commented Feb 26, 2018

cops issues resolved, all should be green this time

Copy link
Member

@iNecas iNecas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK: waiting for jenkins

@adamruzicka
Copy link
Contributor

Mr. J is happy with sqlite and postgresql, but mysql timed out. I'd say this is good to go :shipit:

@ares
Copy link
Member Author

ares commented Feb 26, 2018

I swear it was green before also on PG :-)

@adamruzicka adamruzicka merged commit 0b9bbd9 into theforeman:master Feb 26, 2018
@adamruzicka
Copy link
Contributor

Merged, thanks @ares !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants