foreman-tasks 2.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/js_tests.yml +31 -0
  3. data/.github/workflows/ruby_tests.yml +74 -0
  4. data/.rubocop.yml +12 -4
  5. data/.rubocop_todo.yml +32 -25
  6. data/Gemfile +5 -0
  7. data/app/controllers/foreman_tasks/api/tasks_controller.rb +50 -63
  8. data/app/controllers/foreman_tasks/concerns/parameters/triggering.rb +1 -1
  9. data/app/controllers/foreman_tasks/recurring_logics_controller.rb +7 -0
  10. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +3 -3
  11. data/app/models/foreman_tasks/recurring_logic.rb +1 -1
  12. data/app/models/foreman_tasks/task.rb +11 -0
  13. data/app/models/foreman_tasks/task/dynflow_task.rb +27 -33
  14. data/app/models/foreman_tasks/task/search.rb +1 -1
  15. data/app/models/foreman_tasks/task/status_explicator.rb +1 -1
  16. data/app/models/foreman_tasks/triggering.rb +1 -1
  17. data/app/models/setting/foreman_tasks.rb +9 -9
  18. data/app/services/foreman_tasks/dashboard_table_filter.rb +5 -1
  19. data/app/views/foreman_tasks/api/tasks/index.json.rabl +2 -0
  20. data/app/views/foreman_tasks/layouts/react.html.erb +1 -2
  21. data/app/views/foreman_tasks/recurring_logics/index.html.erb +3 -1
  22. data/app/views/foreman_tasks/tasks/dashboard/_latest_tasks_in_error_warning.html.erb +1 -1
  23. data/app/views/foreman_tasks/tasks/dashboard/_tasks_status.html.erb +1 -1
  24. data/app/views/foreman_tasks/tasks/show.html.erb +1 -6
  25. data/config/routes.rb +2 -1
  26. data/db/migrate/20200517215015_rename_bookmarks_controller.rb +2 -2
  27. data/db/seeds.d/30-notification_blueprints.rb +7 -7
  28. data/db/seeds.d/61-foreman_tasks_bookmarks.rb +1 -1
  29. data/foreman-tasks.gemspec +1 -0
  30. data/lib/foreman_tasks/cleaner.rb +4 -6
  31. data/lib/foreman_tasks/dynflow/configuration.rb +1 -1
  32. data/lib/foreman_tasks/dynflow/persistence.rb +4 -6
  33. data/lib/foreman_tasks/engine.rb +2 -2
  34. data/lib/foreman_tasks/version.rb +1 -1
  35. data/package.json +0 -1
  36. data/test/controllers/api/recurring_logics_controller_test.rb +1 -1
  37. data/test/controllers/api/tasks_controller_test.rb +17 -7
  38. data/test/controllers/tasks_controller_test.rb +6 -6
  39. data/test/core/unit/runner_test.rb +20 -20
  40. data/test/core/unit/task_launcher_test.rb +8 -8
  41. data/test/helpers/foreman_tasks/foreman_tasks_helper_test.rb +7 -7
  42. data/test/helpers/foreman_tasks/tasks_helper_test.rb +3 -3
  43. data/test/lib/actions/middleware/keep_current_request_id_test.rb +3 -3
  44. data/test/support/history_tasks_builder.rb +1 -1
  45. data/test/tasks/generate_task_actions_test.rb +1 -1
  46. data/test/unit/actions/action_with_sub_plans_test.rb +2 -2
  47. data/test/unit/actions/bulk_action_test.rb +6 -6
  48. data/test/unit/actions/proxy_action_test.rb +20 -20
  49. data/test/unit/actions/recurring_action_test.rb +30 -32
  50. data/test/unit/cleaner_test.rb +24 -24
  51. data/test/unit/dashboard_table_filter_test.rb +5 -5
  52. data/test/unit/otp_manager_test.rb +2 -2
  53. data/test/unit/proxy_selector_test.rb +9 -9
  54. data/test/unit/recurring_logic_test.rb +32 -32
  55. data/test/unit/remote_task_test.rb +2 -2
  56. data/test/unit/task_groups_test.rb +4 -4
  57. data/test/unit/task_test.rb +26 -18
  58. data/test/unit/triggering_test.rb +8 -8
  59. data/test/unit/troubleshooting_help_generator_test.rb +6 -6
  60. data/test/unit/ui_notifications_test.rb +11 -11
  61. data/webpack/ForemanTasks/Components/TaskDetails/Components/RunningSteps.js +3 -3
  62. data/webpack/ForemanTasks/Components/TaskDetails/Components/Task.js +8 -157
  63. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskButtons.js +168 -0
  64. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskInfo.js +6 -7
  65. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskSkeleton.js +48 -0
  66. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/RunningSteps.test.js +1 -1
  67. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Task.test.js +12 -70
  68. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/TaskButtons.test.js +95 -0
  69. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/Task.test.js.snap +78 -225
  70. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskButtons.test.js.snap +212 -0
  71. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskInfo.test.js.snap +8 -4
  72. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.js +87 -70
  73. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.scss +10 -0
  74. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsActions.js +48 -125
  75. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsConstants.js +3 -16
  76. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsSelectors.js +55 -29
  77. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.fixtures.js +2 -2
  78. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.test.js +6 -0
  79. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsActions.test.js +2 -18
  80. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetails.test.js.snap +77 -27
  81. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsActions.test.js.snap +14 -101
  82. data/webpack/ForemanTasks/Components/TaskDetails/index.js +6 -3
  83. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.scss +4 -0
  84. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/OtherInfo.js +53 -0
  85. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/OtherInfo.test.js +14 -0
  86. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.js +27 -19
  87. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.scss +14 -0
  88. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.test.js +1 -34
  89. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/{StoppedTasksCardHelper.js → StoppedTasksCardTable.js} +28 -1
  90. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCardTable.test.js +54 -0
  91. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/OtherInfo.test.js.snap +48 -0
  92. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/StoppedTasksCard.test.js.snap +60 -1367
  93. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/StoppedTasksCardTable.test.js.snap +960 -0
  94. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/__snapshots__/TasksCardsGrid.test.js.snap +14 -11
  95. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardConstants.js +2 -0
  96. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardSelectors.js +17 -11
  97. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardSelectors.test.js +26 -14
  98. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboard.test.js.snap +14 -11
  99. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboardSelectors.test.js.snap +38 -22
  100. data/webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js +0 -8
  101. data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.js +13 -4
  102. data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.scss +0 -10
  103. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTablePage.test.js.snap +0 -2
  104. data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/__snapshots__/actionNameCellFormatter.test.js.snap +3 -1
  105. data/webpack/ForemanTasks/Components/TasksTable/formatters/actionNameCellFormatter.js +6 -1
  106. data/webpack/ForemanTasks/Components/common/urlHelpers.js +7 -0
  107. data/webpack/ForemanTasks/ForemanTasksReducers.js +0 -2
  108. data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
  109. data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
  110. data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
  111. data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
  112. metadata +21 -13
  113. data/.travis.yml +0 -7
  114. data/app/assets/stylesheets/foreman_tasks/tasks.scss +0 -9
  115. data/script/travis_run_js_tests.sh +0 -7
  116. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsReducer.js +0 -38
  117. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsReducer.test.js +0 -33
  118. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsReducer.test.js.snap +0 -26
  119. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/integration.test.js.snap +0 -122
  120. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/integration.test.js +0 -72
  121. data/webpack/__mocks__/foremanReact/redux/API.js +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e37924776f38fa00d98c1389b22baff43347f4f4c28c0d3848de93951b5cd1d9
