foreman-tasks 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/foreman_tasks/api/tasks_controller.rb +4 -4
- data/app/controllers/foreman_tasks/tasks_controller.rb +5 -4
- data/app/graphql/types/recurring_logic.rb +1 -0
- data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +4 -1
- data/app/lib/actions/middleware/watch_delegated_proxy_sub_tasks.rb +2 -6
- data/app/lib/actions/trigger_proxy_batch.rb +79 -0
- data/app/models/foreman_tasks/recurring_logic.rb +8 -0
- data/app/models/foreman_tasks/task/dynflow_task.rb +8 -3
- data/app/models/foreman_tasks/task.rb +1 -0
- data/app/models/foreman_tasks/triggering.rb +12 -4
- data/app/views/foreman_tasks/api/tasks/show.json.rabl +1 -1
- data/app/views/foreman_tasks/layouts/react.html.erb +0 -1
- data/app/views/foreman_tasks/recurring_logics/index.html.erb +4 -2
- data/app/views/foreman_tasks/task_groups/recurring_logic_task_groups/_recurring_logic_task_group.html.erb +4 -0
- data/db/migrate/20210720115251_add_purpose_to_recurring_logic.rb +6 -0
- data/extra/foreman-tasks-cleanup.sh +127 -0
- data/extra/foreman-tasks-export.sh +117 -0
- data/lib/foreman_tasks/tasks/export_tasks.rake +92 -47
- data/lib/foreman_tasks/version.rb +1 -1
- data/test/controllers/api/tasks_controller_test.rb +29 -0
- data/test/controllers/tasks_controller_test.rb +19 -0
- data/test/unit/actions/trigger_proxy_batch_test.rb +59 -0
- data/test/unit/triggering_test.rb +22 -0
- data/webpack/ForemanTasks/Components/TaskActions/TaskActionHelpers.js +11 -4
- data/webpack/ForemanTasks/Components/TaskActions/TaskActionHelpers.test.js +27 -5
- data/webpack/ForemanTasks/Components/TasksTable/TasksTable.js +8 -0
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableActions.js +6 -1
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js +2 -1
- data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.js +22 -11
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js +17 -16
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableSelectors.js +3 -0
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableHelpers.test.js +1 -1
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableReducer.test.js +3 -1
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTablePage.test.js.snap +12 -2
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTableReducer.test.js.snap +5 -0
- data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/__snapshots__/selectionHeaderCellFormatter.test.js.snap +1 -0
- data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/selectionHeaderCellFormatter.test.js +1 -1
- data/webpack/ForemanTasks/Components/TasksTable/formatters/selectionHeaderCellFormatter.js +1 -0
- data/webpack/ForemanTasks/Components/TasksTable/index.js +2 -0
- metadata +8 -5
- data/app/services/foreman_tasks/dashboard_table_filter.rb +0 -56
- data/test/unit/dashboard_table_filter_test.rb +0 -77
@@ -1,56 +0,0 @@
|
|
1
|
-
module ForemanTasks
|
2
|
-
# narrows the scope for the tasks table based on params coming from tasks dashboard
|
3
|
-
#
|
4
|
-
# Supported filters:
|
5
|
-
#
|
6
|
-
# * :result
|
7
|
-
# * :state
|
8
|
-
# * :time_horizon - expected format of Hxy, where the xy is the time horizon in hours we're interested in
|
9
|
-
# :time_mode can be set to 'recent' to filter the recent tasks, or 'older' (default) to filter earlier ones
|
10
|
-
class DashboardTableFilter
|
11
|
-
def initialize(scope, params)
|
12
|
-
@scope = scope
|
13
|
-
@params = params
|
14
|
-
end
|
15
|
-
|
16
|
-
def scope
|
17
|
-
@new_scope = @scope
|
18
|
-
scope_by(:result)
|
19
|
-
scope_by(:state)
|
20
|
-
scope_by_time
|
21
|
-
@new_scope
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def scope_by(field)
|
27
|
-
if (field == :result) && (@params[field] == 'other')
|
28
|
-
@new_scope = @new_scope.where(:result => ['cancelled', 'pending'])
|
29
|
-
elsif @params[field].present?
|
30
|
-
@new_scope = @new_scope.where(field => @params[field])
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def scope_by_time
|
35
|
-
return if @params[:time_horizon].blank?
|
36
|
-
hours = if @params[:time_horizon].casecmp('week') == 0
|
37
|
-
24 * 7
|
38
|
-
else
|
39
|
-
@params[:time_horizon][/\AH(\d{1,2})$/i, 1]
|
40
|
-
end
|
41
|
-
|
42
|
-
unless hours
|
43
|
-
raise Foreman::Exception, 'Unexpected format of time: should be in form of "H24" or equal to "week"'
|
44
|
-
end
|
45
|
-
timestamp = Time.now.utc - hours.to_i.hours
|
46
|
-
case @params[:time_mode]
|
47
|
-
when 'recent'
|
48
|
-
operator = '>'
|
49
|
-
else
|
50
|
-
operator = '<'
|
51
|
-
search_suffix = 'OR state_updated_at IS NULL'
|
52
|
-
end
|
53
|
-
@new_scope = @new_scope.where("state_updated_at #{operator} ? #{search_suffix}", timestamp)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'foreman_tasks_test_helper'
|
2
|
-
|
3
|
-
class DashboardTableFilterTest < ActiveSupport::TestCase
|
4
|
-
before do
|
5
|
-
::ForemanTasks::Task.delete_all
|
6
|
-
end
|
7
|
-
|
8
|
-
describe ForemanTasks::DashboardTableFilter do
|
9
|
-
before do
|
10
|
-
@tasks_builder = HistoryTasksBuilder.new
|
11
|
-
@scope = ForemanTasks::Task.all
|
12
|
-
@tasks_builder.build
|
13
|
-
end
|
14
|
-
|
15
|
-
let :subject do
|
16
|
-
ForemanTasks::DashboardTableFilter.new(@scope, params)
|
17
|
-
end
|
18
|
-
|
19
|
-
let :filtered_scope do
|
20
|
-
subject.scope
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'by result' do
|
24
|
-
let(:params) { { result: 'warning' } }
|
25
|
-
|
26
|
-
it 'filters' do
|
27
|
-
_(filtered_scope.count).must_equal @tasks_builder.distribution['stopped'][:by_result]['warning'][:total]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'by state' do
|
32
|
-
let(:params) { { state: 'running' } }
|
33
|
-
|
34
|
-
it 'filters' do
|
35
|
-
_(filtered_scope.count).must_equal @tasks_builder.distribution['running'][:total]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'recent' do
|
40
|
-
let(:params) do
|
41
|
-
{ state: 'running',
|
42
|
-
time_horizon: 'H24',
|
43
|
-
time_mode: 'recent' }
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'filters' do
|
47
|
-
_(filtered_scope.count).must_equal @tasks_builder.distribution['running'][:recent]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe 'recent week time horizon' do
|
52
|
-
let(:params) do
|
53
|
-
{ state: 'running',
|
54
|
-
time_horizon: 'week',
|
55
|
-
time_mode: 'recent' }
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'filters' do
|
59
|
-
_(filtered_scope.count).must_equal @tasks_builder.distribution['running'][:recent]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe 'older' do
|
64
|
-
let(:params) do
|
65
|
-
{ state: 'running',
|
66
|
-
time_horizon: 'H24',
|
67
|
-
time_mode: 'older' }
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'filters' do
|
71
|
-
old_tasks_count = @tasks_builder.distribution['running'][:total] -
|
72
|
-
@tasks_builder.distribution['running'][:recent]
|
73
|
-
_(filtered_scope.count).must_equal old_tasks_count
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|