diff --git a/app/lib/actions/katello/content_view/promote.rb b/app/lib/actions/katello/content_view/promote.rb index 83d327bbe17..e15df02f9f2 100644 --- a/app/lib/actions/katello/content_view/promote.rb +++ b/app/lib/actions/katello/content_view/promote.rb @@ -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) @@ -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 diff --git a/app/mailers/katello/task_mailer.rb b/app/mailers/katello/task_mailer.rb index c19dd0fed6f..fc1bb27fd17 100644 --- a/app/mailers/katello/task_mailer.rb +++ b/app/mailers/katello/task_mailer.rb @@ -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 diff --git a/app/views/katello/task_mailer/cv_promote_failure.html.erb b/app/views/katello/task_mailer/cv_promote_failure.html.erb new file mode 100644 index 00000000000..48dce54339a --- /dev/null +++ b/app/views/katello/task_mailer/cv_promote_failure.html.erb @@ -0,0 +1,31 @@ +

+ <%= _("%{label} failed.") % { :label => @task.action } %> +

+ +
+ + + + + + + + + + + + + + + + + +
<%= _('Content view') %><%= link_to @content_view.name, "#{katello_url}content_views/#{@content_view.id}" %>
<%= _('Task ID') %><%= link_to @task.id, foreman_tasks_task_url(@task.id) %>
<%= _('Task state') %><%= @task.state %>
<%= _('Task result') %><%= @task.result %>
+ + Errors: + +
diff --git a/app/views/katello/task_mailer/cv_promote_failure.text.erb b/app/views/katello/task_mailer/cv_promote_failure.text.erb new file mode 100644 index 00000000000..000b0525b95 --- /dev/null +++ b/app/views/katello/task_mailer/cv_promote_failure.text.erb @@ -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 %> diff --git a/db/seeds.d/106-mail_notifications.rb b/db/seeds.d/106-mail_notifications.rb index cdce426cd10..a4c69ebf32b 100644 --- a/db/seeds.d/106-mail_notifications.rb +++ b/db/seeds.d/106-mail_notifications.rb @@ -11,6 +11,7 @@ N_('Promote errata') N_('Repository sync failure') N_('Content view publish failure') + N_('Content view promote failure') # Mail Notifications notifications = [ @@ -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', } ]