4
- data.tar.gz: 49c49253f6cd157b6c602bb1ceb5bee9b249aee207939501b60e273b4fce1734
3
+ metadata.gz: '09cfa50efbe1f8e34246268b386aa7f2cdc0e6f723beda8aedf60a6edf372cbb'
4
+ data.tar.gz: 6124d140e2ddd581ff85c7d4c44bb6c3fed01a9e64050e39bf595bff485ca7bb
5
5
  SHA512:
6
- metadata.gz: 53aebec3deef276e131483dc20f5ce3753a9bf8b7d64e9a443af9a0284e9749a657c97e03923034db81e1a698aa24d0de120fe3530b5768725e9a910f8b34e52
7
- data.tar.gz: ae5931295bc54e9bfcf3b48278c52724265ddc0e902d39be2d05897f1231b5c29291810f7e638d83f0a436a6f0a414453692158ad9b93c2445db038e87872168
6
+ metadata.gz: 5ee3cd1aee581db4ab76b9278624d00b28271965655cc9c154d2cd18ac3d9284244886d74bd6f6654847d5ae19f9dc8245eb517227ee1b4c8b88281066f43a19
7
+ data.tar.gz: 67c6b3edfd673e60489884f2dbb18fec2a03c7a2a33a04933f1a087686c2b18324038ca2f283a3c07608cae8d335b1f4e441ceffa92dad094468a3ac77cccaaa
@@ -0,0 +1,31 @@
1
+ name: JavaScript Testing
2
+ on:
3
+ pull_request:
4
+ paths:
5
+ - 'webpack/**'
6
+ - 'package.json'
7
+ - '.github/workflows/js_tests.yml'
8
+
9
+ jobs:
10
+ test_js:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ node-version: [10, 12]
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Setup Node
19
+ uses: actions/setup-node@v1
20
+ with:
21
+ node-version: ${{ matrix.node-version }}
22
+ - name: Npm install
23
+ run: npm install
24
+ - name: Run plugin linter
25
+ run: npm run lint
26
+ - name: Run plugin tests
27
+ run: npm run test
28
+ - name: Publish Coveralls
29
+ uses: coverallsapp/github-action@master
30
+ with:
31
+ github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,74 @@
1
+ name: Ruby Testing
2
+ on: [pull_request]
3
+ env:
4
+ RAILS_ENV: test
5
+ DATABASE_URL: postgresql://postgres:@localhost/test
6
+ DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true
7
+ jobs:
8
+ rubocop:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Setup Ruby
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6
16
+ - name: Setup
17
+ run: |
18
+ gem install bundler
19
+ bundle install --jobs=3 --retry=3
20
+ - name: Run rubocop
21
+ run: bundle exec rubocop
22
+ test_ruby:
23
+ runs-on: ubuntu-latest
24
+ needs: rubocop
25
+ services:
26
+ postgres:
27
+ image: postgres:12.1
28
+ ports: ['5432:5432']
29
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
30
+ strategy:
31
+ fail-fast: false
32
+ matrix:
33
+ foreman-core-branch: [develop]
34
+ ruby-version: [2.5, 2.6]
35
+ node-version: [12]
36
+ steps:
37
+ - run: sudo apt-get update
38
+ - run: sudo apt-get install build-essential libcurl4-openssl-dev zlib1g-dev libpq-dev
39
+ - uses: actions/checkout@v2
40
+ with:
41
+ repository: theforeman/foreman
42
+ ref: ${{ matrix.foreman-core-branch }}
43
+ - uses: actions/checkout@v2
44
+ with:
45
+ path: foreman-tasks
46
+ - name: Setup Ruby
47
+ uses: ruby/setup-ruby@v1
48
+ with:
49
+ ruby-version: ${{ matrix.ruby-version }}
50
+ - name: Setup Node
51
+ uses: actions/setup-node@v1
52
+ with:
53
+ node-version: ${{ matrix.node-version }}
54
+ - uses: actions/cache@v2
55
+ with:
56
+ path: vendor/bundle
57
+ key: ${{ runner.os }}-fgems-${{ matrix.ruby-version }}-${{ hashFiles('Gemfile.lock') }}
58
+ restore-keys: |
59
+ ${{ runner.os }}-fgems-${{ matrix.ruby-version }}-
60
+ - name: Setup Bundler
61
+ run: |
62
+ echo "gem 'foreman-tasks', path: './foreman-tasks'" > bundler.d/foreman-tasks.local.rb
63
+ gem install bundler
64
+ bundle config set without journald development console libvirt
65
+ bundle config set path vendor/bundle
66
+ - name: Prepare test env
67
+ run: |
68
+ bundle install --jobs=3 --retry=3
69
+ bundle exec rake db:create
70
+ bundle exec rake db:migrate
71
+ - name: Run plugin tests
72
+ run: |
73
+ bundle exec rake test:foreman-tasks
74
+ bundle exec rake test TEST="test/unit/foreman/access_permissions_test.rb"
data/.rubocop.yml CHANGED
@@ -6,10 +6,10 @@ require:
6
6
  inherit_from: .rubocop_todo.yml
7
7
 
8
8
  AllCops:
9
- Include:
10
- - 'Rakefile'
11
- - 'app/views/foreman_tasks/api/**/*.rabl'
12
- - lib/**/*.rake
9
+ Exclude:
10
+ - 'node_modules/**/*'
11
+ - 'locale/*'
12
+ TargetRubyVersion: 2.5
13
13
 
14
14
  Lint/ShadowingOuterLocalVariable:
15
15
  Enabled: false
@@ -68,6 +68,8 @@ Naming/FileName:
68
68
  - Gemfile
69
69
  - db/seeds.d/*
70
70
  - lib/foreman-tasks.rb
71
+ - gemfile.d/foreman-tasks.rb
72
+
71
73
 
72
74
  Layout/HeredocIndentation:
73
75
  Exclude:
@@ -115,3 +117,9 @@ Naming/RescuedExceptionsVariableName:
115
117
 
116
118
  Style/WordArray:
117
119
  Enabled: false
120
+
121
+ Style/TrailingCommaInArrayLiteral:
122
+ EnforcedStyleForMultiline: comma
123
+
124
+ Style/TrailingCommaInHashLiteral:
125
+ EnforcedStyleForMultiline: comma
data/.rubocop_todo.yml CHANGED
@@ -1,21 +1,34 @@
1
- # Offense count: 1
2
- Lint/EmptyWhen:
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-08-07 08:31:32 UTC using RuboCop version 0.89.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ # Configuration parameters: Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
3
13
  Exclude:
4
- - 'app/lib/actions/proxy_action.rb'
14
+ - 'foreman-tasks-core.gemspec'
15
+ - 'foreman-tasks.gemspec'
5
16
 
6
17
  # Offense count: 1
7
18
  Lint/UselessAssignment:
8
19
  Exclude:
9
20
  - 'lib/foreman_tasks/tasks/export_tasks.rake'
10
21
 
11
- Minitest/AssertEmpty:
12
- Enabled: false
13
-
14
- Minitest/AssertEqual:
15
- Enabled: false
16
-
17
- Minitest/GlobalExpectations:
18
- Enabled: false
22
+ # Offense count: 1
23
+ # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
24
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
25
+ Naming/FileName:
26
+ Exclude:
27
+ - '*.gemspec'
28
+ - 'Gemfile'
29
+ - 'db/seeds.d/*'
30
+ - 'lib/foreman-tasks.rb'
31
+ - 'gemfile.d/foreman-tasks.rb'
19
32
 
20
33
  # Offense count: 3
21
34
  # Configuration parameters: EnforcedStyleForLeadingUnderscores.
@@ -28,7 +41,7 @@ Naming/MemoizedInstanceVariableName:
28
41
 
29
42
  # Offense count: 11
30
43
  # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
31
- # AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp
44
+ # AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
32
45
  Naming/MethodParameterName:
33
46
  Exclude:
34
47
  - 'app/helpers/foreman_tasks/foreman_tasks_helper.rb'
@@ -67,11 +80,13 @@ Rails/OutputSafety:
67
80
  Exclude:
68
81
  - 'app/helpers/foreman_tasks/foreman_tasks_helper.rb'
69
82
 
70
- # Offense count: 1
83
+ # Offense count: 2
71
84
  # Configuration parameters: Include.
72
85
  # Include: **/Rakefile, **/*.rake
73
86
  Rails/RakeEnvironment:
74
87
  Exclude:
88
+ - 'lib/capistrano/tasks/**/*.rake'
89
+ - 'lib/foreman_tasks/tasks/dynflow.rake'
75
90
  - 'lib/foreman_tasks/tasks/test.rake'
