foreman-tasks 0.15.7 → 0.15.8

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: 6e04f597cdb4a8e79251fa3ccb6a9d975f1b2c180406dbaf269430a9f21e5c62
4
- data.tar.gz: 639f76c6744729b1b8622534a255d6ffc38404cdac75b02b73667076574eb998
3
+ metadata.gz: e81942c1beade63bde5e4efc461d3c9b607c90782efdd05c247942cab3b81a99
4
+ data.tar.gz: 2ca06d362cfe353dc4df8959907b48de6da7e741a409e4ea9cf039ee5664d11b
5
5
  SHA512:
6
- metadata.gz: 3c45cb1e7ba0ab92d308bbc4fb7e5bc32063ab78c66dc7f6c4e136d6dc5aecbbc83c095e43280796afff44f407f1abbe8ac9ab2e73087aa2df0a1f09e63a44bc
7
- data.tar.gz: 85327d35ba3de74c3ce82b86907530e330d22d9db343005114b0d4c646f598c3913cc9bdfae9d3092a023366c302e2225f53e7ff2a1f537433902c0fc10d317e
6
+ metadata.gz: 3441d249f033e4e83de8649d041c19d2a0012006f5a37d364ccfaa341000b86c5ba638b89a5a3f54c0452f6d2a84e2da0b59cd7e0065372081da44b84774a64c
7
+ data.tar.gz: aeb244156e659b82173c111d7e7764eb7ba9df41bbdc5f6980565aa0d86658a19d97fcf357b204bf8ba99878d466e977a18f153dfafffb760d315034d68a7bb3
@@ -12,16 +12,7 @@ module ForemanTasks
12
12
 
13
13
  def index
14
14
  params[:order] ||= 'started_at DESC'
15
- respond_to do |format|
16
- format.html do
17
- @tasks = filter(resource_base)
18
- render :index, layout: !request.xhr?
19
- end
20
- format.csv do
21
- @tasks = filter(resource_base, paginate: false)
22
- csv_response(@tasks, [:id, :action, :state, :result, 'started_at.in_time_zone', 'ended_at.in_time_zone', :username], ['Id', 'Action', 'State', 'Result', 'Started At', 'Ended At', 'User'])
23
- end
24
- end
15
+ respond_with_tasks resource_base
25
16
  end
26
17
 
27
18
  def summary
@@ -29,9 +20,9 @@ module ForemanTasks
29
20
  end
30
21
 
31
22
  def sub_tasks
32
- task = resource_base.find(params[:id])
33
- @tasks = filter(task.sub_tasks)
34
- render :index
23
+ # @task is used when rendering breadcrumbs
24
+ @task = resource_base.find(params[:id])
25
+ respond_with_tasks @task.sub_tasks
35
26
  end
36
27
 
37
28
  def cancel_step
@@ -103,6 +94,19 @@ module ForemanTasks
103
94
 
104
95
  private
105
96
 
97
+ def respond_with_tasks(scope)
98
+ respond_to do |format|
99
+ format.html do
100
+ @tasks = filter(scope)
101
+ render :index, layout: !request.xhr?
102
+ end
103
+ format.csv do
104
+ @tasks = filter(scope, paginate: false)
105
+ csv_response(@tasks, [:id, :action, :state, :result, 'started_at.in_time_zone', 'ended_at.in_time_zone', :username], ['Id', 'Action', 'State', 'Result', 'Started At', 'Ended At', 'User'])
106
+ end
107
+ end
108
+ end
109
+
106
110
  def restrict_dangerous_actions
107
111
  render_403 unless Setting['dynflow_allow_dangerous_actions']
108
112
  end
@@ -122,6 +122,26 @@ module ForemanTasks
122
122
  render :partial => 'common/trigger_form', :locals => { :f => f, :triggering => triggering }
123
123
  end
124
124
 
125
+ def task_breadcrumb_item(task, active = false)
126
+ item = { :caption => format_task_input(task) }
127
+ item[:url] = url_for(foreman_tasks_task_path(task.id)) unless active
128
+ item
129
+ end
130
+
131
+ def index_breadcrumb_item
132
+ item = { :caption => _('Tasks') }
133
+ item[:url] = foreman_tasks_tasks_url if action_name != 'index'
134
+ item
135
+ end
136
+
137
+ def breadcrumb_items
138
+ items = [index_breadcrumb_item]
139
+ return items if action_name == 'index'
140
+ items << task_breadcrumb_item(@task, action_name == 'show')
141
+ items << { :caption => _('Sub tasks') } if action_name == 'sub_tasks'
142
+ items
143
+ end
144
+
125
145
  private
126
146
 
127
147
  def future_mode_fieldset(f, triggering)
@@ -10,6 +10,9 @@
10
10
  yo: 'ya'
11
11
  }.to_json) %>
12
12
  <% end %>
13
+ <% content_for(:breadcrumbs) do %>
14
+ <% breadcrumbs(:items => breadcrumb_items) %>
15
+ <% end %>
13
16
 
14
17
  <% title _("Tasks") %>
15
18
  <% title_actions csv_link, help_button %>
@@ -1,15 +1,7 @@
1
1
  <% stylesheet 'foreman_tasks/tasks' %>
2
2
 
