comment votes: add index page.
This commit is contained in:
@@ -10,6 +10,24 @@ class CommentVote < ApplicationRecord
|
||||
validate :validate_comment_can_be_down_voted
|
||||
validates_inclusion_of :score, :in => [-1, 1], :message => "must be 1 or -1"
|
||||
|
||||
def self.visible(user = CurrentUser.user)
|
||||
return all if user.is_admin?
|
||||
where(user: user)
|
||||
end
|
||||
|
||||
def self.comment_matches(params)
|
||||
return all if params.blank?
|
||||
where(comment_id: Comment.search(params).reorder(nil).select(:id))
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = super
|
||||
q = q.visible
|
||||
q = q.search_attributes(params, :comment_id, :user, :score)
|
||||
q = q.comment_matches(params[:comment])
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def validate_user_can_vote
|
||||
if !user.can_comment_vote?
|
||||
errors.add :base, "You cannot vote on more than 10 comments per hour"
|
||||
|
||||
Reference in New Issue
Block a user