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

Reporting posts #3

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion app/controllers/thredded/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PostsController < Thredded::ApplicationController
include Thredded::NewPostParams

helper_method :topic
before_action :assign_messageboard_for_actions, only: %i[mark_as_read mark_as_unread]
before_action :assign_messageboard_for_actions, only: %i[mark_as_read mark_as_unread report]
after_action :update_user_activity

after_action :verify_authorized
Expand Down Expand Up @@ -77,6 +77,18 @@ def quote
render plain: Thredded::ContentFormatter.quote_content(post.content)
end

def report
authorize_reading post
post.update(moderation_state: 'pending_moderation')
respond_to do |format|
format.html do
redirect_back fallback_location: post_path(post, user: thredded_current_user),
notice: I18n.t('thredded.posts.reported_post')
end
format.json { render(json: { reported: true }) }
end
end

private

def canonical_topic_params
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/thredded/post_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ module PostCommon
SELECT MAX(p2.created_at) from #{posts_table_name} p2 WHERE p2.postable_id = #{posts_table_name}.postable_id)
SQL
)

# When we can't load a preloader, return the results as-is
return result if preloader.empty?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not yet sure what the preloaders are for or why we can no longer find them when a post has been reported. This is a hack that needs addressed.


preloader[0].preloaded_records.each do |post|
topic = owners_by_id.delete(post.postable_id)
next unless topic
Expand Down
5 changes: 5 additions & 0 deletions app/policies/thredded/post_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def destroy?
[email protected]_post_in_topic? && update?
end

def report?
# Only allow logged-in users to report posts
!(@user.is_a? Thredded::NullUser)
end

def anonymous?
@user.thredded_anonymous?
end
Expand Down
8 changes: 8 additions & 0 deletions app/view_models/thredded/post_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def can_moderate?
@can_moderate ||= @policy.moderate?
end

def can_report?
@can_report ||= [email protected](:report?)
end

def quote_url_params
if @post.private_topic_post?
{ post: { quote_private_post_id: @post.id } }
Expand All @@ -66,6 +70,10 @@ def mark_unread_path
Thredded::UrlsHelper.mark_unread_path(@post)
end

def report_path
Thredded::UrlsHelper.report_post_path(@post)
end

def destroy_path
Thredded::UrlsHelper.delete_post_path(@post)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
time_ago: time_ago(record.created_at)
}
%>
<article id="<%= dom_id(post) %>" class="thredded--post-moderation-record thredded--post-moderation-record-<%= record.moderation_state %>">
<article id="<%= post.nil? ? nil : dom_id(post) %>" class="thredded--post-moderation-record thredded--post-moderation-record-<%= record.moderation_state %>">
<header class="thredded--post-moderation-record--header">
<p class="thredded--post-moderation-record--moderation-state-notice">
<% if record.approved? %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/thredded/posts_common/_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
<% if post.can_destroy? %>
<%= render 'thredded/posts_common/actions/delete', post: post %>
<% end %>
<% if post.can_report? %>
<%= render 'thredded/posts_common/actions/report', post: post %>
<% end %>
<% if post.read_state %>
<%= view_hooks.post_common.mark_as_unread.render self, post: post do %>
<%= render 'thredded/posts_common/actions/mark_as_unread', post: post %>
<% end %>
<% end %>
<% if user_signed_in? && current_user.forum_moderator? && post.instance_variable_get(:@post).is_a?(Thredded::Post) %>
<%= render 'thredded/moderation/post_moderation_actions', post: post %>
<% end %>
<% end %>
<% end %>

Expand Down
5 changes: 5 additions & 0 deletions app/views/thredded/posts_common/actions/_flag.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= button_to t('thredded.posts.flag'), post.flag_path,
method: :post,
class: 'thredded--post--report thredded--post--dropdown--actions--item',
data: { confirm: I18n.t('thredded.posts.flag_confirm') }
%>
5 changes: 5 additions & 0 deletions app/views/thredded/posts_common/actions/_report.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= button_to t('thredded.posts.report'), post.report_path,
method: :post,
class: 'thredded--post--report thredded--post--dropdown--actions--item',
data: { confirm: I18n.t('thredded.posts.report_confirm') }
%>
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ en:
delete_confirm: Are you sure you want to delete this post?
deleted_notice: Your post has been deleted.
edit: :thredded.nav.edit_post
flag: Flag Post as Spam
flag_confirm: Are you sure you want to flag this post as spam?
form:
content_label: Content
create_btn: Submit Reply
Expand All @@ -145,6 +147,9 @@ en:
update_btn_submitting: :thredded.form.update_btn_submitting
pending_moderation_notice: Your post will be published when it has been reviewed by a moderator.
quote_btn: Quote
report: Report Post
report_confirm: Are you sure you want to report this post?
reported_post: This post has been reported to moderation for review.
spoiler_summary: Spoiler - click to show.
spoiler_summary_for_email: 'Spoiler - select the contents below to see:'
preferences:
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@
member do
post 'mark_as_read'
post 'mark_as_unread'
post 'report'
end
end

resources :private_posts, only: %i[] do
member do
post 'mark_as_read'
post 'mark_as_unread'
post 'report'
end
end
end
Expand Down