diff --git a/app/controllers/simple_discussion/application_controller.rb b/app/controllers/simple_discussion/application_controller.rb index 0d041f7..7ed17df 100644 --- a/app/controllers/simple_discussion/application_controller.rb +++ b/app/controllers/simple_discussion/application_controller.rb @@ -29,6 +29,12 @@ def require_mod_or_author_for_thread! end end + def require_mod! + unless is_moderator? + redirect_to_root + end + end + private def redirect_to_root diff --git a/app/controllers/simple_discussion/forum_posts_controller.rb b/app/controllers/simple_discussion/forum_posts_controller.rb index 06662ed..a797a26 100644 --- a/app/controllers/simple_discussion/forum_posts_controller.rb +++ b/app/controllers/simple_discussion/forum_posts_controller.rb @@ -29,8 +29,22 @@ def update end def destroy - @forum_post.destroy! - redirect_to simple_discussion.forum_thread_path(@forum_thread) + # if @forum_post is first post of forum_thread then we need to destroy forum_thread + if @forum_thread.forum_posts.first == @forum_post + @forum_thread.destroy! + if params[:from] == "moderators_page" + redirect_to simple_discussion.spam_reports_forum_threads_path + else + redirect_to simple_discussion.root_path + end + else + @forum_post.destroy! + if params[:from] == "moderators_page" + redirect_to simple_discussion.spam_reports_forum_threads_path + else + redirect_to simple_discussion.forum_thread_path(@forum_thread) + end + end end def solved diff --git a/app/controllers/simple_discussion/forum_threads_controller.rb b/app/controllers/simple_discussion/forum_threads_controller.rb index cdc1fce..ce1f0dc 100644 --- a/app/controllers/simple_discussion/forum_threads_controller.rb +++ b/app/controllers/simple_discussion/forum_threads_controller.rb @@ -2,6 +2,7 @@ class SimpleDiscussion::ForumThreadsController < SimpleDiscussion::ApplicationCo before_action :authenticate_user!, only: [:mine, :participating, :new, :create] before_action :set_forum_thread, only: [:show, :edit, :update, :destroy] before_action :require_mod_or_author_for_thread!, only: [:edit, :update, :destroy] + before_action :require_mod!, only: [:spam_reports] def index @forum_threads = ForumThread.pinned_first.sorted.includes(:user, :forum_category).paginate(page: page_number) @@ -27,6 +28,11 @@ def participating render action: :index end + def spam_reports + @spam_reports = SpamReport.includes(:forum_post).paginate(page: page_number) + render action: :spam_reports + end + def show @forum_post = ForumPost.new @forum_post.user = current_user diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 8be9045..46efe03 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -1,7 +1,7 @@ class ForumPost < ApplicationRecord belongs_to :forum_thread, counter_cache: true, touch: true belongs_to :user - has_many :spam_posts, dependent: :destroy + has_many :spam_reports, dependent: :destroy validate :clean_body validates :user_id, :body, presence: true diff --git a/app/models/spam_report.rb b/app/models/spam_report.rb index 3347a49..cf9bbd5 100644 --- a/app/models/spam_report.rb +++ b/app/models/spam_report.rb @@ -11,5 +11,5 @@ class SpamReport < ApplicationRecord irrelevant_content: 2, misleading_content: 3, others: 4 -} + } end diff --git a/app/views/layouts/simple_discussion.html.erb b/app/views/layouts/simple_discussion.html.erb index 886791d..f66a978 100644 --- a/app/views/layouts/simple_discussion.html.erb +++ b/app/views/layouts/simple_discussion.html.erb @@ -41,6 +41,14 @@ <%= t('.unanswered') %> <% end %> + <% if is_moderator? %> + <%= forum_link_to simple_discussion.spam_reports_forum_threads_path do %> +
+ <%= spam_report.forum_post.user.name %> <%= forum_user_badge(spam_report.forum_post.user) %> +
+<%= t('on') %> <%= spam_report.forum_post.created_at.strftime("%b %d, %Y") %>
+Forum Post | +Reason | +Reported by | +View in Thread | +Delete | +
---|