foreman-tasks 0.17.6 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc +2 -22
  3. data/.rubocop.yml +12 -12
  4. data/.rubocop_todo.yml +34 -116
  5. data/.travis.yml +2 -2
  6. data/app/controllers/foreman_tasks/api/recurring_logics_controller.rb +20 -1
  7. data/app/controllers/foreman_tasks/api/tasks_controller.rb +38 -11
  8. data/app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb +1 -1
  9. data/app/controllers/foreman_tasks/recurring_logics_controller.rb +19 -0
  10. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +0 -2
  11. data/app/lib/actions/helpers/humanizer.rb +1 -3
  12. data/app/lib/actions/proxy_action.rb +33 -12
  13. data/app/lib/foreman_tasks/concerns/polling_action_extensions.rb +12 -0
  14. data/app/models/foreman_tasks/concerns/action_triggering.rb +1 -1
  15. data/app/models/foreman_tasks/recurring_logic.rb +1 -0
  16. data/app/models/foreman_tasks/remote_task.rb +1 -0
  17. data/app/models/foreman_tasks/task.rb +4 -0
  18. data/app/models/foreman_tasks/task/dynflow_task.rb +1 -1
  19. data/app/models/foreman_tasks/task/search.rb +11 -1
  20. data/app/models/setting/foreman_tasks.rb +6 -1
  21. data/app/services/ui_notifications/tasks/task_bulk_cancel.rb +36 -0
  22. data/app/services/ui_notifications/tasks/task_bulk_resume.rb +38 -0
  23. data/app/views/foreman_tasks/api/recurring_logics/base.json.rabl +2 -1
  24. data/app/views/foreman_tasks/api/tasks/details.json.rabl +1 -0
  25. data/app/views/foreman_tasks/api/tasks/show.json.rabl +1 -1
  26. data/app/views/foreman_tasks/recurring_logics/index.html.erb +30 -0
  27. data/app/views/foreman_tasks/tasks/show.html.erb +3 -0
  28. data/babel.config.js +3 -0
  29. data/config/routes.rb +7 -0
  30. data/db/migrate/20200611090846_add_task_lock_index_on_resource_type_and_task_id.rb +9 -0
  31. data/db/seeds.d/30-notification_blueprints.rb +14 -0
  32. data/foreman-tasks.gemspec +5 -6
  33. data/gemfile.d/foreman-tasks.rb +1 -0
  34. data/lib/foreman_tasks/dynflow/console_authorizer.rb +2 -2
  35. data/lib/foreman_tasks/engine.rb +17 -14
  36. data/lib/foreman_tasks/tasks/cleanup.rake +3 -3
  37. data/lib/foreman_tasks/tasks/dynflow.rake +6 -0
  38. data/lib/foreman_tasks/tasks/export_tasks.rake +3 -3
  39. data/lib/foreman_tasks/test_extensions.rb +1 -1
  40. data/lib/foreman_tasks/version.rb +1 -1
  41. data/locale/action_names.rb +1 -1
  42. data/package.json +19 -79
  43. data/script/rails +2 -2
  44. data/script/travis_run_js_tests.sh +2 -2
  45. data/test/controllers/api/tasks_controller_test.rb +9 -0
  46. data/test/factories/task_factory.rb +34 -2
  47. data/test/foreman_tasks_test_helper.rb +4 -0
  48. data/test/lib/concerns/polling_action_extensions_test.rb +34 -0
  49. data/test/unit/actions/action_with_sub_plans_test.rb +1 -1
  50. data/test/unit/task_test.rb +160 -74
  51. data/webpack/ForemanTasks/Components/TaskDetails/Components/Task.js +4 -0
  52. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskInfo.js +1 -4
  53. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Errors.test.js +1 -1
  54. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Locks.test.js +1 -1
  55. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Raw.test.js +1 -1
  56. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/RunningSteps.test.js +1 -1
  57. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Task.test.js +2 -1
  58. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/TaskInfo.test.js +1 -1
  59. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/Task.test.js.snap +3 -1
  60. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskInfo.test.js.snap +9 -15
  61. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.stories.js +6 -2
  62. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsActions.js +2 -2
  63. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsSelectors.js +3 -0
  64. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.test.js +1 -1
  65. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsActions.test.js +1 -1
  66. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsReducer.test.js +1 -1
  67. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetails.test.js.snap +1 -0
  68. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/integration.test.js +1 -1
  69. data/webpack/ForemanTasks/Components/TaskDetails/index.js +2 -0
  70. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.stories.js +44 -40
  71. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.test.js +1 -1
  72. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.stories.js +45 -40
  73. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.test.js +1 -1
  74. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.stories.js +27 -22
  75. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.test.js +1 -1
  76. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.stories.js +61 -56
  77. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.test.js +1 -1
  78. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.stories.js +40 -35
  79. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.test.js +1 -1
  80. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.stories.js +21 -20
  81. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.test.js +1 -1
  82. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.stories.js +40 -39
  83. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.test.js +1 -1
  84. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.stories.js +16 -17
  85. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.test.js +1 -2
  86. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.stories.mdx +57 -0
  87. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.test.js +1 -1
  88. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.stories.js +36 -18
  89. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.test.js +1 -1
  90. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardConstants.js +5 -0
  91. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js +3 -2
  92. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboard.test.js +1 -1
  93. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardActions.test.js +1 -1
  94. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardReducer.test.js +1 -1
  95. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardSelectors.test.js +1 -1
  96. data/webpack/ForemanTasks/Components/TasksTable/Components/CancelConfirm.js +53 -0
  97. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmationModals.js +56 -0
  98. data/webpack/ForemanTasks/Components/TasksTable/Components/ResumeConfirm.js +52 -0
  99. data/webpack/ForemanTasks/Components/TasksTable/Components/SelectAllAlert.js +43 -0
  100. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ActionSelectButton.test.js +1 -1
  101. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/CancelConfirm.test.js +26 -0
  102. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ConfirmationModals.test.js +24 -0
  103. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ResumeConfirm.test.js +26 -0
  104. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/SelectAllAlert.test.js +29 -0
  105. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/TableSelectionCell.test.js +1 -1
  106. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/TableSelectionHeaderCell.test.js +1 -1
  107. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/CancelConfirm.test.js.snap +65 -0
  108. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ConfirmationModals.test.js.snap +30 -0
  109. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ResumeConfirm.test.js.snap +63 -0
  110. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/SelectAllAlert.test.js.snap +75 -0
  111. data/webpack/ForemanTasks/Components/TasksTable/SubTasksPage.js +4 -1
  112. data/webpack/ForemanTasks/Components/TasksTable/TasksBulkActions.js +164 -0
  113. data/webpack/ForemanTasks/Components/TasksTable/TasksTable.js +46 -22
  114. data/webpack/ForemanTasks/Components/TasksTable/TasksTableActionHelpers.js +52 -0
  115. data/webpack/ForemanTasks/Components/TasksTable/TasksTableActions.js +88 -87
  116. data/webpack/ForemanTasks/Components/TasksTable/TasksTableConstants.js +20 -5
  117. data/webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js +4 -3
  118. data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.js +128 -31
  119. data/webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js +26 -9
  120. data/webpack/ForemanTasks/Components/TasksTable/TasksTableSelectors.js +24 -16
  121. data/webpack/ForemanTasks/Components/TasksTable/__tests__/SubTasksPage.test.js +1 -1
  122. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksBulkActions.test.js +112 -0
  123. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksIndexPage.test.js +1 -1
  124. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTable.fixtures.js +12 -5
  125. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTable.test.js +1 -1
  126. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableActionHelpers.test.js +46 -0
  127. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableActions.test.js +28 -52
  128. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableHelpers.test.js +17 -1
  129. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTablePage.test.js +10 -2
  130. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableReducer.test.js +28 -8
  131. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/SubTasksPage.test.js.snap +15 -5
  132. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksBulkActions.test.js.snap +229 -0
  133. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksIndexPage.test.js.snap +14 -5
  134. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTableActions.test.js.snap +56 -85
  135. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTablePage.test.js.snap +160 -34
  136. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTableReducer.test.js.snap +43 -16
  137. data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/selectionHeaderCellFormatter.test.js +1 -1
  138. data/webpack/ForemanTasks/Components/TasksTable/formatters/selectionHeaderCellFormatter.js +2 -2
  139. data/webpack/ForemanTasks/Components/TasksTable/index.js +11 -4
  140. data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js +4 -4
  141. data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.test.js +1 -1
  142. data/webpack/ForemanTasks/Components/common/ActionButtons/CancelButton.test.js +1 -2
  143. data/webpack/ForemanTasks/Components/common/ActionButtons/ResumeButton.test.js +2 -2
  144. data/webpack/ForemanTasks/Components/common/ActionButtons/__snapshots__/ActionButton.test.js.snap +3 -3
  145. data/webpack/ForemanTasks/Components/common/ToastTypesConstants.js +11 -0
  146. data/webpack/ForemanTasks/ForemanTasks.test.js +1 -1
  147. data/webpack/ForemanTasks/Routes/ForemanTasksRouter.test.js +1 -1
  148. data/webpack/ForemanTasks/Routes/ForemanTasksRoutes.test.js +2 -3
  149. data/webpack/ForemanTasks/Routes/ShowTask/__tests__/ShowTask.test.js +1 -1
  150. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +2 -0
  151. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalHooks.js +10 -0
  152. data/webpack/__mocks__/foremanReact/components/ForemanModal/index.js +4 -0
  153. metadata +55 -24
  154. data/.babelrc +0 -35
  155. data/.storybook/addons.js +0 -2
  156. data/.storybook/config.js +0 -7
  157. data/.storybook/webpack.config.js +0 -63
  158. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.stories.js +0 -23
  159. data/webpack/ForemanTasks/Components/TasksTable/Components/ActionConfirmation.js +0 -49
  160. data/webpack/ForemanTasks/Components/TasksTable/Components/CancelResumeConfirm.js +0 -51
  161. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ActionConfirmation.test.js +0 -18
  162. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/CancelResumeConfirm.test.js +0 -28
  163. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ActionConfirmation.test.js.snap +0 -89
  164. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/CancelResumeConfirm.test.js.snap +0 -37
  165. data/webpack/stories/index.js +0 -10
  166. data/webpack/stories/index.scss +0 -7
  167. data/webpack/test_setup.js +0 -6
