diff --git a/app/controllers/forum_post_votes_controller.rb b/app/controllers/forum_post_votes_controller.rb index 150a73608..12e386b86 100644 --- a/app/controllers/forum_post_votes_controller.rb +++ b/app/controllers/forum_post_votes_controller.rb @@ -3,14 +3,14 @@ class ForumPostVotesController < ApplicationController before_action :member_only, only: [:create, :destroy] def index - @forum_post_votes = ForumPostVote.paginated_search(params, count_pages: true) + @forum_post_votes = ForumPostVote.visible.paginated_search(params, count_pages: true) @forum_post_votes = @forum_post_votes.includes(:creator, forum_post: [:creator, :topic]) if request.format.html? respond_with(@forum_post_votes) end def create - @forum_post = ForumPost.find(params[:forum_post_id]) + @forum_post = ForumPost.permitted.find(params[:forum_post_id]) @forum_post_vote = @forum_post.votes.create(forum_post_vote_params.merge(creator: CurrentUser.user)) respond_with(@forum_post_vote) end diff --git a/app/models/forum_post_vote.rb b/app/models/forum_post_vote.rb index 886de7900..0540d41ab 100644 --- a/app/models/forum_post_vote.rb +++ b/app/models/forum_post_vote.rb @@ -3,10 +3,12 @@ class ForumPostVote < ApplicationRecord belongs_to :forum_post validates :creator_id, uniqueness: {scope: :forum_post_id} validates :score, inclusion: {in: [-1, 0, 1]} + scope :up, -> {where(score: 1)} scope :down, -> {where(score: -1)} scope :by, ->(user_id) {where(creator_id: user_id)} scope :excluding_user, ->(user_id) {where("creator_id <> ?", user_id)} + scope :visible, -> { where(forum_post: ForumPost.permitted) } def self.forum_post_matches(params) return all if params.blank?