Skip to content

Commit

Permalink
Fixes #37938 - Reject start-at dates in the past when a job is scheduled
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Fernández Rodríguez <pafernan@redhat.com>
  • Loading branch information
pafernanr committed Jan 2, 2025
1 parent 749b439 commit d3d5d2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/models/foreman_tasks/triggering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Triggering < ApplicationRecord
:if => proc { |t| t.recurring? && t.input_type == :monthly } }
validate :can_start_recurring, :if => :recurring?
validate :can_start_future, :if => :future?
validate :start_at_is_not_past

def self.new_from_params(params = {})
new(params.except(:mode, :start_at, :start_before)).tap do |triggering|
Expand Down Expand Up @@ -121,5 +122,9 @@ def can_start_future
parse_start_at!
errors.add(:start_before_raw, _('The task could not be started')) if !start_before.nil? && start_before < start_at
end

def start_at_is_not_past
errors.add(:start_at, _('is in the past')) if !start_at.nil? && Time.zone.parse(start_at_raw) < Time.zone.now
end
end
end
1 change: 0 additions & 1 deletion test/unit/triggering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class TriggeringTest < ActiveSupport::TestCase
it 'is validates future execution' do
triggering = FactoryBot.build(:triggering, :future)
assert_predicate(triggering, :valid?)
triggering.start_before = triggering.start_at - 120
assert_not_predicate(triggering, :valid?)
end

Expand Down

0 comments on commit d3d5d2b

Please sign in to comment.