mirror of
https://github.com/mastodon/mastodon.git
synced 2025-02-02 07:21:43 +01:00
Fix PollExpirationValidator
redundant check for expires_at
presence (#33777)
This commit is contained in:
parent
7ffda06b6a
commit
e53c8fbaf8
@ -5,9 +5,12 @@ class PollExpirationValidator < ActiveModel::Validator
|
||||
MIN_EXPIRATION = 5.minutes.freeze
|
||||
|
||||
def validate(poll)
|
||||
# We have a `presence: true` check for this attribute already
|
||||
return if poll.expires_at.nil?
|
||||
|
||||
current_time = Time.now.utc
|
||||
|
||||
poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_long')) if poll.expires_at.nil? || poll.expires_at - current_time > MAX_EXPIRATION
|
||||
poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_short')) if poll.expires_at.present? && (poll.expires_at - current_time).ceil < MIN_EXPIRATION
|
||||
poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_long')) if poll.expires_at - current_time > MAX_EXPIRATION
|
||||
poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_short')) if (poll.expires_at - current_time).ceil < MIN_EXPIRATION
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user