@@ -0,0 +1 @@
1
+ gem 'sqlite3'
@@ -34,7 +34,7 @@ module ForemanTasks
34
34
  # console no matter what task it is...
35
35
  edit_permission = Permission.where(:name => :edit_foreman_tasks, :resource_type => ForemanTasks::Task.name).first
36
36
  if @user.filters.joins(:filterings).unlimited.where('filterings.permission_id' => edit_permission).first
37
- return true
37
+ true
38
38
  end
39
39
  end
40
40
 
@@ -43,7 +43,7 @@ module ForemanTasks
43
43
  begin
44
44
  original_user = User.current
45
45
  User.current = @user
46
- return Authorizer.new(@user).can?(:edit_foreman_tasks, task)
46
+ Authorizer.new(@user).can?(:edit_foreman_tasks, task)
47
47
  ensure
48
48
  User.current = original_user
49
49
  end
@@ -7,10 +7,10 @@ module ForemanTasks
7
7
  engine_name 'foreman_tasks'
8
8
 
9
9
  initializer 'foreman_tasks.load_default_settings', :before => :load_config_initializers do
10
- require_dependency File.expand_path('../../../app/models/setting/foreman_tasks.rb', __FILE__) if begin
10
+ require_dependency File.expand_path('../../app/models/setting/foreman_tasks.rb', __dir__) if begin
11
11
  Setting.table_exists?
