end
if user.administrator?
- can [:hide, :unhide, :hidecomment, :unhidecomment], [DiaryEntry, DiaryComment]
- can [:hide, :hidecomment], DiaryEntry
++ can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry
can [:index, :show, :resolve, :ignore, :reopen], Issue
can :create, IssueComment
can [:set_status, :delete, :index], User
</p>
<div class="richtext"><%= diary_comment.body.to_html %></div>
- <% if current_user && current_user.administrator? %>
+ <% if can? :hidecomment, DiaryEntry %>
<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>
</li>
<% end %>
- <% if current_user && current_user.administrator? %>
+ <% if can? :hide, DiaryEntry %>
<li>
- <%= link_to t(".hide_link"), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t(".confirm") } %>
+ <% if diary_entry.visible %>
+ <%= link_to t(".hide_link"), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t(".confirm") } %>
+ <% else %>
+ <%= link_to t(".unhide_link"), unhide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t(".confirm") } %>
+ <% end %>
</li>
<% end %>
</ul>
assert_equal false, DiaryEntry.find(diary_entry.id).visible
end
+ def test_unhide
+ user = create(:user)
+
+ # Try without logging in
+ diary_entry = create(:diary_entry, :user => user, :visible => false)
+ post :unhide,
+ :params => { :display_name => user.display_name, :id => diary_entry.id }
+ assert_response :forbidden
+ assert_equal false, DiaryEntry.find(diary_entry.id).visible
+
+ # Now try as a normal user
+ post :unhide,
+ :params => { :display_name => user.display_name, :id => diary_entry.id },
+ :session => { :user => user }
+ assert_response :redirect
+ assert_redirected_to :controller => :errors, :action => :forbidden
+ assert_equal false, DiaryEntry.find(diary_entry.id).visible
+
+ # Finally try as an administrator
+ post :unhide,
+ :params => { :display_name => user.display_name, :id => diary_entry.id },
+ :session => { :user => create(:administrator_user) }
+ assert_response :redirect
+ assert_redirected_to :action => :index, :display_name => user.display_name
+ assert_equal true, DiaryEntry.find(diary_entry.id).visible
+ end
+
def test_hidecomment
user = create(:user)
- administrator_user = create(:administrator_user)
diary_entry = create(:diary_entry, :user => user)
diary_comment = create(:diary_comment, :diary_entry => diary_entry)
+
# Try without logging in
post :hidecomment,
:params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }