Allow admins to unhide diary comments, if they wish
This commit is contained in:
parent
49fc17c6b6
commit
fdffd22cca
6 changed files with 46 additions and 2 deletions
|
@ -51,7 +51,7 @@ class Ability
|
||||||
end
|
end
|
||||||
|
|
||||||
if user.administrator?
|
if user.administrator?
|
||||||
can [:hide, :unhide, :hidecomment], [DiaryEntry, DiaryComment]
|
can [:hide, :unhide, :hidecomment, :unhidecomment], [DiaryEntry, DiaryComment]
|
||||||
can [:index, :show, :resolve, :ignore, :reopen], Issue
|
can [:index, :show, :resolve, :ignore, :reopen], Issue
|
||||||
can :create, IssueComment
|
can :create, IssueComment
|
||||||
can [:set_status, :delete, :index], User
|
can [:set_status, :delete, :index], User
|
||||||
|
|
|
@ -226,6 +226,12 @@ class DiaryEntriesController < ApplicationController
|
||||||
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
|
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
|
||||||
end
|
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
|
def comments
|
||||||
@comment_pages, @comments = paginate(:diary_comments,
|
@comment_pages, @comments = paginate(:diary_comments,
|
||||||
:conditions => {
|
:conditions => {
|
||||||
|
|
|
@ -9,7 +9,11 @@
|
||||||
<div class="richtext"><%= diary_comment.body.to_html %></div>
|
<div class="richtext"><%= diary_comment.body.to_html %></div>
|
||||||
<% if current_user && current_user.administrator? %>
|
<% if current_user && current_user.administrator? %>
|
||||||
<span>
|
<span>
|
||||||
|
<% 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") } %>
|
<%= 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>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -337,6 +337,7 @@ en:
|
||||||
diary_comment:
|
diary_comment:
|
||||||
comment_from: "Comment from %{link_user} on %{comment_created_at}"
|
comment_from: "Comment from %{link_user} on %{comment_created_at}"
|
||||||
hide_link: Hide this comment
|
hide_link: Hide this comment
|
||||||
|
unhide_link: Unhide this comment
|
||||||
confirm: Confirm
|
confirm: Confirm
|
||||||
report: Report this comment
|
report: Report this comment
|
||||||
location:
|
location:
|
||||||
|
|
|
@ -236,6 +236,7 @@ OpenStreetMap::Application.routes.draw do
|
||||||
post "/user/:display_name/diary/:id/hide" => "diary_entries#hide", :id => /\d+/, :as => :hide_diary_entry
|
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/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/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/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+/
|
post "/user/:display_name/diary/:id/unsubscribe" => "diary_entries#unsubscribe", :as => :diary_entry_unsubscribe, :id => /\d+/
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,10 @@ class DiaryEntriesControllerTest < ActionController::TestCase
|
||||||
{ :path => "/user/username/diary/1/hidecomment/2", :method => :post },
|
{ :path => "/user/username/diary/1/hidecomment/2", :method => :post },
|
||||||
{ :controller => "diary_entries", :action => "hidecomment", :display_name => "username", :id => "1", :comment => "2" }
|
{ :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(
|
assert_routing(
|
||||||
{ :path => "/user/username/diary/1/subscribe", :method => :post },
|
{ :path => "/user/username/diary/1/subscribe", :method => :post },
|
||||||
{ :controller => "diary_entries", :action => "subscribe", :display_name => "username", :id => "1" }
|
{ :controller => "diary_entries", :action => "subscribe", :display_name => "username", :id => "1" }
|
||||||
|
@ -809,6 +813,34 @@ class DiaryEntriesControllerTest < ActionController::TestCase
|
||||||
assert_equal false, DiaryComment.find(diary_comment.id).visible
|
assert_equal false, DiaryComment.find(diary_comment.id).visible
|
||||||
end
|
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
|
def test_comments
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
other_user = create(:user)
|
other_user = create(:user)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue