end
if user.administrator?
- can [:hide, :unhide, :hidecomment], [DiaryEntry, DiaryComment]
+ can [:hide, :unhide, :hidecomment, :unhidecomment], [DiaryEntry, DiaryComment]
can [:index, :show, :resolve, :ignore, :reopen], Issue
can :create, IssueComment
can [:set_status, :delete, :index], User
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
end
+ def unhidecomment
+ comment = DiaryComment.find(params[:comment])
+ comment.update(:visible => true)
+ redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
+ end
+
def comments
@comment_pages, @comments = paginate(:diary_comments,
:conditions => {
<div class="richtext"><%= diary_comment.body.to_html %></div>
<% if current_user && current_user.administrator? %>
<span>
- <%= link_to t(".hide_link"), hide_diary_comment_path(:display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id), :method => :post, :data => { :confirm => t(".confirm") } %>
+ <% if diary_comment.visible? %>
+ <%= link_to t(".hide_link"), hide_diary_comment_path(:display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id), :method => :post, :data => { :confirm => t(".confirm") } %>
+ <% else %>
+ <%= link_to t(".unhide_link"), unhide_diary_comment_path(:display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id), :method => :post, :data => { :confirm => t(".confirm") } %>
+ <% end %>
</span>
<% end %>
</div>
diary_comment:
comment_from: "Comment from %{link_user} on %{comment_created_at}"
hide_link: Hide this comment
+ unhide_link: Unhide this comment
confirm: Confirm
report: Report this comment
location:
post "/user/:display_name/diary/:id/hide" => "diary_entries#hide", :id => /\d+/, :as => :hide_diary_entry
post "/user/:display_name/diary/:id/unhide" => "diary_entries#unhide", :id => /\d+/, :as => :unhide_diary_entry
post "/user/:display_name/diary/:id/hidecomment/:comment" => "diary_entries#hidecomment", :id => /\d+/, :comment => /\d+/, :as => :hide_diary_comment
+ post "/user/:display_name/diary/:id/unhidecomment/:comment" => "diary_entries#unhidecomment", :id => /\d+/, :comment => /\d+/, :as => :unhide_diary_comment
post "/user/:display_name/diary/:id/subscribe" => "diary_entries#subscribe", :as => :diary_entry_subscribe, :id => /\d+/
post "/user/:display_name/diary/:id/unsubscribe" => "diary_entries#unsubscribe", :as => :diary_entry_unsubscribe, :id => /\d+/
{ :path => "/user/username/diary/1/hidecomment/2", :method => :post },
{ :controller => "diary_entries", :action => "hidecomment", :display_name => "username", :id => "1", :comment => "2" }
)
+ assert_routing(
+ { :path => "/user/username/diary/1/unhidecomment/2", :method => :post },
+ { :controller => "diary_entries", :action => "unhidecomment", :display_name => "username", :id => "1", :comment => "2" }
+ )
assert_routing(
{ :path => "/user/username/diary/1/subscribe", :method => :post },
{ :controller => "diary_entries", :action => "subscribe", :display_name => "username", :id => "1" }
assert_equal false, DiaryComment.find(diary_comment.id).visible
end
+ def test_unhidecomment
+ user = create(:user)
+ administrator_user = create(:administrator_user)
+ diary_entry = create(:diary_entry, :user => user)
+ diary_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
+ # Try without logging in
+ post :unhidecomment,
+ :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }
+ assert_response :forbidden
+ assert_equal false, DiaryComment.find(diary_comment.id).visible
+
+ # Now try as a normal user
+ post :unhidecomment,
+ :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
+ :session => { :user => user }
+ assert_response :redirect
+ assert_redirected_to :controller => :errors, :action => :forbidden
+ assert_equal false, DiaryComment.find(diary_comment.id).visible
+
+ # Finally try as an administrator
+ post :unhidecomment,
+ :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
+ :session => { :user => administrator_user }
+ assert_response :redirect
+ assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
+ assert_equal true, DiaryComment.find(diary_comment.id).visible
+ end
+
def test_comments
user = create(:user)
other_user = create(:user)