post votes: fix exception when voting on posts using API.
Fix an `undefined method post_vote_url` exception when doing `POST https://danbooru.donmai.us/posts/1/votes.json`. Also add the following API endpoints: * https://danbooru.donmai.us/post_votes/:id.json * https://danbooru.donmai.us/comment_votes/:id.json * https://danbooru.donmai.us/forum_post_votes/:id.json where `:id` is the vote ID, not the post ID.
This commit is contained in:
@@ -8,6 +8,11 @@ class CommentVotesController < ApplicationController
|
||||
respond_with(@comment_votes)
|
||||
end
|
||||
|
||||
def show
|
||||
@comment_vote = authorize CommentVote.find(params[:id])
|
||||
respond_with(@comment_vote)
|
||||
end
|
||||
|
||||
def create
|
||||
@comment = Comment.find(params[:comment_id])
|
||||
|
||||
|
||||
@@ -8,6 +8,11 @@ class ForumPostVotesController < ApplicationController
|
||||
respond_with(@forum_post_votes)
|
||||
end
|
||||
|
||||
def show
|
||||
@forum_post_vote = authorize ForumPostVote.find(params[:id])
|
||||
respond_with(@forum_post_vote)
|
||||
end
|
||||
|
||||
def create
|
||||
@forum_post = ForumPost.find(params[:forum_post_id])
|
||||
@forum_post_vote = authorize ForumPostVote.new(creator: CurrentUser.user, forum_post: @forum_post, **permitted_attributes(ForumPostVote))
|
||||
|
||||
@@ -8,6 +8,11 @@ class PostVotesController < ApplicationController
|
||||
respond_with(@post_votes)
|
||||
end
|
||||
|
||||
def show
|
||||
@post_vote = authorize PostVote.find(params[:id])
|
||||
respond_with(@post_vote)
|
||||
end
|
||||
|
||||
def create
|
||||
@post = Post.find(params[:post_id])
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ class CommentVotePolicy < ApplicationPolicy
|
||||
!record.is_deleted? && (record.user_id == user.id || user.is_admin?)
|
||||
end
|
||||
|
||||
def show?
|
||||
can_see_votes? || record.user == user
|
||||
end
|
||||
|
||||
def can_see_votes?
|
||||
user.is_moderator?
|
||||
end
|
||||
|
||||
@@ -6,4 +6,8 @@ class PostVotePolicy < ApplicationPolicy
|
||||
def destroy?
|
||||
unbanned? && record.user == user
|
||||
end
|
||||
|
||||
def show?
|
||||
user.is_admin? || record.user == user
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user