foreman-tasks 0.14.5 → 0.14.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f651b03116f8e483229e92bad65056ad96c2e1922850d0dd93f5a347d0f34f46
4
- data.tar.gz: 8f1fa49ba1dcd42f2c4508e2dd4d12a981a7fdd5c6233f48d76770276d47ad55
3
+ metadata.gz: 675f98353547dd5b378bfe5055c60e976618b39754e4d46e0d361641ee8640e0
4
+ data.tar.gz: 2de7b22aaaacdb644d953e0aeb4c0e7ba6083e2f9650248baf021b78d0ff7474
5
5
  SHA512:
6
- metadata.gz: 93904ebc7747a5aa2e49862c243b7330eb1d804fe4d5c58fc87da036e052c8c3cd088bbcf7d25d4d12b41118d0398f0ab2d923c846369368af1b8602e89b079a
7
- data.tar.gz: 83eac16d2413eb0aab6e2a14eb618ff570e4aada7aa9b1c3f80ddded23cd53303ca77c9b569b9af7638782445d5b59fed490df9d0c31e451c53f78d7eda34373
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 = Task.find(params[:id])
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 = Task.find(params[:id])
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 = Task.find(params[:id])
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 = ::ForemanTasks::Task.where("result <> 'success'")
5
- .select('count(state) AS count, state, result, max(started_at) AS started_at')
6
- .group(:state, :result).order(:state)
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
- ::ForemanTasks::Task.where('result in (?)', %w[error warning]).order('started_at DESC').limit(limit)
16
+ @scope.where('result in (?)', %w[error warning]).order('started_at DESC').limit(limit)
13
17
  end
14
18
  end
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanTasks
2
- VERSION = '0.14.5'.freeze
2
+ VERSION = '0.14.6'.freeze
3
3
  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
- triggered = ForemanTasks.trigger(DummyTestSummaryAction, true)
49
- wait_for { ForemanTasks::Task.find_by(external_id: triggered.id).state == 'running' }
50
- wait_for do
51
- w = ForemanTasks.dynflow.world
52
- w.persistence.load_step(triggered.id, 2, w).state == :suspended
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)] }
@@ -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 = 'missing-task'
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.5
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: 2018-12-21 00:00:00.000000000 Z
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
- rubyforge_project:
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