Disallow to modify the end date for an ended poll

This commit is contained in:
Julian Herrero
2022-09-14 18:06:34 +02:00
committed by Javi Martín
parent 8b5c315eb0
commit ecd22131f1
4 changed files with 24 additions and 1 deletions

View File

@@ -40,6 +40,7 @@ class Poll < ApplicationRecord
validate :start_date_is_not_past_date, on: :create
validate :start_date_change, on: :update
validate :end_date_is_not_past_date, on: :update
validate :end_date_change, on: :update
validate :only_one_active, unless: :public?
accepts_nested_attributes_for :questions, reject_if: :all_blank, allow_destroy: true
@@ -168,6 +169,12 @@ class Poll < ApplicationRecord
end
end
def end_date_change
if will_save_change_to_ends_at? && ends_at_in_database < Time.current
errors.add(:ends_at, I18n.t("errors.messages.cannot_change_date.poll_ended"))
end
end
def generate_slug?
slug.nil?
end