Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guardrails for posts with pending spam flags #1520

Merged
merged 3 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 18 additions & 4 deletions app/views/posts/_expanded.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,17 @@
on <%= post.locked_at.strftime('%b %e, %Y at %H:%M') %>.
</p>
</div>
<% end %>
<% end %>

<% if post.spam_flag_pending? && user_signed_in? %>
<div class="notice has-margin-2">
<% if post.user == current_user %>
<p>Your post has been flagged by members of our community. Please review our <a href="/help/spam">guidelines for promotional content</a>.</p>
<% else %>
<p><strong>Possible spam:</strong> this post has pending flags for spam. Be careful when following links.</p>
<% end %>
</div>
<% end %>
<% if post_type.is_public_editable && post.pending_suggested_edit? %>
<% if check_your_post_privilege(post, 'edit_posts') %>
<div class="notice h-p-2">
Expand All @@ -163,10 +172,15 @@
<%= link_to 'pending review', suggested_edit_url(post.pending_suggested_edit.id) %></strong>.</p>
</div>
<% end %>
<% end %>
<% end %>

<div class="post--body">
<%= raw(sanitize(post.body, scrubber: scrubber)) %>
<div class="post--body">
<% 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 %>
Expand Down
Loading