Skip to content

Commit

Permalink
Added link to hide topics on topics/show for admins. Also fix bug whe…
Browse files Browse the repository at this point in the history
…re hidden topics weren't actually hidden
  • Loading branch information
radar committed Jun 26, 2011
1 parent d62908e commit 46ef621
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
7 changes: 7 additions & 0 deletions app/controllers/forem/admin/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def destroy
redirect_to forum_topics_path(forum)
end

def toggle_hide
@topic.toggle!(:hidden)
i18n_string = @topic.hidden? ? "hidden" : "visible"
flash[:notice] = t("forem.topic.#{i18n_string}")
redirect_to forum_topic_path(@topic.forum, @topic)
end

private
def find_topic
@topic = Forem::Topic.find(params[:id])
Expand Down
13 changes: 10 additions & 3 deletions app/controllers/forem/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ class TopicsController < Forem::ApplicationController
before_filter :find_forum

def show
@topic = @forum.topics.find(params[:id])
register_view
@posts = @topic.posts.page(params[:page]).per(20)
begin
scope = forem_admin? ? @forum.topics : @forum.topics.visible
@topic = scope.find(params[:id])
rescue ActiveRecord::RecordNotFound
flash[:error] = t("forem.topic.not_found")
redirect_to @forum
else
register_view
@posts = @topic.posts.page(params[:page]).per(20)
end
end

def new
Expand Down
4 changes: 4 additions & 0 deletions app/views/forem/topics/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
| <%= link_to t(".delete"), forum_topic_path(@forum, @topic), :method => :delete, :confirm => 'Are you sure?' %>
<% end %>
</menu>

<% if forem_admin? %>
<%= link_to t(".hide"), toggle_hide_admin_topic_path(@topic), :method => :put %>
<% end %>
<%= paginate @posts %>
<div id='posts'>
<%= render :partial => "forem/posts/post", :collection => @posts %>
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ en:
not_created: This topic could not be created.
deleted: Your topic has been deleted.
cannot_delete: You cannot delete a topic you do not own.
updated: This topic has been updated.
not_updated: This topic could not be updated.
none: There are no topics in this forum currently.
links:
new: New topic
back_to_topics: Back to topics
edit: Edit topic
not_found: The topic you are looking for could not be found.
hidden: This topic is now hidden.
visible: This topic is now visible.
topics:
show:
reply: 'Reply'
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
namespace :admin do
root :to => "base#index"
resources :forums
resources :topics
resources :topics do
member do
put :toggle_hide
end
end
end
end
22 changes: 22 additions & 0 deletions spec/integration/admin/topics_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'spec_helper'

describe "topics" do
let(:forum) { Factory(:forum) }
let(:topic) { Factory(:topic, :forum => forum) }

before do
sign_in! :admin => true
end

it "can hide a topic" do
visit forum_topic_path(forum, topic)
click_link "Hide"
page!
flash_notice!("This topic is now hidden.")

sign_out!

visit forum_topic_path(forum, topic)
flash_error!("The topic you are looking for could not be found.")
end
end

0 comments on commit 46ef621

Please sign in to comment.