pundit: convert post votes to pundit.

Side effects:

* The data-current-user-is-voter <body> attribute has been removed.
* {{upvote:self}} no longer works. {{upvote:<name>}} should be used instead.
This commit is contained in:
evazion
2020-03-19 22:55:28 -05:00
parent 33d81d0d1b
commit 415d9591c5
9 changed files with 46 additions and 42 deletions

View File

@@ -1,25 +1,24 @@
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 = authorize 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 = authorize Post.find(params[:post_id]), policy_class: PostVotePolicy
@post.vote!(params[:score])
respond_with(@post)
end
def destroy
@post = Post.find(params[:post_id])
@post = authorize Post.find(params[:post_id]), policy_class: PostVotePolicy
@post.unvote!
respond_with(@post)