12
- rescue
13
- false
12
+ rescue
13
+ false
14
14
  end
15
15
  end
16
16
 
@@ -26,7 +26,7 @@ module ForemanTasks
26
26
  end
27
27
 
28
28
  initializer 'foreman_tasks.register_gettext', :after => :load_config_initializers do
29
- locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
29
+ locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
30
30
  locale_domain = 'foreman_tasks'
31
31
 
32
32
  Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
@@ -34,7 +34,7 @@ module ForemanTasks
34
34
 
35
35
  initializer 'foreman_tasks.register_plugin', :before => :finisher_hook do |_app|
36
36
  Foreman::Plugin.register :"foreman-tasks" do
37
- requires_foreman '>= 1.24.0'
37
+ requires_foreman '>= 2.0.0'
38
38
  divider :top_menu, :parent => :monitor_menu, :last => true, :caption => N_('Foreman Tasks')
39
39
  menu :top_menu, :tasks,
40
40
  :url_hash => { :controller => 'foreman_tasks/tasks', :action => :index },
@@ -53,15 +53,15 @@ module ForemanTasks
53
53
  :'foreman_tasks/react' => [:index],
54
54
  :'foreman_tasks/api/tasks' => [:bulk_search, :show, :index, :summary, :summary_sub_tasks, :details, :sub_tasks] }, :resource_type => ForemanTasks::Task.name
55
55
  permission :edit_foreman_tasks, { :'foreman_tasks/tasks' => [:resume, :unlock, :force_unlock, :cancel_step, :cancel, :abort],
56
- :'foreman_tasks/api/tasks' => [:bulk_resume] }, :resource_type => ForemanTasks::Task.name
56
+ :'foreman_tasks/api/tasks' => [:bulk_resume, :bulk_cancel] }, :resource_type => ForemanTasks::Task.name
57
57
 
58
58
  permission :create_recurring_logics, {}, :resource_type => ForemanTasks::RecurringLogic.name
59
59
 
60
60
  permission :view_recurring_logics, { :'foreman_tasks/recurring_logics' => [:index, :show],
61
61
  :'foreman_tasks/api/recurring_logics' => [:index, :show] }, :resource_type => ForemanTasks::RecurringLogic.name
62
62
 
63
- permission :edit_recurring_logics, { :'foreman_tasks/recurring_logics' => [:cancel, :enable, :disable],
64
- :'foreman_tasks/api/recurring_logics' => [:cancel, :update] }, :resource_type => ForemanTasks::RecurringLogic.name
63
+ permission :edit_recurring_logics, { :'foreman_tasks/recurring_logics' => [:cancel, :enable, :disable, :clear_cancelled],
64
+ :'foreman_tasks/api/recurring_logics' => [:cancel, :update, :bulk_destroy] }, :resource_type => ForemanTasks::RecurringLogic.name
65
65
  end
66
66
 
67
67
  add_all_permissions_to_default_roles
@@ -69,8 +69,10 @@ module ForemanTasks
69
69
  logger :dynflow, :enabled => true
70
70
  logger :action, :enabled => true
71
71
 
72
- role 'Tasks Manager', [:view_foreman_tasks, :edit_foreman_tasks]
73
- role 'Tasks Reader', [:view_foreman_tasks]
72
+ role 'Tasks Manager', [:view_foreman_tasks, :edit_foreman_tasks],
73
+ 'Role granting permissions to inspect, cancel, resume and unlock tasks'
74
+ role 'Tasks Reader', [:view_foreman_tasks],
75
+ 'Role granting permissions to inspect tasks'
74
76
 
75
77
  widget 'foreman_tasks/tasks/dashboard/tasks_status', :sizex => 6, :sizey => 1, :name => N_('Task Status')
76
78
  widget 'foreman_tasks/tasks/dashboard/latest_tasks_in_error_warning', :sizex => 6, :sizey => 1, :name => N_('Latest Warning/Error Tasks')
@@ -133,16 +135,17 @@ module ForemanTasks
133
135
  # to enable async Foreman operations using Dynflow
134
136
  if ENV['FOREMAN_TASKS_MONKEYS'] == 'true'
135
137
  config.to_prepare do
136
- ::Api::V2::HostsController.send :prepend, ForemanTasks::Concerns::HostsControllerExtension
137
- ::Host::Base.send :include, ForemanTasks::Concerns::HostActionSubject
138
+ ::Api::V2::HostsController.prepend ForemanTasks::Concerns::HostsControllerExtension
139
+ ::Host::Base.include ForemanTasks::Concerns::HostActionSubject
138
140
  end
