flags: fix mods not being able to see the flagger on self-flagged posts.

Fix a bug where, when a mod searched for their own flags, they couldn't
see their own self-flagged uploads.

Fix a bug where, when a mod viewed their own flags, they couldn't see
the flagger name for their own self-flagged uploads.

This also makes it so you can do things like `/post_flags?search[creator][level]=20`
to search flags by user level.
This commit is contained in:
evazion
2022-09-21 16:22:42 -05:00
parent a35f49e905
commit a6e0872ce4
3 changed files with 31 additions and 11 deletions

View File

@@ -59,17 +59,9 @@ class PostFlag < ApplicationRecord
end
def search(params)
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :status, :post)
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :status, :post, :creator)
q = q.text_attribute_matches(:reason, params[:reason_matches])
if params[:creator_id].present?
flagger = User.find(params[:creator_id])
q = q.creator_matches(flagger, CurrentUser.user)
elsif params[:creator_name].present?
flagger = User.find_by_name(params[:creator_name])
q = q.creator_matches(flagger, CurrentUser.user)
end
if params[:category]
q = q.category_matches(params[:category])
end