Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37938 - Reject start-at dates in the past when a job is scheduled #763

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion test/unit/triggering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TriggeringTest < ActiveSupport::TestCase
triggering = FactoryBot.build(:triggering, :future)
assert_predicate(triggering, :valid?)
triggering.start_before = triggering.start_at - 120
assert_not_predicate(triggering, :valid?)
assert_not_predicate(triggering, :valid?).returns(false)
end

it 'is invalid when recurring logic is invalid' do
Expand Down