139
141
  end
140
142
 
141
143
  config.to_prepare do
142
144
  ForemanTasks.dynflow.eager_load_actions! if ForemanTasks.dynflow.initialized?
143
145
 
144
- Authorizer.send(:prepend, AuthorizerExt)
145
- User.send(:include, ForemanTasks::Concerns::UserExtensions)
146
+ Authorizer.prepend AuthorizerExt
147
+ User.include ForemanTasks::Concerns::UserExtensions
148
+ ::Dynflow::Action::Polling.prepend ForemanTasks::Concerns::PollingActionExtensions
146
149
  end
147
150
 
148
151
  rake_tasks do
@@ -1,6 +1,6 @@
1
1
  namespace :foreman_tasks do
2
2
  namespace :cleanup do
3
- desc <<-DESC.strip_heredoc
3
+ desc <<~DESC
4
4
  Clean tasks based on filter and age. ENV variables:
5
5
 
6
6
  * TASK_SEARCH : scoped search filter (example: 'label = "Actions::Foreman::Host::ImportFacts"')
@@ -14,7 +14,7 @@ namespace :foreman_tasks do
14
14
  If TASK_SEARCH is set then AFTER, STATES can be set and it's used for cleanup. If TASK_SEARCH is not set then
15
15
  the cleanup respects the configuration file and setting AFTER or STATES will throw exception.
16
16
  DESC
17
- task :run => 'environment' do
17
+ task :run => ['environment', 'dynflow:client'] do
18
18
  options = {}
19
19
 
20
20
  options[:filter] = ENV['TASK_SEARCH'] if ENV['TASK_SEARCH']
@@ -38,7 +38,7 @@ namespace :foreman_tasks do
38
38
  end
39
39
 
40
40
  desc 'Show the current configuration for auto-cleanup'
41
- task :config => 'environment' do
41
+ task :config => ['environment', 'dynflow:client'] do
42
42
  if ForemanTasks::Cleaner.cleanup_settings[:after]
43
43
  puts _('The tasks will be deleted after %{after}') % { :after => ForemanTasks::Cleaner.cleanup_settings[:after] }
44
44
  else
@@ -0,0 +1,6 @@
1
+ namespace :dynflow do
2
+ task :client do
3
+ ::ForemanTasks.dynflow.config.remote = true
4
+ ::ForemanTasks.dynflow.initialize!
5
+ end
6
+ end
@@ -7,7 +7,7 @@
7
7
  require 'csv'
8
8
 
9
9
  namespace :foreman_tasks do
10
- desc <<-DESC.strip_heredoc
10
+ desc <<~DESC
11
11
  Export dynflow tasks based on filter. ENV variables:
12
12
 
13
13
  * TASK_SEARCH : scoped search filter (example: 'label = "Actions::Foreman::Host::ImportFacts"')
@@ -19,7 +19,7 @@ namespace :foreman_tasks do
19
19
  all unsuccessful tasks in the past 60 days. The default TASK_FORMAT is html
20
20
  which requires a tar.gz file extension.
21
21
  DESC
22
- task :export_tasks => :environment do
22
+ task :export_tasks => [:environment, 'dynflow:client'] do
23
23
  deprecated_options = { :tasks => 'TASK_SEARCH',
24
24
  :days => 'TASK_DAYS',
25
25
  :export => 'TASK_FILE' }
@@ -259,7 +259,7 @@ namespace :foreman_tasks do
259
259
 
260
260
  File.open(File.join(tmp_dir, 'index.html'), 'w') { |file| file.write(PageHelper.pagify(PageHelper.generate_index(tasks))) }
261
261
 
262
- sh("tar cvzf #{export_filename} #{tmp_dir} > /dev/null")
262
+ system("tar", "czf", export_filename, tmp_dir)
263
263
  end
264
264
  elsif format == 'csv'
265
265
  CSV.open(export_filename, 'wb') do |csv|