76
91
 
77
92
  # Offense count: 12
@@ -92,22 +107,14 @@ Style/ClassAndModuleChildren:
92
107
  - 'test/controllers/api/recurring_logics_controller_test.rb'
93
108
  - 'test/controllers/api/tasks_controller_test.rb'
94
109
 
95
- # Offense count: 2
110
+ # Offense count: 1
111
+ # Configuration parameters: EnforcedStyle.
112
+ # SupportedStyles: allowed_in_returns, forbidden
96
113
  Style/DoubleNegation:
97
114
  Exclude:
98
- - 'app/models/foreman_tasks/lock.rb'
99
115
  - 'app/models/foreman_tasks/recurring_logic.rb'
100
116
 
101
- # Offense count: 36
117
+ # Offense count: 35
102
118
  # Configuration parameters: MinBodyLength.
103
119
  Style/GuardClause:
104
120
  Enabled: false
105
-
106
- Style/HashEachMethods:
107
- Enabled: false
108
-
109
- Style/HashTransformKeys:
110
- Enabled: false
111
-
112
- Style/HashTransformValues:
113
- Enabled: false
data/Gemfile CHANGED
@@ -13,3 +13,8 @@ gemspec :name => 'foreman-tasks'
13
13
 
14
14
  # To use debugger
