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

Spam topic removal #7

Open
wants to merge 10 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
5 changes: 5 additions & 0 deletions app/assets/stylesheets/simple_discussion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions app/controllers/simple_discussion/forum_threads_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/views/layouts/simple_discussion.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
<%= t('.unanswered') %>
</div>
<% end %>

<% if is_moderator? %>
<%= forum_link_to simple_discussion.spam_forum_threads_path do %>
<div class="btn-link">
<%= icon "fas", "exclamation-circle" %>
<%= t('.spam') %>
</div>
<% end %>
<% end %>
</div>
<% if @forum_thread.present? && @forum_thread.persisted? %>
<div class="mt-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<div class="category-chip" style="color: <%= forum_thread.forum_category.color %>; border-color: <%= forum_thread.forum_category.color %>">
<%= forum_thread.forum_category.name %>
</div>
<div class="spam">
<% if forum_thread.spam? %>
<span class="badge badge-warning">Marked as Spam</span>
<% end %>
</div>
</div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions app/views/simple_discussion/forum_threads/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<div class="category-chip mx-3" style="color: <%= @forum_thread.forum_category.color %>; border-color: <%= @forum_thread.forum_category.color %>">
<%= @forum_thread.forum_category.name %>
</div>
<% 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 %>
</div>

<%= render partial: "simple_discussion/forum_posts/forum_post", collection: @forum_thread.forum_posts.includes(:user).sorted %>
Expand Down
8 changes: 8 additions & 0 deletions app/views/simple_discussion/forum_threads/spam.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h2>Spam Threads</h2>
<% if @spam_threads.present? %>
<% @spam_threads.each do |spam_thread| %>
<%= render partial: "forum_thread", locals: { forum_thread: spam_thread } %>
<% end %>
<% else %>
<p>No spammed threads found.</p>
<% end %>
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down