foreman-tasks 11.0.1 → 11.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79bd6594ab916273ed9721d27414688ac717fd041ba33fdc67a1531e0ff0e30c
4
- data.tar.gz: 91de29666d6b045b9179f662bda4f645e4532683ec1ff5e397b6f90948e6f32a
3
+ metadata.gz: 14937b8abb913127b2f1ab4028a967e25ed56ae35a476dc99dfd4bce07d9ec2a
4
+ data.tar.gz: 124922626f20e21268d8fd2c341be934af3d17a1e1fe9df34a61d8a90718508f
5
5
  SHA512:
6
- metadata.gz: 81a6e7b9989f9becb04bf6486ded109c937e9395325ac060d9ce9b027343f44b2be70d44a1b997cb19c15520dabf7bdd654ddf7b017482b09e812fa980a7f103
7
- data.tar.gz: ed7f40efaae46bbaec076deb15d0c7ff076fe661f5ad28bff67694070954eeac0229d3304a81375982cf96e9f11b60f7fb94402285310598837e52b0ffcec499
6
+ metadata.gz: ed4850116bdc86ba5118a2c1a08e4d475285f3236dee047f8b3c98c24c5eb4030b31a409b0293e5016153e92522f90ef31fccca48e901c7ca30f56b95f55d06b
7
+ data.tar.gz: c93ab2b4c78fac530e6bef4efca4c0baee0d03931522b15726526406881f8e538cec47dbba5ad863f86faca1a3ec025585453b3b47560435cd56fb1cd6fffb20
@@ -23,11 +23,7 @@ module Actions
23
23
  end
24
24
 
25
25
  def humanized_name
26
- if task.sub_tasks.first
27
- task.sub_tasks.first.humanized[:action]
28
- else
29
- _('Bulk action')
30
- end
26
+ with_sub_task { |t| t.humanized[:action] } || _('Bulk action')
31
27
  end
32
28
 
33
29
  def rescue_strategy
@@ -35,8 +31,7 @@ module Actions
35
31
  end
36
32
 
37
33
  def humanized_input
38
- a_sub_task = task.sub_tasks.first
39
- if a_sub_task
34
+ with_sub_task do |a_sub_task|
40
35
  [a_sub_task.humanized[:action].to_s.downcase] +
41
36
  Array(a_sub_task.humanized[:input]) + ['...']
42
37
  end
@@ -79,5 +74,17 @@ module Actions
79
74
  def extract_concurrency_limit(args = [], limit = nil)
80
75
  args.find { |arg| arg.is_a?(Hash) && arg.key?(:concurrency_limit) }&.fetch(:concurrency_limit) || limit
81
76
  end
77
+
78
+ def with_sub_task
79
+ sub_task = begin
80
+ task.sub_tasks.first
81
+ rescue ActiveRecord::RecordNotFound
82
+ # #task raises if the action has no task linked to it
83
+ # While it shouldn't happen, there's not much of a difference
84
+ # between a action not having a task and an action having a
85
+ # task but no sub tasks
86
+ end
87
+ yield sub_task if sub_task
88
+ end
82
89
  end
83
90
  end
@@ -8,11 +8,9 @@ module ForemanTasks
8
8
  graphql_type '::Types::Triggering'
9
9
 
10
10
  before_save do
11
- if future?
11
+ unless immediate?
12
12
  parse_start_at!
13
13
  parse_start_before!
14
- else
15
- self.start_at ||= Time.zone.now
16
14
  end
17
15
  end
18
16
 
@@ -31,21 +29,20 @@ module ForemanTasks
31
29
  :inclusion => { :in => ALLOWED_INPUT_TYPES,
32
30
  :message => _('%{value} is not allowed input type') }