15
15
  # gem 'debugger'
16
+
17
+ gem 'rubocop', '~> 0.87'
18
+ gem 'rubocop-minitest', '~> 0.9.0'
19
+ gem 'rubocop-performance', '~> 1.5.2'
20
+ gem 'rubocop-rails', '~> 2.5.2'
@@ -31,17 +31,6 @@ module ForemanTasks
31
31
  param :id, :identifier, desc: 'UUID of the task'
32
32
  def details; end
33
33
 
34
- api :GET, '/tasks/:id/sub_tasks', 'Show sub_tasks details'
35
- param :id, :identifier, desc: 'UUID of the task'
36
- def sub_tasks
37
- parent_task = resource_scope.find(params[:id])
38
- filtered_scope = parent_task.sub_tasks
39
- action_name = { "action_name" => parent_task.action }
40
-
41
- filtered_scope = DashboardTableFilter.new(filtered_scope, params).scope
42
- render :json => action_name.merge(tasks_list(filtered_scope))
43
- end
44
-
45
34
  api :POST, '/tasks/bulk_search', 'List dynflow tasks for uuids'
46
35
  param :searches, Array, :desc => 'List of uuids to fetch info about' do
47
36
  param :search_id, String, :desc => <<-DESC
@@ -86,11 +75,16 @@ module ForemanTasks
86
75
  end
87
76
 
88
77
  api :POST, '/tasks/bulk_resume', N_('Resume all paused error tasks')
78
+ desc <<~DOC
79
+ Resumes all selected resumable tasks. If neither a search query nor an
80
+ explicit list of task IDs is provided, it tries to resume all tasks in
81
+ paused state with result error.
82
+ DOC
89
83
  param :search, String, :desc => N_('Resume tasks matching search string')
90
84
  param :task_ids, Array, :desc => N_('Resume specific tasks by ID')
91
85
  def bulk_resume
92
86
  if params[:search].nil? && params[:task_ids].nil?
93
- raise BadRequest, _('Please provide at least one of search or task_ids parameters in the request')
87
+ params[:search] = 'state = paused and result = error'
94
88
  end
