eBooru/app/models/comment_vote.rb

34 lines
855 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class CommentVote < UserVote
2011-04-01 19:01:17 -04:00
validate :validate_user_can_vote
validate :validate_comment_can_be_voted
def self.for_comments_and_user(comment_ids, user_id)
return {} unless user_id
CommentVote.where(comment_id: comment_ids, user_id: user_id).index_by(&:comment_id)
end
2022-10-08 17:59:33 -04:00
def self.model_creator_column
:creator
end
2011-04-01 19:01:17 -04:00
def validate_user_can_vote
allowed = user.can_comment_vote_with_reason
2019-09-04 00:56:41 -04:00
if allowed != true
errors.add(:user, User.throttle_reason(allowed))
2019-09-04 00:56:41 -04:00
return false
2011-04-01 19:01:17 -04:00
end
2019-09-04 00:56:41 -04:00
true
2011-04-01 19:01:17 -04:00
end
2013-03-19 08:10:10 -04:00
def validate_comment_can_be_voted
if (is_positive? || is_negative?) && comment.creator == CurrentUser.user
errors.add :base, "You cannot vote on your own comments"
end
if comment.is_sticky
errors.add :base, "You cannot vote on sticky comments"
2011-04-01 19:01:17 -04:00
end
end
2010-02-15 13:59:58 -05:00
end