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:
@@ -14,7 +14,7 @@ class PostFlagPolicy < ApplicationPolicy
|
||||
end
|
||||
|
||||
def can_view_flagger?
|
||||
(user.is_moderator? || record.creator_id == user.id) && (record.post&.uploader_id != user.id)
|
||||
record.creator_id == user.id || (user.is_moderator? && record.post&.uploader_id != user.id)
|
||||
end
|
||||
|
||||
def permitted_attributes_for_create
|
||||
@@ -30,4 +30,15 @@ class PostFlagPolicy < ApplicationPolicy
|
||||
attributes -= [:creator_id] unless can_view_flagger?
|
||||
attributes
|
||||
end
|
||||
|
||||
def visible_for_search(relation, attribute)
|
||||
case attribute
|
||||
in :creator | :creator_id if can_search_flagger?
|
||||
relation.where(creator: user).or(relation.where.not(post: user.posts))
|
||||
in :creator | :creator_id
|
||||
relation.where(creator: user)
|
||||
else
|
||||
relation
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user