@@ -14,4 +14,4 @@ module ForemanTasks
14
14
  end
15
15
  end
16
16
 
17
- ActiveSupport::TestCase.send(:include, ForemanTasks::TestExtensions::AccessPermissionsTestExtension)
17
+ ActiveSupport::TestCase.include ForemanTasks::TestExtensions::AccessPermissionsTestExtension
@@ -1,3 +1,3 @@
1
1
  module ForemanTasks
2
- VERSION = '0.17.6'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
@@ -2,4 +2,4 @@
2
2
  _("Remote action:")
3
3
  _("Import Puppet classes")
4
4
  _("Import facts")
5
- _("Action with sub plans")
5
+ _("Action with sub plans")
@@ -4,14 +4,14 @@
4
4
  "description": "Foreman Tasks =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "lint": "./node_modules/.bin/eslint -c .eslintrc webpack/",
8
- "test": "node node_modules/.bin/jest --no-cache",
9
- "test:watch": "node node_modules/.bin/jest --watchAll",
10
- "test:current": "node node_modules/.bin/jest --watch",
11
- "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
12
- "storybook": "start-storybook -p 6006",
13
- "storybook:build": "node --max_old_space_size=2048 ./node_modules/.bin/build-storybook --config-dir .storybook --output-dir .storybook-dist",
14
- "storybook:deploy": "surge --project .storybook-dist",
7
+ "lint": "tfm-lint --plugin -d /webpack",
8
+ "test": "tfm-test --plugin",
9
+ "test:watch": "tfm-test --plugin --watchAll",
10
+ "test:current": "tfm-test --plugin --watch",
11
+ "publish-coverage": "tfm-publish-coverage",
12
+ "stories": "tfm-stories --plugin",
13
+ "stories:build": "tfm-build-stories --plugin",
14
+ "stories:deploy": "surge --project .storybook-dist",
15
15
  "create-react-component": "yo react-domain"
16
16
  },
