Files
danbooru/app/components/post_votes_tooltip_component.rb
evazion 353e708538 votes: allow admins to remove post votes.
Allow admins to remove votes on posts. This is for fixing vote abuse.

Votes can be removed by going to the vote list on the /post_votes page,
or by clicking on a post's score, then using the "Remove" option in the
"..." dropdown menu next to the vote.

Votes are soft-deleted - they're marked as deleted in the database, but
not fully deleted. Removed votes are only visible to admins, not to
regular users. When a vote is removed by an admin, it leaves a mod
action.

Technically it's possible to undelete votes, but there's no UI for it.
2021-11-23 23:18:54 -06:00

35 lines
862 B
Ruby

# frozen_string_literal: true
# This component represents the tooltip that displays when you hover over a post's score.
class PostVotesTooltipComponent < ApplicationComponent
attr_reader :post, :current_user
delegate :upvote_icon, :downvote_icon, to: :helpers
def initialize(post:, current_user:)
super
@post = post
@current_user = current_user
end
def votes
@post.votes.active.includes(:user).order(id: :desc)
end
def vote_icon(vote)
vote.is_positive? ? upvote_icon : downvote_icon
end
def upvote_ratio
return nil if votes.length == 0
sprintf("(%.1f%%)", 100.0 * post.up_score / (post.up_score + post.down_score.abs))
end
def voter_name(vote)
if policy(vote).can_see_voter?
link_to_user(vote.user, classes: "align-middle")
else
tag.i("hidden", class: "align-middle")
end
end
end