diff --git a/app/models/post.rb b/app/models/post.rb index 436e84812..4a1d1ba99 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -202,6 +202,14 @@ def locked? false end + # The test here is for flags that are pending (no status). A spam flag + # could be marked helpful but the post wouldn't be deleted, and + # we don't necessarily want the post to be treated like it's a spam risk + # if that happens. + def spam_flag_pending? + flags.any? { |flag| flag.post_flag_type&.name == "it's spam" && !flag.status } + end + # @param user [User, Nil] # @return [Boolean] whether the given user can view this post def can_access?(user) diff --git a/app/views/posts/_expanded.html.erb b/app/views/posts/_expanded.html.erb index 4a4258d60..5f28e9d23 100644 --- a/app/views/posts/_expanded.html.erb +++ b/app/views/posts/_expanded.html.erb @@ -145,8 +145,17 @@ on <%= post.locked_at.strftime('%b %e, %Y at %H:%M') %>.

- <% end %> + <% end %> + <% if post.spam_flag_pending? && user_signed_in? %> +
+ <% if post.user == current_user %> +

Your post has been flagged by members of our community. Please review our guidelines for promotional content.

+ <% else %> +

Possible spam: this post has pending flags for spam. Be careful when following links.

+ <% end %> +
+ <% end %> <% if post_type.is_public_editable && post.pending_suggested_edit? %> <% if check_your_post_privilege(post, 'edit_posts') %>
@@ -163,10 +172,15 @@ <%= link_to 'pending review', suggested_edit_url(post.pending_suggested_edit.id) %>.

<% end %> - <% end %> + <% end %> -
- <%= raw(sanitize(post.body, scrubber: scrubber)) %> +
+ <% effective_post = raw(sanitize(post.body, scrubber: scrubber)) %> + <% if post.spam_flag_pending? && !user_signed_in? %> + <%= sanitize(effective_post, attributes: %w()) %> + <% else %> + <%= effective_post %> + <% end %> <% been_edited = post.last_edited_by_id != nil %> <% if been_edited then last_edited_by_self = post.user_id == post.last_edited_by_id end %>