votes: make upvotes visible to everyone by default.
Make upvotes public the same way favorites are public: * Rename the "Private favorites" account setting to "Private favorites and upvotes". * Make upvotes public, unless the user has private upvotes enabled. Note that private upvotes are still visible to admins. Downvotes are still hidden to everyone except for admins. * Make https://danbooru.donmai.us/post_votes visible to all users. This page shows all public upvotes. Private upvotes and downvotes are only visible on the page to admins and to the voter themselves. * Make votes searchable with the `upvote:username` and `downvote:username` metatags. These already existed before, but they were only usable by admins and by people searching for their own votes. Upvotes are public to discourage users from upvoting with multiple accounts. Upvote abuse is obvious to everyone when upvotes are public. The other reason is to make upvotes consistent with favorites, which are already public.
This commit is contained in:
@@ -9,59 +9,157 @@ class PostVotesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
@admin = create(:admin_user)
|
||||
as(@user) { @post_vote = create(:post_vote, post: @post, user: @user) }
|
||||
as(@admin) { @admin_vote = create(:post_vote, post: @post, user: @admin) }
|
||||
@unrelated_vote = create(:post_vote)
|
||||
@user = create(:user, enable_private_favorites: true)
|
||||
create(:post_vote, user: @user, score: 1)
|
||||
create(:post_vote, user: @user, score: -1)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get_auth post_votes_path, @user
|
||||
get post_votes_path
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "as a user" do
|
||||
setup do
|
||||
CurrentUser.user = @user
|
||||
should "show the user all their own votes" do
|
||||
get_auth post_votes_path, @user
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 2
|
||||
|
||||
get_auth post_votes_path(search: { user_id: @user.id }), @user
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 2
|
||||
|
||||
get_auth post_votes_path(search: { user_name: @user.name }), @user
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 2
|
||||
end
|
||||
|
||||
should respond_to_search({}).with { @post_vote }
|
||||
should "not show private upvotes to other users" do
|
||||
get_auth post_votes_path, create(:user)
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 0
|
||||
|
||||
get_auth post_votes_path(search: { user_id: @user.id }), create(:user)
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 0
|
||||
|
||||
get_auth post_votes_path(search: { user_name: @user.name }), create(:user)
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 0
|
||||
end
|
||||
|
||||
should "not show downvotes to other users" do
|
||||
@user.update!(enable_private_favorites: false)
|
||||
|
||||
get_auth post_votes_path, create(:user)
|
||||
assert_response :success
|
||||
assert_select "tbody tr[data-score=1]", 1
|
||||
assert_select "tbody tr[data-score=-1]", 0
|
||||
|
||||
get_auth post_votes_path(search: { user_id: @user.id }), create(:user)
|
||||
assert_response :success
|
||||
assert_select "tbody tr[data-score=1]", 1
|
||||
assert_select "tbody tr[data-score=-1]", 0
|
||||
|
||||
get_auth post_votes_path(search: { user_name: @user.name }), create(:user)
|
||||
assert_response :success
|
||||
assert_select "tbody tr[data-score=1]", 1
|
||||
assert_select "tbody tr[data-score=-1]", 0
|
||||
end
|
||||
end
|
||||
|
||||
context "as a moderator" do
|
||||
setup do
|
||||
CurrentUser.user = @admin
|
||||
end
|
||||
context "as an admin" do
|
||||
should "show all votes by other users" do
|
||||
@admin = create(:admin_user)
|
||||
|
||||
should respond_to_search({}).with { [@unrelated_vote, @admin_vote, @post_vote] }
|
||||
should respond_to_search(score: 1).with { [@unrelated_vote, @admin_vote, @post_vote].select{ |v| v.score == 1 } }
|
||||
get_auth post_votes_path, @admin
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 2
|
||||
|
||||
context "using includes" do
|
||||
should respond_to_search(post_tags_match: "dragon").with { [@admin_vote, @post_vote] }
|
||||
should respond_to_search(user_name: "meiling").with { @post_vote }
|
||||
should respond_to_search(user: {level: User::Levels::ADMIN}).with { @admin_vote }
|
||||
get_auth post_votes_path(search: { user_id: @user.id }), @admin
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 2
|
||||
|
||||
get_auth post_votes_path(search: { user_name: @user.name }), @admin
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 2
|
||||
|
||||
get_auth post_votes_path(search: { user: { level: @user.level }}), @admin
|
||||
assert_response :success
|
||||
assert_select "tbody tr", 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
setup do
|
||||
@post_vote = create(:post_vote, post: @post, user: @user)
|
||||
context "for a public upvote" do
|
||||
setup do
|
||||
@user = create(:user, enable_private_favorites: false)
|
||||
@post_vote = create(:post_vote, user: @user, score: 1)
|
||||
end
|
||||
|
||||
should "show the voter to everyone" do
|
||||
get post_vote_path(@post_vote), as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_equal(@user.id, response.parsed_body["user_id"])
|
||||
end
|
||||
end
|
||||
|
||||
should "show the vote to the voter" do
|
||||
get_auth post_vote_path(@post_vote), @user, as: :json
|
||||
assert_response :success
|
||||
context "for a private upvote" do
|
||||
setup do
|
||||
@user = create(:user, enable_private_favorites: true)
|
||||
@post_vote = create(:post_vote, user: @user, score: 1)
|
||||
end
|
||||
|
||||
should "show the voter to themselves" do
|
||||
get_auth post_vote_path(@post_vote), @user, as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_equal(@user.id, response.parsed_body["user_id"])
|
||||
end
|
||||
|
||||
should "show the voter to admins" do
|
||||
get_auth post_vote_path(@post_vote), create(:admin_user), as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_equal(@user.id, response.parsed_body["user_id"])
|
||||
end
|
||||
|
||||
should "not show the voter to other users" do
|
||||
get post_vote_path(@post_vote), as: :json
|
||||
|
||||
assert_response 403
|
||||
assert_nil(response.parsed_body["user_id"])
|
||||
end
|
||||
end
|
||||
|
||||
should "show the vote to admins" do
|
||||
get_auth post_vote_path(@post_vote), create(:admin_user), as: :json
|
||||
assert_response :success
|
||||
end
|
||||
context "for a downvote" do
|
||||
setup do
|
||||
@user = create(:user, enable_private_favorites: false)
|
||||
@post_vote = create(:post_vote, user: @user, score: -1)
|
||||
end
|
||||
|
||||
should "not show the vote to other users" do
|
||||
get_auth post_vote_path(@post_vote), create(:user), as: :json
|
||||
assert_response 403
|
||||
should "show the voter to themselves" do
|
||||
get_auth post_vote_path(@post_vote), @user, as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_equal(@user.id, response.parsed_body["user_id"])
|
||||
end
|
||||
|
||||
should "show the voter to admins" do
|
||||
get_auth post_vote_path(@post_vote), create(:admin_user), as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_equal(@user.id, response.parsed_body["user_id"])
|
||||
end
|
||||
|
||||
should "not show the voter to other users" do
|
||||
get post_vote_path(@post_vote), as: :json
|
||||
|
||||
assert_response 403
|
||||
assert_nil(response.parsed_body["user_id"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user