pundit: convert post flags to pundit.
This commit is contained in:
@@ -335,27 +335,21 @@ class PostQueryBuilder
|
||||
end
|
||||
end
|
||||
|
||||
if q[:flagger_ids_neg]
|
||||
q[:flagger_ids_neg].each do |flagger_id|
|
||||
if CurrentUser.can_view_flagger?(flagger_id)
|
||||
post_ids = PostFlag.unscoped.search(:creator_id => flagger_id, :category => "normal").reorder("").select {|flag| flag.not_uploaded_by?(CurrentUser.id)}.map {|flag| flag.post_id}.uniq
|
||||
if post_ids.any?
|
||||
relation = relation.where.not("posts.id": post_ids)
|
||||
end
|
||||
end
|
||||
end
|
||||
q[:flaggers_neg].to_a.each do |flagger|
|
||||
flags = PostFlag.unscoped.creator_matches(flagger, CurrentUser.user).where("post_id = posts.id").select("1")
|
||||
relation = relation.where("NOT EXISTS (#{flags.to_sql})")
|
||||
end
|
||||
|
||||
if q[:flagger_ids]
|
||||
q[:flagger_ids].each do |flagger_id|
|
||||
if flagger_id == "any"
|
||||
relation = relation.where('EXISTS (' + PostFlag.unscoped.search(:category => "normal").where('post_id = posts.id').reorder('').select('1').to_sql + ')')
|
||||
elsif flagger_id == "none"
|
||||
relation = relation.where('NOT EXISTS (' + PostFlag.unscoped.search(:category => "normal").where('post_id = posts.id').reorder('').select('1').to_sql + ')')
|
||||
elsif CurrentUser.can_view_flagger?(flagger_id)
|
||||
post_ids = PostFlag.unscoped.search(creator_id: flagger_id, category: "normal").reorder("").select {|flag| flag.not_uploaded_by?(CurrentUser.id)}.map(&:post_id).uniq
|
||||
relation = relation.where("posts.id": post_ids)
|
||||
end
|
||||
q[:flaggers].to_a.each do |flagger|
|
||||
if flagger == "any"
|
||||
flags = PostFlag.unscoped.category_matches("normal").where("post_id = posts.id").select("1")
|
||||
relation = relation.where("EXISTS (#{flags.to_sql})")
|
||||
elsif flagger == "none"
|
||||
flags = PostFlag.unscoped.category_matches("normal").where("post_id = posts.id").select("1")
|
||||
relation = relation.where("NOT EXISTS (#{flags.to_sql})")
|
||||
else
|
||||
flags = PostFlag.unscoped.creator_matches(flagger, CurrentUser.user).where("post_id = posts.id").select("1")
|
||||
relation = relation.where("EXISTS (#{flags.to_sql})")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -738,28 +732,29 @@ class PostQueryBuilder
|
||||
end
|
||||
|
||||
when "flagger"
|
||||
q[:flagger_ids] ||= []
|
||||
|
||||
if g2 == "none"
|
||||
q[:flagger_ids] << "none"
|
||||
q[:flaggers] ||= []
|
||||
q[:flaggers] << "none"
|
||||
elsif g2 == "any"
|
||||
q[:flagger_ids] << "any"
|
||||
q[:flaggers] ||= []
|
||||
q[:flaggers] << "any"
|
||||
else
|
||||
user_id = User.name_to_id(g2)
|
||||
q[:flagger_ids] << user_id unless user_id.blank?
|
||||
user = User.find_by_name(g2)
|
||||
q[:flaggers] ||= []
|
||||
q[:flaggers] << user unless user.blank?
|
||||
end
|
||||
|
||||
when "-flagger"
|
||||
if g2 == "none"
|
||||
q[:flagger_ids] ||= []
|
||||
q[:flagger_ids] << "any"
|
||||
q[:flaggers] ||= []
|
||||
q[:flaggers] << "any"
|
||||
elsif g2 == "any"
|
||||
q[:flagger_ids] ||= []
|
||||
q[:flagger_ids] << "none"
|
||||
q[:flaggers] ||= []
|
||||
q[:flaggers] << "none"
|
||||
else
|
||||
q[:flagger_ids_neg] ||= []
|
||||
user_id = User.name_to_id(g2)
|
||||
q[:flagger_ids_neg] << user_id unless user_id.blank?
|
||||
user = User.find_by_name(g2)
|
||||
q[:flaggers_neg] ||= []
|
||||
q[:flaggers_neg] << user unless user.blank?
|
||||
end
|
||||
|
||||
when "appealer"
|
||||
|
||||
Reference in New Issue
Block a user