17
17
  "repository": {
@@ -21,88 +21,28 @@
21
21
  "bugs": {
22
22
  "url": "http://projects.theforeman.org/projects/foreman-tasks/issues"
23
23
  },
24
+ "peerDependencies": {
25
+ "@theforeman/vendor": ">= 4.0.2"
26
+ },
24
27
  "dependencies": {
25
- "@theforeman/vendor": "^1.4.0",
26
28
  "c3": "^0.4.11",
27
29
  "humanize-duration": "^3.20.1",
28
30
  "react-html-parser": "^2.0.2",
29
31
  "react-intl": "^2.8.0"
30
32
  },
31
33
  "devDependencies": {
32
- "@storybook/addon-actions": "^5.0.1",
33
- "@storybook/addon-knobs": "^5.0.1",
34
- "@storybook/react": "^5.0.1",
35
- "@theforeman/vendor-dev": "^1.4.0",
36
- "babel-cli": "^6.10.1",
37
- "babel-core": "^6.26.3",
38
- "babel-eslint": "^8.2.3",
39
- "babel-jest": "^23.6.0",
40
- "babel-loader": "^7.1.1",
41
- "babel-plugin-dynamic-import-node": "^2.0.0",
42
- "babel-plugin-module-resolver": "^3.2.0",
43
- "babel-plugin-syntax-dynamic-import": "^6.18.0",
44
- "babel-plugin-transform-class-properties": "^6.24.1",
45
- "babel-plugin-transform-object-assign": "^6.8.0",
46
- "babel-plugin-transform-object-rest-spread": "^6.8.0",
47
- "babel-preset-env": "^1.7.0",
48
- "babel-preset-react": "^6.5.0",
49
- "coveralls": "^3.0.0",
50
- "enzyme": "^3.4.0",
51
- "enzyme-adapter-react-16": "^1.4.0",
52
- "enzyme-to-json": "^3.2.1",
53
- "eslint": "^4.10.0",
54
- "eslint-import-resolver-babel-module": "^4.0.0",
55
- "eslint-plugin-patternfly-react": "0.2.0",
56
- "identity-obj-proxy": "^3.0.0",
34
+ "@babel/core": "^7.7.0",
35
+ "@theforeman/builder": "^4.0.2",
36
+ "@theforeman/eslint-plugin-foreman": "4.0.5",
37
+ "@theforeman/stories": "^4.0.2",
38
+ "@theforeman/test": "^4.0.2",
39
+ "@theforeman/vendor-dev": "^4.0.2",
40
+ "babel-eslint": "^10.0.3",
41
+ "eslint": "^6.7.2",
57
42
  "jed": "^1.1.1",
58
- "jest-cli": "^23.6.0",
59
- "jest-prop-type-error": "^1.1.0",
60
- "node-sass": "^4.5.0",
61
- "patternfly": "^3.58.0",
62
43
  "prettier": "^1.13.5",
63
- "raf": "^3.4.0",
64
- "react-redux-test-utils": "^0.1.1",
65
- "react-remarkable": "^1.1.3",
66
- "sass-loader": "^6.0.7",
67
44
  "stylelint": "^9.3.0",
68
45
  "stylelint-config-standard": "^18.0.0",
69
46
  "surge": "^0.20.3"
70
- },
71
- "jest": {
72
- "verbose": true,
73
- "testMatch": [
74
- "**/*.test.js"
75
- ],
76
- "testURL": "http://localhost/",
77
- "collectCoverage": true,
78
- "collectCoverageFrom": [
79
- "webpack/**/*.js",
80
- "!webpack/index.js",
81
- "!webpack/test_setup.js",
82
- "!webpack/**/bundle*",
83
- "!webpack/stories/**",
84
- "!webpack/**/*stories.js"
85
- ],
86
- "coverageReporters": [
87
- "lcov"
88
- ],
89
- "moduleNameMapper": {
90
- "^.+\\.(png|gif|css|scss)$": "identity-obj-proxy"
91
- },
92
- "globals": {
93
- "__testing__": true
94
- },
95
- "transform": {
96
- "^.+\\.js$": "babel-jest"
97
- },
98
- "moduleDirectories": [
99
- "node_modules",
100
- "webpack"
101
- ],
102
- "setupFiles": [
103
- "raf/polyfill",
104
- "jest-prop-type-error",
105
- "./webpack/test_setup.js"
106
- ]
107
47
  }
108
48
  }
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
3
 
4
- ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
- ENGINE_PATH = File.expand_path('../../lib/foreman_tasks/engine', __FILE__)
4
+ ENGINE_ROOT = File.expand_path('..', __dir__)
5
+ ENGINE_PATH = File.expand_path('../lib/foreman_tasks/engine', __dir__)
6
6
 
7
7
  require 'rails/all'
8
8
  require 'rails/engine/commands'
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
  set -ev
3
- if [[ $( git diff --name-only HEAD~1..HEAD webpack/ .travis.yml .babelrc .eslintrc package.json | wc -l ) -ne 0 ]]; then
3
+ if [[ $( git diff --name-only HEAD~1..HEAD webpack/ .travis.yml babel.config.js .eslintrc package.json | wc -l ) -ne 0 ]]; then
4
4
  npm run test;
5
- npm run coveralls;
5
+ npm run publish-coverage;
6
6
  npm run lint;
7
7
  fi
@@ -27,6 +27,15 @@ module ForemanTasks
27
27
  _(data['results'].count).must_equal 5
28
28
  end
29
29
 
30
+ it 'renders task ids when searching by resource id' do
31
+ task = FactoryBot.create(:dynflow_task, :product_create_task)
32
+ ForemanTasks::Lock.create!(name: "create", resource_type: "Katello::Product", resource_id: 1, task_id: task.id)
33
+ get :index, params: { :search => "label = Actions::Katello::Product::Create and resource_id = 1" }
34
+ assert_response :success
35
+ data = JSON.parse(response.body)
36
+ _(data['results'].first["id"]).must_equal task.id
37
+ end
38
+
30
39
  it 'supports ordering by duration' do
31
40
  get :index, params: { :sort_by => 'duration' }
32
41
  assert_response :success
@@ -22,7 +22,7 @@ FactoryBot.define do
22
22
  execution_plan = ForemanTasks.dynflow.world.plan(Support::DummyDynflowAction)