95
89
  resumed = []
96
90
  failed = []
@@ -116,13 +110,18 @@ module ForemanTasks
116
110
  total: resumed.length + failed.length + skipped.length,
117
111
  resumed: resumed,
118
112
  failed: failed,
119
- skipped: skipped
113
+ skipped: skipped,
120
114
  }
121
115
  end
122
116
 
123
- api :POST, '/tasks/bulk_cancel', N_('Cancel all cancellable tasks')
117
+ api :POST, '/tasks/bulk_cancel', N_('Cancel selected cancellable tasks')
118
+ desc <<~DOC
119
+ Cancels all selected cancellable tasks. Requires a search query or an
120
+ explicit list of task IDs to be provided.
121
+ DOC
124
122
  param :search, String, :desc => N_('Cancel tasks matching search string')
125
123
  param :task_ids, Array, :desc => N_('Cancel specific tasks by ID')
124
+ error :bad_request, 'Returned if neither search nor task_ids parameter is provided.'
126
125
  def bulk_cancel
127
126
  if params[:search].nil? && params[:task_ids].nil?
128
127
  raise BadRequest, _('Please provide at least one of search or task_ids parameters in the request')
@@ -137,13 +136,18 @@ module ForemanTasks
137
136
  render :json => {
138
137
  total: cancelled.length + skipped.length,
139
138
  cancelled: cancelled,
140
- skipped: skipped
139
+ skipped: skipped,
141
140
  }
142
141
  end
143
142
 
144
- api :POST, '/tasks/bulk_stop', N_('Stop all stoppable tasks')
143
+ api :POST, '/tasks/bulk_stop', N_('Stop selected stoppable tasks')
144
+ desc <<~DOC
145
+ Stops all selected tasks which are not already stopped. Requires a
146
+ search query or an explicit list of task IDs to be provided.
147
+ DOC
145
148
  param :search, String, :desc => N_('Stop tasks matching search string')
146
149
  param :task_ids, Array, :desc => N_('Stop specific tasks by ID')
150
+ error :bad_request, 'Returned if neither search nor task_ids parameter is provided.'
147
151
  def bulk_stop
148
152
  if params[:search].nil? && params[:task_ids].nil?
149
153
  raise BadRequest, _('Please provide at least one of search or task_ids parameters in the request')
@@ -165,22 +169,33 @@ module ForemanTasks
165
169
  render :json => {
166
170
  total: total_length,
167
171
  stopped_length: to_stop_length,
168
- skipped_length: skipped_length
172
+ skipped_length: skipped_length,
169
173
  }
170
174
  end
171
175
 
172
176
  api :GET, '/tasks', N_('List tasks')
173
- param :search, String, :desc => N_('Search string')
174
- param :page, :number, :desc => N_('Page number, starting at 1')
175
- param :per_page, :number, :desc => N_('Number of results per page to return')
176
- param :order, String, :desc => N_("Sort field and order, e.g. 'name DESC'")
177
- param :sort, Hash, :desc => N_("Hash version of 'order' param") do
178
- param :by, String, :desc => N_('Field to sort the results on')
179
- param :order, String, :desc => N_('How to order the sorted results (e.g. ASC for ascending)')
180
- end
177
+ api :GET, '/tasks/:parent_task_id/sub_tasks', 'Show sub_tasks details'
178
+ param :parent_task_id, :identifier, desc: 'UUID of the task'
179
+ param_group :search_and_pagination, ::Api::V2::BaseController
181
180
  def index
