Fix #5317: Don't allow users to flag posts they can't see.

A couple non-obvious consequences:

* Users can't flag non-rating:G posts in safe mode.
* Non-Gold users can flag Gold-only posts if they're the uploader.
This commit is contained in:
evazion
2022-12-02 14:44:24 -06:00
parent e11cd288b9
commit 25978ca754
2 changed files with 11 additions and 0 deletions

View File

@@ -87,6 +87,7 @@ class PostFlag < ApplicationRecord
errors.add(:post, "is pending and cannot be flagged") if post.is_pending? && !is_deletion
errors.add(:post, "is deleted and cannot be flagged") if post.is_deleted? && creator != User.system # DanbooruBot is allowed to prune expired appeals
errors.add(:post, "is already flagged") if post.is_flagged? && !is_deletion
errors.add(:post, "cannot be flagged") if !post.visible?(creator)
flag = post.flags.in_cooldown.last
if !is_deletion && !creator.is_approver? && flag.present?