Skip to content

Commit

Permalink
Fixes #TBFL - Opt-in email notification on cv publish failure
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Sep 18, 2023
1 parent 4677602 commit 94fc88c
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/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Publish < Actions::EntryAction
include ::Actions::ObservableAction
attr_accessor :version
execution_plan_hooks.use :trigger_capsule_sync, :on => :success
execution_plan_hooks.use :notify_on_failure, :on => :failure

# rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
def plan(content_view, description = "", options = {importing: false, syncable: false}) # rubocop:disable Metrics/PerceivedComplexity
Expand Down Expand Up @@ -132,6 +133,14 @@ def trigger_capsule_sync(_execution_plan)
end
end

def notify_on_failure(_plan)
notification = MailNotification[:cv_publish_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 content_view_version_id
input['content_view_version_id']
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 @@ -14,5 +14,17 @@ def repo_sync_failure(options)
end
end
end

def cv_publish_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_publish_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_publish_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 @@ -10,6 +10,7 @@
N_('Sync errata')
N_('Promote errata')
N_('Repository sync failure')
N_('Content view publish failure')

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

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

Expand Down

0 comments on commit 94fc88c

Please sign in to comment.