From 7717b497f1538377d94e38c137ce6545bebcf0ec Mon Sep 17 00:00:00 2001
From: Alexander Olofsson <alexander.olofsson@liu.se>
Date: Thu, 2 May 2019 10:06:15 +0200
Subject: [PATCH] Allow for specifying context on actions

---
 app/lib/actions/foreman_template_tasks/template_action.rb  | 7 +++++++
 .../foreman_template_tasks/template_export_action.rb       | 4 ----
 .../foreman_template_tasks/template_import_action.rb       | 4 ----
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/app/lib/actions/foreman_template_tasks/template_action.rb b/app/lib/actions/foreman_template_tasks/template_action.rb
index 6530a7c..83b6c71 100644
--- a/app/lib/actions/foreman_template_tasks/template_action.rb
+++ b/app/lib/actions/foreman_template_tasks/template_action.rb
@@ -8,6 +8,7 @@ module Actions
       middleware.use Actions::Middleware::KeepCurrentUser
 
       def plan(template_params = {})
+        input.update context: template_params.delete(:context)
         input.update task_params: template_params
         plan_self
       end
@@ -50,6 +51,12 @@ module Actions
         raise NotImplementedError
       end
 
+      def humanized_name
+        format N_('%<action>s Foreman Templates%<context>s'),
+               action: humanized_action,
+               context: input[:context] ? " (#{input[:context]})" : ''
+      end
+
       def task_output
         (output[:results] || []).map do |r|
           {
diff --git a/app/lib/actions/foreman_template_tasks/template_export_action.rb b/app/lib/actions/foreman_template_tasks/template_export_action.rb
index 131d64e..0b97739 100644
--- a/app/lib/actions/foreman_template_tasks/template_export_action.rb
+++ b/app/lib/actions/foreman_template_tasks/template_export_action.rb
@@ -12,10 +12,6 @@ module Actions
       def humanized_action
         'Export'
       end
-
-      def humanized_name
-        _('Export Foreman Templates')
-      end
     end
   end
 end
diff --git a/app/lib/actions/foreman_template_tasks/template_import_action.rb b/app/lib/actions/foreman_template_tasks/template_import_action.rb
index 0f17106..c405f2b 100644
--- a/app/lib/actions/foreman_template_tasks/template_import_action.rb
+++ b/app/lib/actions/foreman_template_tasks/template_import_action.rb
@@ -12,10 +12,6 @@ module Actions
       def humanized_action
         'Import'
       end
-
-      def humanized_name
-        _('Import Foreman Templates')
-      end
     end
   end
 end
-- 
GitLab