Skip to content

Fixes #22609 - customizable notifications per feature#318

Merged
adamruzicka merged 1 commit into
theforeman:masterfrom
ares:fix/22609
Feb 26, 2018
Merged

Fixes #22609 - customizable notifications per feature#318
adamruzicka merged 1 commit into
theforeman:masterfrom
ares:fix/22609

Conversation

@ares

@ares ares commented Feb 16, 2018

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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]

Copy link
Copy Markdown

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]

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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.

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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]

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]

Copy link
Copy Markdown

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]


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

Copy link
Copy Markdown

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.

:targeting => targeting_params,
:triggering => {},
:concurrency_control => {},
:remote_execution_feature_id => @feature.id,

Copy link
Copy Markdown

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.

Comment thread app/models/job_invocation.rb Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
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 :-)

@adamruzicka adamruzicka left a comment

Copy link
Copy Markdown
Contributor

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'}}

Copy link
Copy Markdown

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',

Copy link
Copy Markdown

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',

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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,

Copy link
Copy Markdown

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 => {

Copy link
Copy Markdown

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,

Copy link
Copy Markdown

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,

Copy link
Copy Markdown

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,

Copy link
Copy Markdown

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'}}

Copy link
Copy Markdown

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',

Copy link
Copy Markdown

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',

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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,

Copy link
Copy Markdown

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 => {

Copy link
Copy Markdown

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,

Copy link
Copy Markdown

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,

Copy link
Copy Markdown

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,

Copy link
Copy Markdown

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'}}

Copy link
Copy Markdown

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.

def build_notification
UINotifications::RemoteExecutionJobs::BaseJobFinish.new(self)
klass = nil
if self.remote_execution_feature && self.remote_execution_feature.notification_builder.present?

Copy link
Copy Markdown

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.

def build_notification
UINotifications::RemoteExecutionJobs::BaseJobFinish.new(self)
klass = nil
if self.remote_execution_feature && self.remote_execution_feature.notification_builder.present?

Copy link
Copy Markdown

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

ares commented Feb 26, 2018

Copy link
Copy Markdown
Member Author

cops issues resolved, all should be green this time

@iNecas iNecas left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

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

@ares

ares commented Feb 26, 2018

Copy link
Copy Markdown
Member Author

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

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

Copy link
Copy Markdown
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