eBooru/app/models/post_vote.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

23 lines
483 B
Ruby

# frozen_string_literal: true
class PostVote < UserVote
validate :validate_user_can_vote
def self.model_creator_column
:uploader
end
def validate_user_can_vote
if user.younger_than(3.days) && score == -1
errors.add(:user, "must be 3 days old to downvote posts")
return false
end
allowed = user.can_post_vote_with_reason
if allowed != true
errors.add(:user, User.throttle_reason(allowed))
return false
end
true
end
end