Refactor how model visibility works in index actions: * Call `visible` in the controller instead of in model `search` methods. This decouples model visibility from model searching. * Explicitly pass CurrentUser when calling `visible`. This reduces hidden dependencies on the current user inside models. * Standardize on calling the method `visible`. In some places it was called `permitted` instead. * Add a `visible` base method to ApplicationModel.
28 lines
649 B
Ruby
28 lines
649 B
Ruby
class PostVotesController < ApplicationController
|
|
before_action :voter_only
|
|
skip_before_action :api_check
|
|
respond_to :js, :json, :xml, :html
|
|
rescue_with PostVote::Error, status: 422
|
|
|
|
def index
|
|
@post_votes = PostVote.visible(CurrentUser.user).paginated_search(params, count_pages: true)
|
|
@post_votes = @post_votes.includes(:user, post: :uploader) if request.format.html?
|
|
|
|
respond_with(@post_votes)
|
|
end
|
|
|
|
def create
|
|
@post = Post.find(params[:post_id])
|
|
@post.vote!(params[:score])
|
|
|
|
respond_with(@post)
|
|
end
|
|
|
|
def destroy
|
|
@post = Post.find(params[:post_id])
|
|
@post.unvote!
|
|
|
|
respond_with(@post)
|
|
end
|
|
end
|