diff --git a/app/controllers/post_votes_controller.rb b/app/controllers/post_votes_controller.rb
index 0331c60ee..f02e1bc4c 100644
--- a/app/controllers/post_votes_controller.rb
+++ b/app/controllers/post_votes_controller.rb
@@ -1,9 +1,14 @@
class PostVotesController < ApplicationController
- before_action :voter_only
+ before_action :voter_only, only: [:create, :destroy]
skip_before_action :api_check
- respond_to :js, :json, :xml
+ respond_to :js, :json, :xml, :html
rescue_with PostVote::Error, status: 422
+ def index
+ @post_votes = PostVote.includes(:post, :user).paginated_search(params)
+ respond_with(@post_votes)
+ end
+
def create
@post = Post.find(params[:post_id])
@post.vote!(params[:score])
diff --git a/app/models/post_vote.rb b/app/models/post_vote.rb
index ffb063940..d5e56c4a8 100644
--- a/app/models/post_vote.rb
+++ b/app/models/post_vote.rb
@@ -23,6 +23,18 @@ class PostVote < ApplicationRecord
select_values_sql("select post_id from post_votes where score > 0 and user_id = ?", user_id)
end
+ def self.visible(user = CurrentUser.user)
+ return all if user.is_admin?
+ where(user: user)
+ end
+
+ def self.search(params)
+ q = super
+ q = q.visible
+ q = q.search_attributes(params, :post, :user, :score)
+ q.apply_default_order(params)
+ end
+
def initialize_attributes
self.user_id ||= CurrentUser.user.id
diff --git a/app/views/comments/partials/index/_header.html.erb b/app/views/comments/partials/index/_header.html.erb
index 735bc541c..d69fff8c1 100644
--- a/app/views/comments/partials/index/_header.html.erb
+++ b/app/views/comments/partials/index/_header.html.erb
@@ -19,7 +19,7 @@
<%= post.score %>
<% if CurrentUser.is_voter? %>
- (vote <%= link_to(content_tag("i", nil, class: "far fa-thumbs-up"), post_votes_path(:score => "up", :post_id => post.id), :remote => true, :method => :post) %>/<%= link_to(content_tag("i", nil, class: "far fa-thumbs-down"), post_votes_path(:score => "down", :post_id => post.id), :remote => true, :method => :post) %>)
+ (vote <%= link_to(content_tag("i", nil, class: "far fa-thumbs-up"), post_post_votes_path(:score => "up", :post_id => post.id), :remote => true, :method => :post) %>/<%= link_to(content_tag("i", nil, class: "far fa-thumbs-down"), post_post_votes_path(:score => "down", :post_id => post.id), :remote => true, :method => :post) %>)
<% end %>
diff --git a/app/views/post_votes/index.html.erb b/app/views/post_votes/index.html.erb
new file mode 100644
index 000000000..db7a7ed5b
--- /dev/null
+++ b/app/views/post_votes/index.html.erb
@@ -0,0 +1,46 @@
+
+
+ <%= search_form_for(post_votes_path) do |f| %>
+ <%= f.input :user_name, label: "User", input_html: { value: params[:search][:user_name], "data-autocomplete": "user" } %>
+ <%= f.input :post_id, label: "Post", input_html: { value: params[:search][:post_id] } %>
+ <%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], "data-autocomplete": "tag-query" } %>
+ <%= f.input :score, collection: [["+3", "3"], ["+1", "1"], ["-1", "-1"], ["-3", "-3"]], include_blank: true, selected: params[:search][:score] %>
+ <%= f.submit "Search" %>
+ <% end %>
+
+
+
+
+ | Post |
+ Tags |
+ Score |
+ Created |
+ |
+
+
+
+ <% @post_votes.each do |vote| %>
+
+ |
+ <%= PostPresenter.preview(vote.post, show_deleted: true) %>
+ |
+
+ <%= TagSetPresenter.new(vote.post.tag_array).inline_tag_list_html %>
+ |
+ <%= link_to sprintf("%+d", vote.score), post_votes_path(search: { score: vote.score }) %> |
+
+ <%= link_to_user vote.user %>
+ <%= link_to "ยป", post_votes_path(search: { user_name: vote.user.name }) %>
+ <%= time_ago_in_words_tagged(vote.created_at) %>
+ |
+
+ <%= link_to "undo", post_post_votes_path(vote.post), remote: true, method: :delete %>
+ |
+
+ <% end %>
+
+
+
+ <%= numbered_paginator(@post_votes) %>
+
+
diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb
index 672710e69..b36643ae4 100644
--- a/app/views/posts/partials/show/_information.html.erb
+++ b/app/views/posts/partials/show/_information.html.erb
@@ -22,11 +22,11 @@
<% if CurrentUser.is_voter? %>
<%= tag.span id: "vote-links-for-post-#{post.id}", style: ("display: none;" if !@post.can_be_voted_by?(CurrentUser.user)) do %>
(vote
- <%= link_to tag.i(class: "far fa-thumbs-up"), post_votes_path(post_id: post.id, score: "up"), remote: true, method: :post %>
- <%= link_to tag.i(class: "far fa-thumbs-down"), post_votes_path(post_id: post.id, score: "down"), remote: true, method: :post %>)
+ <%= link_to tag.i(class: "far fa-thumbs-up"), post_post_votes_path(post_id: post.id, score: "up"), remote: true, method: :post %>
+ <%= link_to tag.i(class: "far fa-thumbs-down"), post_post_votes_path(post_id: post.id, score: "down"), remote: true, method: :post %>)
<% end %>
<%= tag.span id: "unvote-link-for-post-#{post.id}", style: ("display: none;" if @post.can_be_voted_by?(CurrentUser.user)) do %>
- (<%= link_to "undo vote", post_votes_path(post), remote: true, method: :delete, class: "unvote-post-link" %>)
+ (<%= link_to "undo vote", post_post_votes_path(post), remote: true, method: :delete, class: "unvote-post-link" %>)
<% end %>
<% end %>
diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb
index e33c610f5..872ddae27 100644
--- a/app/views/static/site_map.html.erb
+++ b/app/views/static/site_map.html.erb
@@ -9,13 +9,13 @@
<%= link_to("Upload Listing", uploads_path) %>
<%= link_to("Popular", popular_explore_posts_path) %>
<%= link_to("Most Viewed", viewed_explore_posts_path) %>
+ <%= link_to("Votes", post_votes_path) %>
<% if CurrentUser.can_approve_posts? %>
<%= link_to("Moderate", moderator_post_queue_path) %>
<% end %>
<% if CurrentUser.is_moderator? %>
<%= link_to("Mass Edit", edit_moderator_tag_path) %>
<% end %>
- <%= link_to("Similar Images Search", iqdb_queries_path) %>
Post Events
@@ -36,6 +36,7 @@
- <%= link_to("Bookmarklet", bookmarklet_path) %>
- <%= link_to("User Scripts", wiki_pages_path(title: "about:userscripts")) %>
- <%= link_to("API Documentation", wiki_pages_path(:title => "help:api")) %>
+ - <%= link_to("Similar Images Search", iqdb_queries_path) %>
Artists
diff --git a/config/routes.rb b/config/routes.rb
index ebfdee76f..c3d5193e7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -202,14 +202,15 @@ Rails.application.routes.draw do
end
end
resources :post_replacements, :only => [:index, :new, :create, :update]
- resources :posts, :only => [:index, :show, :update] do
+ resources :post_votes, only: [:index]
+ resources :posts, only: [:index, :show, :update] do
resources :events, :only => [:index], :controller => "post_events"
resources :replacements, :only => [:index, :new, :create], :controller => "post_replacements"
resource :artist_commentary, :only => [:index, :show] do
collection { put :create_or_update }
member { put :revert }
end
- resource :votes, :controller => "post_votes", :only => [:create, :destroy]
+ resource :votes, controller: "post_votes", only: [:create, :destroy], as: "post_votes"
collection do
get :random
end
diff --git a/test/factories/post_vote.rb b/test/factories/post_vote.rb
new file mode 100644
index 000000000..8a360bd39
--- /dev/null
+++ b/test/factories/post_vote.rb
@@ -0,0 +1,7 @@
+FactoryBot.define do
+ factory(:post_vote) do
+ user
+ post
+ score { [-1, 1].sample }
+ end
+end
diff --git a/test/functional/post_votes_controller_test.rb b/test/functional/post_votes_controller_test.rb
index 2cd90f8b3..e4d9e7725 100644
--- a/test/functional/post_votes_controller_test.rb
+++ b/test/functional/post_votes_controller_test.rb
@@ -9,9 +9,18 @@ class PostVotesControllerTest < ActionDispatch::IntegrationTest
end
end
+ context "index action" do
+ should "work" do
+ as(@user) { create(:post_vote, post_id: @post.id, user_id: @user.id) }
+ get post_votes_path
+
+ assert_response :success
+ end
+ end
+
context "create action" do
should "not allow anonymous users to vote" do
- post post_votes_path(post_id: @post.id), params: {:score => "up", :format => "js"}
+ post post_post_votes_path(post_id: @post.id), params: {:score => "up", :format => "js"}
assert_response 403
assert_equal(0, @post.reload.score)
end
@@ -19,20 +28,20 @@ class PostVotesControllerTest < ActionDispatch::IntegrationTest
should "not allow banned users to vote" do
@banned = create(:user)
@ban = create(:ban, user: @banned)
- post_auth post_votes_path(post_id: @post.id), @banned, params: {:score => "up", :format => "js"}
+ post_auth post_post_votes_path(post_id: @post.id), @banned, params: {:score => "up", :format => "js"}
assert_response 403
assert_equal(0, @post.reload.score)
end
should "not allow members to vote" do
@member = create(:member_user)
- post_auth post_votes_path(post_id: @post.id), @member, params: {:score => "up", :format => "js"}
+ post_auth post_post_votes_path(post_id: @post.id), @member, params: {:score => "up", :format => "js"}
assert_response 403
assert_equal(0, @post.reload.score)
end
should "increment a post's score if the score is positive" do
- post_auth post_votes_path(post_id: @post.id), @user, params: {:score => "up", :format => "js"}
+ post_auth post_post_votes_path(post_id: @post.id), @user, params: {:score => "up", :format => "js"}
assert_response :success
@post.reload
assert_equal(1, @post.score)
@@ -47,7 +56,7 @@ class PostVotesControllerTest < ActionDispatch::IntegrationTest
should "fail silently on an error" do
assert_nothing_raised do
- post_auth post_votes_path(post_id: @post.id), @user, params: {:score => "up", :format => "js"}
+ post_auth post_post_votes_path(post_id: @post.id), @user, params: {:score => "up", :format => "js"}
end
end
end