182
- filtered_scope = DashboardTableFilter.new(resource_scope, params).scope
183
- render :json => tasks_list(filtered_scope)
181
+ if params[:sort_by] || params[:sort_order]
182
+ Foreman::Deprecation.api_deprecation_warning(
183
+ "The sort params sort_by and sort_order are deprecated.
184
+ Please use the order param instead as one string 'order=started_at desc'"
185
+ )
186
+
187
+ ordering_params = {
188
+ sort_by: params[:sort_by] || 'started_at',
189
+ sort_order: params[:sort_order] || 'DESC',
190
+ }
191
+ params[:order] = "#{ordering_params[:sort_by]} #{ordering_params[:sort_order]}"
192
+ end
193
+ params[:order] ||= 'started_at DESC'
194
+ @tasks = DashboardTableFilter.new(resource_scope_for_index, params).scope.order(params[:order].to_s)
195
+ end
196
+
197
+ def search_options
198
+ [params[:search], {}]
184
199
  end
185
200
 
186
201
  def_param_group :callback_target do
@@ -221,7 +236,7 @@ module ForemanTasks
221
236
  end
222
237
 
223
238
  def search_tasks(search_params)
224
- scope = resource_scope_for_index.select('DISTINCT foreman_tasks_tasks.*')
239
+ scope = resource_scope_for_index
225
240
  scope = ordering_scope(scope, search_params)
226
241
  scope = search_scope(scope, search_params)
227
242
  scope = active_scope(scope, search_params)
@@ -287,7 +302,6 @@ module ForemanTasks
287
302
  sort_by = ordering_params[:sort_by] || 'started_at'
288
303
  sort_by = 'foreman_tasks_tasks.' + sort_by if sort_by == 'started_at'
289
304
  sort_order = ordering_params[:sort_order] || 'DESC'
290
- scope = scope.select("foreman_tasks_tasks.*, coalesce(ended_at, current_timestamp) - coalesce(coalesce(started_at, ended_at), current_timestamp) as duration")
291
305
  scope.order("#{sort_by} #{sort_order}")
292
306
  end
293
307
 
@@ -312,7 +326,13 @@ module ForemanTasks
312
326
  end
313
327
 
314
328
  def resource_scope(_options = {})
315
- @resource_scope ||= ForemanTasks::Task.authorized("#{action_permission}_foreman_tasks")
329
+ scope = ForemanTasks::Task.authorized("#{action_permission}_foreman_tasks")
330
+ scope = scope.where(:parent_task_id => params[:parent_task_id]) if params[:parent_task_id]
331
+ scope
332
+ end
333
+
334
+ def resource_scope_for_index(*args)
335
+ super.select("DISTINCT foreman_tasks_tasks.*, coalesce(ended_at, current_timestamp) - coalesce(coalesce(started_at, ended_at), current_timestamp) as duration")
316
336
  end
317
337
 
318
338
  def controller_permission
@@ -330,39 +350,6 @@ module ForemanTasks
330
350
  end
331
351
  end
332
352
 
333
- def tasks_list(filtered_scope)
334
- total = resource_scope.count
335
-
336
- search_scope = filtered_scope.search_for(params[:search])
337
- subtotal = search_scope.select('DISTINCT foreman_tasks_tasks.id').count
338
- filtered_scope = search_scope.select('DISTINCT foreman_tasks_tasks.*')
339
-
340
- ordering_params = {
341
- sort_by: params[:sort_by] || 'started_at',
342
- sort_order: params[:sort_order] || 'DESC'
343
- }
344
- filtered_scope = ordering_scope(filtered_scope, ordering_params)
345
-
346
- pagination_params = {
347
- page: params[:page] || 1,
348
- per_page: params[:per_page] || Setting[:entries_per_page] || 20
349
- }
350
- filtered_scope = pagination_scope(filtered_scope, pagination_params)
351
- results = filtered_scope.map { |task| task_hash(task) }
352
-
353
- {
354
- total: total,
355
- subtotal: subtotal,
356
- page: pagination_params[:page],
357
- per_page: pagination_params[:per_page],
358
- sort: {
359
- by: ordering_params[:sort_by],
360
- order: ordering_params[:sort_order]
361
- },
362
- results: results
363
- }
364
- end
365
-
366
353
  def bulk_scope
367
354
  scope = resource_scope
368
355
  scope = scope.search_for(params[:search]) if params[:search]