foreman-tasks 0.14.5 → 0.14.6
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.
- checksums.yaml +4 -4
- data/app/controllers/foreman_tasks/api/tasks_controller.rb +3 -3
- data/app/controllers/foreman_tasks/tasks_controller.rb +2 -2
- data/app/models/foreman_tasks/task/summarizer.rb +8 -4
- data/lib/foreman_tasks/version.rb +1 -1
- data/test/controllers/api/tasks_controller_test.rb +37 -13
- data/test/controllers/tasks_controller_test.rb +18 -0
- data/test/unit/task_test.rb +3 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 675f98353547dd5b378bfe5055c60e976618b39754e4d46e0d361641ee8640e0
|
4
|
+
data.tar.gz: 2de7b22aaaacdb644d953e0aeb4c0e7ba6083e2f9650248baf021b78d0ff7474
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bab26f5c355c09ea6d292e2b10fc011d41c769c91fa863985a89a43075d831b2115f5222c3f5c276054f09272fb39e4d03b9957dbb0d75a50b6a7025b4031e57
|
7
|
+
data.tar.gz: 2651f86adccfd7469c01268c7408115547e94e90723a752a9d047c59c4431204cbb606815b40245893ff8d142657cf65e7a493d063a20d89416fd7f0a917879d
|
@@ -21,7 +21,7 @@ module ForemanTasks
|
|
21
21
|
|
22
22
|
api :GET, '/tasks/summary', 'Show task summary'
|
23
23
|
def summary
|
24
|
-
render :json => ForemanTasks::Task::Summarizer.new.summarize_by_status
|
24
|
+
render :json => ForemanTasks::Task::Summarizer.new(resource_scope).summarize_by_status
|
25
25
|
end
|
26
26
|
|
27
27
|
api :GET, '/tasks/:id', 'Show task details'
|
@@ -248,7 +248,7 @@ module ForemanTasks
|
|
248
248
|
end
|
249
249
|
|
250
250
|
def find_task
|
251
|
-
@task =
|
251
|
+
@task = resource_scope.find(params[:id])
|
252
252
|
end
|
253
253
|
|
254
254
|
def resource_scope(_options = {})
|
@@ -257,7 +257,7 @@ module ForemanTasks
|
|
257
257
|
|
258
258
|
def action_permission
|
259
259
|
case params[:action]
|
260
|
-
when 'bulk_search'
|
260
|
+
when 'bulk_search', 'summary'
|
261
261
|
:view
|
262
262
|
when 'bulk_resume'
|
263
263
|
:edit
|
@@ -6,7 +6,7 @@ module ForemanTasks
|
|
6
6
|
before_action :restrict_dangerous_actions, :only => [:unlock, :force_unlock]
|
7
7
|
|
8
8
|
def show
|
9
|
-
@task =
|
9
|
+
@task = resource_base.find(params[:id])
|
10
10
|
end
|
11
11
|
|
12
12
|
def index
|
@@ -24,7 +24,7 @@ module ForemanTasks
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def sub_tasks
|
27
|
-
task =
|
27
|
+
task = resource_base.find(params[:id])
|
28
28
|
@tasks = filter(task.sub_tasks)
|
29
29
|
render :index
|
30
30
|
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module ForemanTasks
|
2
2
|
class Task::Summarizer
|
3
|
+
def initialize(scope = Task.authorized)
|
4
|
+
@scope = scope
|
5
|
+
end
|
6
|
+
|
3
7
|
def summarize_by_status(since = nil)
|
4
|
-
result =
|
5
|
-
|
6
|
-
|
8
|
+
result = @scope.where("result <> 'success'")
|
9
|
+
.select('count(state) AS count, state, result, max(started_at) AS started_at')
|
10
|
+
.group(:state, :result).order(:state)
|
7
11
|
result = result.where('started_at > ?', since) if since
|
8
12
|
result
|
9
13
|
end
|
10
14
|
|
11
15
|
def latest_tasks_in_errors_warning(limit = 5)
|
12
|
-
|
16
|
+
@scope.where('result in (?)', %w[error warning]).order('started_at DESC').limit(limit)
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -25,6 +25,13 @@ module ForemanTasks
|
|
25
25
|
assert_response :missing
|
26
26
|
assert_includes @response.body, 'Resource task not found by id'
|
27
27
|
end
|
28
|
+
|
29
|
+
it 'does not show task the user is not allowed to see' do
|
30
|
+
setup_user('view', 'foreman_tasks', 'owner.id = current_user')
|
31
|
+
get :show, params: { id: FactoryBot.create(:some_task).id },
|
32
|
+
session: set_session_user(User.current)
|
33
|
+
assert_response :not_found
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
describe 'GET /api/tasks/summary' do
|
@@ -41,24 +48,41 @@ module ForemanTasks
|
|
41
48
|
suspend
|
42
49
|
end
|
43
50
|
end
|
51
|
+
|
52
|
+
def self.while_suspended
|
53
|
+
triggered = ForemanTasks.trigger(DummyTestSummaryAction, true)
|
54
|
+
wait_for { ForemanTasks::Task.find_by(external_id: triggered.id).state == 'running' }
|
55
|
+
wait_for do
|
56
|
+
w = ForemanTasks.dynflow.world
|
57
|
+
w.persistence.load_step(triggered.id, 2, w).state == :suspended
|
58
|
+
end
|
59
|
+
yield
|
60
|
+
ForemanTasks.dynflow.world.event(triggered.id, 2, nil)
|
61
|
+
triggered.finished.wait
|
62
|
+
end
|
44
63
|
end
|
45
64
|
|
46
65
|
test_attributes :pid => 'bdcab413-a25d-4fe1-9db4-b50b5c31ebce'
|
47
66
|
it 'get tasks summary' do
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
67
|
+
DummyTestSummaryAction.while_suspended do
|
68
|
+
get :summary
|
69
|
+
assert_response :success
|
70
|
+
response = JSON.parse(@response.body)
|
71
|
+
assert_kind_of Array, response
|
72
|
+
assert_not response.empty?
|
73
|
+
assert_kind_of Hash, response[0]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'gets tasks summary only for tasks the user is allowed to see' do
|
78
|
+
DummyTestSummaryAction.while_suspended do
|
79
|
+
setup_user('view', 'foreman_tasks', 'owner.id = current_user')
|
80
|
+
get :summary
|
81
|
+
assert_response :success
|
82
|
+
response = JSON.parse(@response.body)
|
83
|
+
assert_kind_of Array, response
|
84
|
+
assert response.empty?
|
53
85
|
end
|
54
|
-
get :summary
|
55
|
-
assert_response :success
|
56
|
-
response = JSON.parse(@response.body)
|
57
|
-
assert_kind_of Array, response
|
58
|
-
assert_not response.empty?
|
59
|
-
assert_kind_of Hash, response[0]
|
60
|
-
ForemanTasks.dynflow.world.event(triggered.id, 2, nil)
|
61
|
-
triggered.finished.wait
|
62
86
|
end
|
63
87
|
end
|
64
88
|
|
@@ -32,6 +32,24 @@ module ForemanTasks
|
|
32
32
|
assert_include response.body.lines[1], 'Some action'
|
33
33
|
end
|
34
34
|
|
35
|
+
describe 'show' do
|
36
|
+
it 'does not allow user without permissions to see task details' do
|
37
|
+
setup_user('view', 'foreman_tasks', 'owner.id = current_user')
|
38
|
+
get :show, params: { id: FactoryBot.create(:some_task).id },
|
39
|
+
session: set_session_user(User.current)
|
40
|
+
assert_response :not_found
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'sub_tasks' do
|
45
|
+
it 'does not allow user without permissions to see task details' do
|
46
|
+
setup_user('view', 'foreman_tasks', 'owner.id = current_user')
|
47
|
+
get :sub_tasks, params: { id: FactoryBot.create(:some_task).id },
|
48
|
+
session: set_session_user(User.current)
|
49
|
+
assert_response :not_found
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
35
53
|
describe 'taxonomy scoping' do
|
36
54
|
let(:organizations) { (0..1).map { FactoryBot.create(:organization) } }
|
37
55
|
let(:tasks) { organizations.map { |o| linked_task(o) } + [FactoryBot.create(:some_task)] }
|
data/test/unit/task_test.rb
CHANGED
@@ -84,9 +84,11 @@ class TasksTest < ActiveSupport::TestCase
|
|
84
84
|
end
|
85
85
|
|
86
86
|
describe 'task without valid execution plan' do
|
87
|
+
let(:missing_task_uuid) { '11111111-2222-3333-4444-555555555555' }
|
88
|
+
|
87
89
|
let(:task) do
|
88
90
|
task = FactoryBot.create(:dynflow_task).tap do |task|
|
89
|
-
task.external_id =
|
91
|
+
task.external_id = missing_task_uuid
|
90
92
|
task.save
|
91
93
|
end
|
92
94
|
ForemanTasks::Task.find(task.id)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman-tasks-core
|
@@ -299,8 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
299
299
|
- !ruby/object:Gem::Version
|
300
300
|
version: '0'
|
301
301
|
requirements: []
|
302
|
-
|
303
|
-
rubygems_version: 2.7.3
|
302
|
+
rubygems_version: 3.0.3
|
304
303
|
signing_key:
|
305
304
|
specification_version: 4
|
306
305
|
summary: Foreman plugin for showing tasks information for resoruces and users
|