2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-08 06:04:17 -04:00
|
|
|
class PostVote < UserVote
|
2019-09-04 08:30:37 -04:00
|
|
|
validate :validate_user_can_vote
|
2016-02-24 14:35:26 -05:00
|
|
|
|
2022-10-08 17:59:33 -04:00
|
|
|
def self.model_creator_column
|
|
|
|
:uploader
|
|
|
|
end
|
|
|
|
|
2019-09-04 00:56:41 -04:00
|
|
|
def validate_user_can_vote
|
2019-09-18 15:36:05 -04:00
|
|
|
if user.younger_than(3.days) && score == -1
|
|
|
|
errors.add(:user, "must be 3 days old to downvote posts")
|
2019-09-04 00:56:41 -04:00
|
|
|
return false
|
|
|
|
end
|
2019-09-18 15:36:05 -04:00
|
|
|
allowed = user.can_post_vote_with_reason
|
2019-09-04 00:56:41 -04:00
|
|
|
if allowed != true
|
2019-09-18 15:36:05 -04:00
|
|
|
errors.add(:user, User.throttle_reason(allowed))
|
2019-09-04 00:56:41 -04:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
2010-02-15 17:45:09 -05:00
|
|
|
end
|