/comment_votes: make visible to banned users.
Let banned users see their own comment votes.
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
class CommentVotesController < ApplicationController
|
class CommentVotesController < ApplicationController
|
||||||
before_action :member_only
|
before_action :member_only, except: [:index]
|
||||||
skip_before_action :api_check
|
skip_before_action :api_check
|
||||||
respond_to :js, :json, :xml, :html
|
respond_to :js, :json, :xml, :html
|
||||||
rescue_with CommentVote::Error, ActiveRecord::RecordInvalid, status: 422
|
rescue_with CommentVote::Error, ActiveRecord::RecordInvalid, status: 422
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@comment_votes = CommentVote.paginated_search(params, count_pages: true)
|
@comment_votes = CommentVote.visible(CurrentUser.user).paginated_search(params, count_pages: true)
|
||||||
@comment_votes = @comment_votes.includes(:user, comment: [:creator, post: [:uploader]]) if request.format.html?
|
@comment_votes = @comment_votes.includes(:user, comment: [:creator, post: [:uploader]]) if request.format.html?
|
||||||
respond_with(@comment_votes)
|
respond_with(@comment_votes)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,8 +11,13 @@ class CommentVote < ApplicationRecord
|
|||||||
validates_inclusion_of :score, :in => [-1, 1], :message => "must be 1 or -1"
|
validates_inclusion_of :score, :in => [-1, 1], :message => "must be 1 or -1"
|
||||||
|
|
||||||
def self.visible(user = CurrentUser.user)
|
def self.visible(user = CurrentUser.user)
|
||||||
return all if user.is_admin?
|
if user.is_admin?
|
||||||
where(user: user)
|
all
|
||||||
|
elsif user.is_member?
|
||||||
|
where(user: user)
|
||||||
|
else
|
||||||
|
none
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.comment_matches(params)
|
def self.comment_matches(params)
|
||||||
@@ -22,7 +27,6 @@ class CommentVote < ApplicationRecord
|
|||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = super
|
q = super
|
||||||
q = q.visible
|
|
||||||
q = q.search_attributes(params, :comment_id, :user, :score)
|
q = q.search_attributes(params, :comment_id, :user, :score)
|
||||||
q = q.comment_matches(params[:comment])
|
q = q.comment_matches(params[:comment])
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
|
|||||||
Reference in New Issue
Block a user