Remove `ModerationVote` model, relations and methods

This commit is contained in:
Andreas Nedbal 2022-07-18 22:30:34 +02:00 committed by Karina Kwiatek
parent 3cabd39b89
commit e283648ce0
3 changed files with 0 additions and 36 deletions

View File

@ -1,6 +0,0 @@
class ModerationVote < ApplicationRecord
belongs_to :user
belongs_to :report
validates :user_id, presence: true
validates :report_id, presence: true
end

View File

@ -1,6 +1,5 @@
class Report < ApplicationRecord
belongs_to :user
has_many :moderation_votes, dependent: :destroy
has_many :moderation_comments, dependent: :destroy
validates :type, presence: true
validates :target_id, presence: true
@ -10,10 +9,6 @@ class Report < ApplicationRecord
type.sub('Reports::', '').constantize.where(id: target_id).first
end
def votes
moderation_votes.where(upvote: true).count - moderation_votes.where(upvote: false).count
end
class << self
include CursorPaginatable

View File

@ -36,7 +36,6 @@ class User < ApplicationRecord
has_many :notifications, foreign_key: :recipient_id, dependent: :destroy_async
has_many :reports, dependent: :destroy_async
has_many :moderation_comments, dependent: :destroy_async
has_many :moderation_votes, dependent: :destroy_async
has_many :lists, dependent: :destroy_async
has_many :list_memberships, class_name: "ListMember", dependent: :destroy_async
has_many :mute_rules, dependent: :destroy_async
@ -156,30 +155,6 @@ class User < ApplicationRecord
end
end
# @param upvote [Boolean]
def report_vote(report, upvote = false)
return unless mod?
ModerationVote.create!(user: self, report: report, upvote: upvote)
end
def report_unvote(report)
return unless mod?
ModerationVote.find_by(user: self, report: report).destroy
end
def report_voted?(report)
return false unless mod?
report.moderation_votes.each { |s| return true if s.user_id == self.id }
false
end
# @param upvote [Boolean]
def report_x_voted?(report, upvote)
return false unless mod?
report.moderation_votes.where(upvote: upvote).each { |s| return true if s.user_id == self.id }
false
end
def report_comment(report, content)
ModerationComment.create!(user: self, report: report, content: content)
end