Skip to content

Commit

Permalink
Fixes #37938 - Reject 'start at' dates in the past when a job is sche…
Browse files Browse the repository at this point in the history
…duled

Signed-off-by: Pablo Fernández Rodríguez <[email protected]>
  • Loading branch information
pafernanr committed Nov 11, 2024
1 parent c59952e commit 4767f89
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion 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 @@ -95,7 +96,6 @@ def recurring?

def parse_start_at!
self.start_at ||= Time.zone.parse(start_at_raw) if start_at_raw.present?
errors.add(:start_at, _('is in the past')) if self.start_at < Time.zone.now
end

def parse_start_at
Expand All @@ -122,5 +122,10 @@ 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
future

0 comments on commit 4767f89

Please sign in to comment.