Skip to content

Commit

Permalink
Fixes #TBFL - Opt-in email notification on cv promote failure
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Sep 18, 2023
1 parent 94fc88c commit 581ec07
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/lib/actions/katello/content_view/promote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module ContentView
class Promote < Actions::EntryAction
extend ApipieDSL::Class
include ::Actions::ObservableAction
execution_plan_hooks.use :notify_on_failure, :on => :failure

def plan(version, environments, is_force = false, description = nil, incremental_update = false)
action_subject(version.content_view)
Expand All @@ -23,6 +24,14 @@ def plan(version, environments, is_force = false, description = nil, incremental
end
end

def notify_on_failure(_plan)
notification = MailNotification[:cv_promote_failure]
view = ::Katello::ContentView.find(input.fetch(:content_view, {})[:id])
notification.users.each do |user|
notification.deliver(user: user, content_view: view, task: task)
end
end

def environments
input['environments']
end
Expand Down
12 changes: 12 additions & 0 deletions app/mailers/katello/task_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,17 @@ def cv_publish_failure(options)
end
end
end

def cv_promote_failure(options)
user, @content_view, @task = options.values_at(:user, :content_view, :task)

::User.as(user.login) do
subject = _("%{label} failed") % { :label => @task.action }

set_locale_for(user) do
mail(:to => user.mail, :subject => subject)
end
end
end
end
end
31 changes: 31 additions & 0 deletions app/views/katello/task_mailer/cv_promote_failure.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<p>
<%= _("%{label} failed.") % { :label => @task.action } %>
</p>

<div class="dashboard">
<table>
<tr>
<td><%= _('Content view') %></td>
<td><%= link_to @content_view.name, "#{katello_url}content_views/#{@content_view.id}" %></td>
</tr>
<tr>
<td><%= _('Task ID') %></td>
<td><%= link_to @task.id, foreman_tasks_task_url(@task.id) %></td>
</tr>
<tr>
<td><%= _('Task state') %></td>
<td><%= @task.state %></td>
</tr>
<tr>
<td><%= _('Task result') %></td>
<td><%= @task.result %></td>
</tr>
</table>

Errors:
<ul>
<% @task.execution_plan.errors.each do |error| %>
<li><%= error.exception_class %>: <%= error.message %></li>
<% end %>
</ul>
</div>
13 changes: 13 additions & 0 deletions app/views/katello/task_mailer/cv_promote_failure.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= _("%{label} failed.") % { :label => @task.action } %>

<%= _('Content view ID') %>: <%= @content_view.id %>
<%= _('Content view name') %>: <%= @content_view.name %>
<%= _('Task ID') %>: <%= @task.id %>
<%= _('Task state') %>: <%= @task.state %>
<%= _('Task result') %>: <%= @task.result %>
<%= _('Task details') %>: <%= foreman_tasks_task_url(@task) %>

Errors:
<% @task.execution_plan.errors.each do |error| %>
- <%= error.exception_class %>: <%= error.message %>
<% end %>
8 changes: 8 additions & 0 deletions db/seeds.d/106-mail_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
N_('Promote errata')
N_('Repository sync failure')
N_('Content view publish failure')
N_('Content view promote failure')

# Mail Notifications
notifications = [
Expand Down Expand Up @@ -55,6 +56,13 @@
:mailer => 'Katello::TaskMailer',
:method => 'cv_publish_failure',
:subscription_type => 'alert',
},

{:name => :content_view_promote_failure,
:description => N_('A notification about failed content view promotion'),
:mailer => 'Katello::TaskMailer',
:method => 'cv_promote_failure',
:subscription_type => 'alert',
}
]

Expand Down

0 comments on commit 581ec07

Please sign in to comment.