3
3
  <%= breadcrumbs(
4
- items: [
5
- {
6
- caption: _('Tasks'),
7
- url: url_for(foreman_tasks_tasks_path)
8
- },
9
- {
10
- caption: format_task_input(@task)
11
- }
12
- ],
4
+ items: breadcrumb_items,
13
5
  name_field: 'action',
14
6
  resource_url: foreman_tasks_api_tasks_path,
15
7
  switcher_item_url: foreman_tasks_task_path(:id => ':id')
@@ -244,6 +244,7 @@ namespace :foreman_tasks do
244
244
 
245
245
  tasks = ForemanTasks::Task.search_for(filter)
246
246
 
247
+ puts _("Exporting all tasks matching filter #{filter}")
247
248
  puts _("Gathering #{tasks.count} tasks.")
248
249
  if format == 'html'
249
250
  Dir.mktmpdir('task-export') do |tmp_dir|
@@ -255,7 +256,6 @@ namespace :foreman_tasks do
255
256
  tasks.each_with_index do |task, count|
256
257
  File.open(File.join(tmp_dir, "#{task.id}.html"), 'w') { |file| file.write(PageHelper.pagify(renderer.render_task(task))) }
257
258
  puts "#{count + 1}/#{total}"
258
- count += 1
259
259
  end
260
260
 
261
261
  File.open(File.join(tmp_dir, 'index.html'), 'w') { |file| file.write(PageHelper.pagify(PageHelper.generate_index(tasks))) }
@@ -1,3 +1,3 @@
1
1
  module ForemanTasks
2
- VERSION = '0.15.7'.freeze
2
+ VERSION = '0.15.8'.freeze
3
3
  end
@@ -67,6 +67,17 @@ module ForemanTasks
67
67
  session: set_session_user(User.current)
68
68
  assert_response :not_found
69
69
  end
70
+
71
+ it 'supports csv export' do
72
+ parent = FactoryBot.create(:some_task, :action => 'Some action')
73
+ child = FactoryBot.create(:some_task, :action => 'Child action')
74
+ child.parent_task_id = parent.id
75
+ child.save!
76
+ get(:sub_tasks, params: { id: parent.id, format: :csv }, session: set_session_user)
77
+ assert_response :success
78
+ assert_equal 2, response.body.lines.size
79
+ assert_include response.body.lines[1], 'Child action'
80
+ end
70
81
  end
71
82
 
72
83
  describe 'taxonomy scoping' do
@@ -0,0 +1,39 @@
1
+ require 'foreman_tasks_test_helper'
2
+
3
+ module ForemanTasks
4
+ class ForemanTasksHelperTest < ActionView::TestCase
5
+ describe 'breadcrumb items' do
6
+ before do
7
+ self.class.send(:include, ForemanTasks::TasksHelper)
8
+ end
9
+
10
+ it 'prepares items for index correctly' do
11
+ stubs(:action_name).returns('index')
12
+ items = breadcrumb_items
13
+ items.count.must_equal 1
14
+ items.first[:caption].must_equal 'Tasks'
15
+ items.first[:url].must_be_nil
16
+ end
17
+
18
+ it 'prepares items for show correctly' do
19
+ @task = FactoryBot.build(:dynflow_task, :user_create_task)
20
+ @task.action = 'A task'
21
+ stubs(:action_name).returns('show')
22
+ items = breadcrumb_items
23
+ items.map { |i| i[:caption] }.must_equal ['Tasks', 'A task']
24
+ items.last[:url].must_be_nil
25
+ end
26
+
27
+ it 'prepares items for sub tasks correctly' do
28
+ @task = FactoryBot.build(:dynflow_task, :user_create_task)
29
+ child = FactoryBot.build(:dynflow_task, :user_create_task)
30
+ @task.sub_tasks = [child]
31
+ @task.action = 'A task'
32
+ stubs(:action_name).returns('sub_tasks')
33
+ items = breadcrumb_items
34
+ items.map { |i| i[:caption] }.must_equal ['Tasks', 'A task', 'Sub tasks']
35
+ items.last[:url].must_be_nil
36
+ end
37
+ end
38
+ end
39
+ end
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.15.7
4
+ version: 0.15.8
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: 2019-07-16 00:00:00.000000000 Z
11
+ date: 2019-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman-tasks-core
@@ -279,6 +279,7 @@ files:
279
279
  - test/factories/triggering_factory.rb
280
280
  - test/foreman_tasks_core_test_helper.rb
281
281
  - test/foreman_tasks_test_helper.rb
282
+ - test/helpers/foreman_tasks/foreman_tasks_helper_test.rb
282
283
  - test/helpers/foreman_tasks/tasks_helper_test.rb
283
284
  - test/lib/actions/middleware/keep_current_request_id_test.rb
284
285
  - test/lib/actions/middleware/keep_current_taxonomies_test.rb
@@ -429,8 +430,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
429
430
  - !ruby/object:Gem::Version
430
431
  version: '0'
431
432
  requirements: []
432
- rubyforge_project:
433
- rubygems_version: 2.7.3
433
+ rubygems_version: 3.0.3
434
434
  signing_key:
435
435
  specification_version: 4
436
436
  summary: Foreman plugin for showing tasks information for resources and users
@@ -447,6 +447,7 @@ test_files:
447
447
  - test/factories/triggering_factory.rb
448
448
  - test/foreman_tasks_core_test_helper.rb
449
449
  - test/foreman_tasks_test_helper.rb
450
+ - test/helpers/foreman_tasks/foreman_tasks_helper_test.rb
450
451
  - test/helpers/foreman_tasks/tasks_helper_test.rb
451
452
  - test/lib/actions/middleware/keep_current_request_id_test.rb
452
453
  - test/lib/actions/middleware/keep_current_taxonomies_test.rb