diff --git a/app/assets/stylesheets/simple_discussion.scss b/app/assets/stylesheets/simple_discussion.scss index 606f3ff..520e6da 100644 --- a/app/assets/stylesheets/simple_discussion.scss +++ b/app/assets/stylesheets/simple_discussion.scss @@ -95,6 +95,11 @@ border-style: solid; } +.spam{ + font-size: 18px; + margin-left: 10px; +} + // Solved tag for threads .simple_discussion .solved-tag { font-weight: 500; diff --git a/app/controllers/simple_discussion/forum_threads_controller.rb b/app/controllers/simple_discussion/forum_threads_controller.rb index d7e5bf0..faee6b3 100644 --- a/app/controllers/simple_discussion/forum_threads_controller.rb +++ b/app/controllers/simple_discussion/forum_threads_controller.rb @@ -1,6 +1,6 @@ class SimpleDiscussion::ForumThreadsController < SimpleDiscussion::ApplicationController - before_action :authenticate_user!, only: [:mine, :participating, :new, :create] - before_action :set_forum_thread, only: [:show, :edit, :update] + before_action :authenticate_user!, only: [:mine, :participating, :new, :create, :mark_as_spam, :unmark_as_spam] + before_action :set_forum_thread, only: [:show, :edit, :update, :mark_as_spam, :unmark_as_spam] before_action :require_mod_or_author_for_thread!, only: [:edit, :update] def index @@ -27,6 +27,22 @@ def participating render action: :index end + def spam + @spam_threads = ForumThread.where(spam: true).sorted.includes(:user, :forum_category).paginate(page: page_number) + end + + def mark_as_spam + @forum_thread.update(spam: true) + flash[:notice] = 'Thread was successfully marked as spam.' + redirect_to simple_discussion.forum_thread_path(@forum_thread) + end + + def unmark_as_spam + @forum_thread.update(spam: false) + flash[:notice] = 'Thread was successfully unmarked as spam.' + redirect_to simple_discussion.forum_thread_path(@forum_thread) + end + def show @forum_post = ForumPost.new @forum_post.user = current_user diff --git a/app/views/layouts/simple_discussion.html.erb b/app/views/layouts/simple_discussion.html.erb index ed9dedb..b9c75b7 100644 --- a/app/views/layouts/simple_discussion.html.erb +++ b/app/views/layouts/simple_discussion.html.erb @@ -41,6 +41,15 @@ <%= t('.unanswered') %> <% end %> + + <% if is_moderator? %> + <%= forum_link_to simple_discussion.spam_forum_threads_path do %> + + <% end %> + <% end %> <% if @forum_thread.present? && @forum_thread.persisted? %>
diff --git a/app/views/simple_discussion/forum_threads/_forum_thread.html.erb b/app/views/simple_discussion/forum_threads/_forum_thread.html.erb index bbd64e9..54bfa2a 100644 --- a/app/views/simple_discussion/forum_threads/_forum_thread.html.erb +++ b/app/views/simple_discussion/forum_threads/_forum_thread.html.erb @@ -37,6 +37,11 @@
<%= forum_thread.forum_category.name %>
+
+ <% if forum_thread.spam? %> + Marked as Spam + <% end %> +
diff --git a/app/views/simple_discussion/forum_threads/show.html.erb b/app/views/simple_discussion/forum_threads/show.html.erb index eb73340..cd0438a 100644 --- a/app/views/simple_discussion/forum_threads/show.html.erb +++ b/app/views/simple_discussion/forum_threads/show.html.erb @@ -11,6 +11,11 @@
<%= @forum_thread.forum_category.name %>
+ <% if @forum_thread.spam? %> + <%= link_to 'Unmark as Spam', simple_discussion.unmark_as_spam_forum_thread_path(@forum_thread), method: :put, class: "btn btn-warning ml-auto", data: { confirm: 'Are you sure you want to unmark this thread as spam?' } %> + <% else %> + <%= link_to 'Mark as Spam', simple_discussion.mark_as_spam_forum_thread_path(@forum_thread), method: :put, class: "btn btn-danger ml-auto", data: { confirm: 'Are you sure you want to mark this thread as spam?' } %> + <% end %> <%= render partial: "simple_discussion/forum_posts/forum_post", collection: @forum_thread.forum_posts.includes(:user).sorted %> diff --git a/app/views/simple_discussion/forum_threads/spam.html.erb b/app/views/simple_discussion/forum_threads/spam.html.erb new file mode 100644 index 0000000..0fd8b9e --- /dev/null +++ b/app/views/simple_discussion/forum_threads/spam.html.erb @@ -0,0 +1,8 @@ +

Spam Threads

+<% if @spam_threads.present? %> + <% @spam_threads.each do |spam_thread| %> + <%= render partial: "forum_thread", locals: { forum_thread: spam_thread } %> + <% end %> +<% else %> +

No spammed threads found.

+<% end %> diff --git a/config/routes.rb b/config/routes.rb index b490da3..a83639b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,10 +5,16 @@ get :answered get :unanswered get :mine + get :spam get :participating get "category/:id", to: "forum_categories#index", as: :forum_category end + member do + put :mark_as_spam + put :unmark_as_spam + end + resources :forum_posts, path: :posts do member do put :solved