33
31
  validates :start_at_raw, format: { :with => TIME_REGEXP, :if => ->(triggering) { triggering.future? || (triggering.recurring? && triggering.start_at_raw) },
34
- :message => _('%{value} is wrong format') }
32
+ :message => _('%{value} is wrong format'), :allow_blank => true }
35
33
  validates :start_before_raw, format: { :with => TIME_REGEXP, :if => :future?,
36
34
  :message => _('%{value} is wrong format'), :allow_blank => true }
37
35
  validates :days, format: { :with => DAYS_REGEXP,
38
36
  :if => proc { |t| t.recurring? && t.input_type == :monthly } }
39
37
  validate :can_start_recurring, :if => :recurring?
40
38
  validate :can_start_future, :if => :future?
41
- validate :start_at_is_not_past
39
+ validate :start_at_is_not_past, :if => ->(triggering) { triggering.start_at_relevant? && triggering.start_at_changed? }
42
40
 
43
41
  def self.new_from_params(params = {})
44
42
  new(params.except(:mode, :start_at, :start_before)).tap do |triggering|
45
43
  triggering.mode = params.fetch(:mode, :immediate).to_sym
46
44
  triggering.input_type = params.fetch(:input_type, :daily).to_sym
47
45
  triggering.end_time_limited = params[:end_time_limited] == 'true'
48
- triggering.start_at_raw ||= Time.zone.now.strftime(TIME_FORMAT)
49
46
  triggering.recurring_logic = ::ForemanTasks::RecurringLogic.new_from_triggering(triggering) if triggering.recurring?
50
47
  end
51
48
  end
@@ -77,7 +74,7 @@ module ForemanTasks
77
74
 
78
75
  def delay_options
79
76
  {
80
- :start_at => start_at.utc,
77
+ :start_at => start_at.try(:utc),
81
78
  :start_before => start_before.try(:utc),
82
79
  }
83
80
  end
@@ -108,6 +105,11 @@ module ForemanTasks
108
105
  self.start_before ||= Time.zone.parse(start_before_raw) if start_before_raw.present?
109
106
  end
110
107
 
108
+ # start_at is required for future execution and optional for recurring execution
109
+ def start_at_relevant?
110
+ future? || (recurring? && (start_at || start_at_raw))
111
+ end
112
+
111
113
  private
112
114
 
113
115
  def can_start_recurring
@@ -1,3 +1,3 @@
1
1
  module ForemanTasks
2
- VERSION = '11.0.1'.freeze
2
+ VERSION = '11.0.2'.freeze
3
3
  end
@@ -48,6 +48,22 @@ class TriggeringTest < ActiveSupport::TestCase
48
48
  triggering = FactoryBot.build(:triggering, :recurring_logic => logic, :mode => :recurring, :input_type => :cronline, :cronline => '* * * * *')
49
49
  assert_predicate(triggering, :valid?)
50
50
  end
51
+
52
+ it 'is valid by default' do
53
+ triggering = ForemanTasks::Triggering.new_from_params
54
+ assert triggering.save
55
+ assert_predicate triggering.start_at, :blank?
56
+ assert_predicate triggering, :valid?
57
+ end
58
+
59
+ it 'stays valid once created' do
60
+ triggering = ForemanTasks::Triggering.new_from_params({ :mode => "future" })
61
+ triggering.start_at = Time.zone.now + 1.second
62
+ triggering.save!
63
+ assert_predicate(triggering, :valid?)
64
+ Time.zone.expects(:now).never # No time comparisons should be done as nothing changed
65
+ assert_predicate(triggering, :valid?)
66
+ end
51
67
  end
52
68
 
53
69
  it 'cannot have mode set to arbitrary value' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.0.1
4
+ version: 11.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
@@ -640,7 +640,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
640
640
  - !ruby/object:Gem::Version
641
641
  version: '0'
642
642
  requirements: []
643
- rubygems_version: 3.6.7
643
+ rubygems_version: 3.6.9
644
644
  specification_version: 4
645
645
  summary: Foreman plugin for showing tasks information for resources and users
646
646
  test_files: