users: replace scopes with associations.
This commit is contained in:
@@ -52,15 +52,12 @@ class PostFlag < ApplicationRecord
|
||||
where("created_at <= ?", 3.days.ago)
|
||||
end
|
||||
|
||||
def for_creator(user_id)
|
||||
where("creator_id = ?", user_id)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
q = q.attribute_matches(:reason, params[:reason_matches])
|
||||
|
||||
# XXX
|
||||
if params[:creator_id].present?
|
||||
if CurrentUser.can_view_flagger?(params[:creator_id].to_i)
|
||||
q = q.where.not(post_id: CurrentUser.user.posts)
|
||||
@@ -70,6 +67,7 @@ class PostFlag < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
# XXX
|
||||
if params[:creator_name].present?
|
||||
flagger_id = User.name_to_id(params[:creator_name].strip)
|
||||
if flagger_id && CurrentUser.can_view_flagger?(flagger_id)
|
||||
@@ -150,7 +148,7 @@ class PostFlag < ApplicationRecord
|
||||
errors[:creator] << "cannot flag posts"
|
||||
end
|
||||
|
||||
if creator_id != User.system.id && PostFlag.for_creator(creator_id).where("created_at > ?", 30.days.ago).count >= CREATION_THRESHOLD
|
||||
if creator_id != User.system.id && creator.post_flags.where("created_at > ?", 30.days.ago).count >= CREATION_THRESHOLD
|
||||
report = Reports::PostFlags.new(user_id: post.uploader_id, date_range: 90.days.ago)
|
||||
|
||||
if report.attackers.include?(creator_id)
|
||||
@@ -185,7 +183,7 @@ class PostFlag < ApplicationRecord
|
||||
end
|
||||
|
||||
def flag_count_for_creator
|
||||
PostFlag.where(:creator_id => creator_id).recent.count
|
||||
creator.post_flags.recent.count
|
||||
end
|
||||
|
||||
def uploader_id
|
||||
|
||||
Reference in New Issue
Block a user