23
23
  # remove the task created automatically by the persistence
24
24
  ForemanTasks::Task.where(:external_id => execution_plan.id).delete_all
25
- task.update_attributes!(:external_id => execution_plan.id)
25
+ task.update!(:external_id => execution_plan.id)
26
26
  if evaluator.sync_with_dynflow
27
27
  task.update_from_dynflow(execution_plan.to_hash)
28
28
  end
@@ -38,9 +38,41 @@ FactoryBot.define do
38
38
 
39
39
  trait :inconsistent_dynflow_task do
40
40
  after(:build) do |task|
41
- task.update_attributes!(:state => 'running')
41
+ task.update!(:state => 'running')
42
+ end
43
+ end
44
+
45
+ factory :task_with_locks do
46
+ # posts_count is declared as a transient attribute and available in
47
+ # attributes on the factory, as well as the callback via the evaluator
48
+ transient do
49
+ locks_count { 3 }
50
+ resource_id { 1 }
51
+ resource_type { 'type1' }
52
+ end
53
+
54
+ # the after(:create) yields two values; the user instance itself and the
55
+ # evaluator, which stores all values from the factory, including transient
56
+ # attributes; `create_list`'s second argument is the number of records
57
+ # to create and we make sure the user is associated properly to the post
58
+ after(:create) do |task, evaluator|
59
+ create_list(
60
+ :lock,
61
+ evaluator.locks_count,
62
+ task: task,
63
+ resource_type: evaluator.resource_type,
64
+ resource_id: evaluator.resource_id
65
+ )
42
66
  end
43
67
  end
44
68
  end
45
69
  end
70
+
71
+ factory :lock, :class => ForemanTasks::Lock do
72
+ name { 'read' }
73
+ resource_type { 'Katello::Repository' }
74
+ resource_id { 1 }
75
+ exclusive { true }
76
+ association :task, factory: :task_with_locks
77
+ end
46
78
  end
@@ -27,3 +27,7 @@ def wait_for(waiting_message = 'something to happen')
27
27
  end
28
28
  raise "waiting for #{waiting_message} was not successful"
29
29
  end
30
+
31
+ def on_postgresql?
32
+ ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
33
+ end
@@ -0,0 +1,34 @@
1
+ require 'foreman_tasks_test_helper'
2
+
3
+ module ForemanTasks
4
+ module Concerns
5
+ class PollingActionExtensionsTest < ::ActiveSupport::TestCase
6
+ class Action < ::Dynflow::Action
7
+ include ::Dynflow::Action::Polling
8
+ end
9
+
10
+ describe 'polling interval tuning' do
11
+ let(:default_intervals) { [0.5, 1, 2, 4, 8, 16] }
12
+
13
+ it 'is extends the polling action module' do
14
+ _(::Dynflow::Action::Polling.ancestors.first).must_equal ForemanTasks::Concerns::PollingActionExtensions
15
+ end
16
+
17
+ it 'does not modify polling intervals by default' do
18
+ _(Action.allocate.poll_intervals).must_equal default_intervals
19
+ end
20
+
21
+ it 'cannot make intervals shorter than 0.5 seconds' do
22
+ Setting.expects(:[]).with(:foreman_tasks_polling_multiplier).returns 0
23
+ _(Action.allocate.poll_intervals).must_equal(default_intervals.map { 0.5 })
24
+ end
25
+
26
+ it 'can be used to make the intervals longer' do
27
+ value = 5
28
+ Setting.expects(:[]).with(:foreman_tasks_polling_multiplier).returns value
29
+ _(Action.allocate.poll_intervals).must_equal(default_intervals.map { |i| i * value })
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -8,7 +8,7 @@ module ForemanTasks
8
8
  end
9
9
 
10
10
  # to be able to use the locking
11
- ::User.send(:include, ForemanTasks::Concerns::ActionSubject)
11
+ ::User.include ForemanTasks::Concerns::ActionSubject
12
12
 
13
13
  class ParentAction < Actions::ActionWithSubPlans
14
14
  def plan(user)