diff options
-rw-r--r-- | app/controllers/admin_user_controller.rb | 6 | ||||
-rw-r--r-- | app/helpers/admin_helper.rb | 5 | ||||
-rw-r--r-- | app/views/admin_request/_some_annotations.html.erb | 95 | ||||
-rw-r--r-- | config/routes.rb | 1 | ||||
-rw-r--r-- | spec/controllers/admin_user_controller_spec.rb | 69 | ||||
-rw-r--r-- | spec/factories.rb | 17 | ||||
-rw-r--r-- | spec/helpers/admin_helper_spec.rb | 21 |
7 files changed, 173 insertions, 41 deletions
diff --git a/app/controllers/admin_user_controller.rb b/app/controllers/admin_user_controller.rb index 940a5fe8f..a6438e151 100644 --- a/app/controllers/admin_user_controller.rb +++ b/app/controllers/admin_user_controller.rb @@ -99,6 +99,12 @@ class AdminUserController < AdminController redirect_to admin_user_show_url(@admin_user) end + def modify_comment_visibility + @visibility_value = params.key?(:hide_selected) ? false : true + Comment.update_all(["visible=?", @visibility_value], :id => params[:comment_ids]) + redirect_to :back + end + private end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 059cebdfa..151e53758 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -33,5 +33,10 @@ module AdminHelper link_to(eye, user_path(user), :title => "view user's page on public website") + " " + link_to(h(user.name), admin_user_show_path(user), :title => "view full details") end + + def comment_visibility(comment) + comment.visible? ? 'Visible' : 'Hidden' + end + end diff --git a/app/views/admin_request/_some_annotations.html.erb b/app/views/admin_request/_some_annotations.html.erb index dfd46f828..7adcdc5bb 100644 --- a/app/views/admin_request/_some_annotations.html.erb +++ b/app/views/admin_request/_some_annotations.html.erb @@ -1,48 +1,61 @@ -<% if comments.size > 0 %> - <div class="accordion" id="comments"> - <% for comment in comments %> - <div class="accordion-group"> - <div class="accordion-heading"> - <a href="#comment_<%=comment.id%>" data-toggle="collapse" data-parent="#comments"><%= chevron_right %></a> - <%= link_to admin_request_edit_comment_path(comment) do %> - #<%=comment.id%> - -- - <%=h(comment.user.name)%> - <%=admin_value(comment.created_at)%> +<% if comments.any? %> + <%= form_tag admin_user_modify_comment_visibility_path do %> + <div class="accordion" id="comments"> + <% comments.each do |comment| %> + <div class="accordion-group"> + <div class="accordion-heading"> + <%= check_box_tag 'comment_ids[]', comment.id %> + + <a href="#comment_<%= comment.id %>" data-toggle="collapse" data-parent="#comments"><%= chevron_right %></a> + + <%= link_to admin_request_edit_comment_path(comment) do %> + #<%= comment.id %> + -- + <%= h(comment.user.name) %> + <%= admin_value(comment.created_at) %> <% end %> - <blockquote class="incoming-message"> - <%= truncate(comment.body, :length => 400) %> - </blockquote> - </div> - <div id="comment_<%=comment.id%>" class="accordion-body collapse"> - <table class="table table-striped table-condensed"> - <tbody> - <tr> - <td colspan="2"> - By <%= user_both_links(comment.user) %> - </td> - </tr> - <% comment.for_admin_column do |name, value, type, column_name |%> + + <%= comment_visibility(comment) %> + + <blockquote class="incoming-message"> + <%= truncate(comment.body, :length => 400) %> + </blockquote> + </div> + + <div id="comment_<%= comment.id %>" class="accordion-body collapse"> + <table class="table table-striped table-condensed"> + <tbody> <tr> - <td> - <b><%=name%></b> - </td> - <td> - <% if column_name == 'body' && !comment.visible %> - <s><%=h comment.send(column_name) %></s> - <% else %> - <%=h comment.send(column_name) %> - <% end %> + <td colspan="2"> + By <%= user_both_links(comment.user) %> </td> </tr> - <% end %> - </tbody> - </table> + <% comment.for_admin_column do |name, value, type, column_name |%> + <tr> + <td> + <b><%= name %></b> + </td> + <td> + <% if column_name == 'body' && !comment.visible %> + <s><%= h comment.send(column_name) %></s> + <% else %> + <%= h comment.send(column_name) %> + <% end %> + </td> + </tr> + <% end %> + </tbody> + </table> + </div> + </div> - </div> - <% end %> - </div> + <% end %> + </div> + + <%= submit_tag 'Hide selected', :name => 'hide_selected' %> + <%= submit_tag 'Unhide selected', :name => 'unhide_selected' %> + + <% end %> <% else %> <p>None yet.</p> -<% end %> - +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 87a62c0bf..1079fbe14 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -233,6 +233,7 @@ Alaveteli::Application.routes.draw do match '/admin/user/destroy_track' => 'admin_user#destroy_track', :as => :admin_user_destroy_track match '/admin/user/login_as/:id' => 'admin_user#login_as', :as => :admin_user_login_as match '/admin/user/clear_profile_photo/:id' => 'admin_user#clear_profile_photo', :as => :admin_clear_profile_photo + match '/admin/user/modify_comment_visibility/:id' => 'admin_user#modify_comment_visibility', :as => 'admin_user_modify_comment_visibility' #### #### AdminTrack controller diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index 99894a414..8b89506f9 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -44,3 +44,72 @@ describe AdminUserController, "when updating a user" do end end + +describe AdminUserController do + + describe :modify_comment_visibility do + + before(:each) do + @user = FactoryGirl.create(:user) + request.env["HTTP_REFERER"] = admin_user_show_path(@user) + end + + it 'redirects to the page the admin was previously on' do + comment = FactoryGirl.create(:visible_comment, :user => @user) + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => comment.id, + :hide_selected => 'hidden' } + + response.should redirect_to(admin_user_show_path(@user)) + end + + it 'sets the given comments visibility to hidden' do + comments = FactoryGirl.create_list(:visible_comment, 3, :user => @user) + comment_ids = comments.map(&:id) + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => comment_ids, + :hide_selected => 'hidden' } + + Comment.find(comment_ids).each { |comment| comment.should_not be_visible } + end + + it 'sets the given comments visibility to visible' do + comments = FactoryGirl.create_list(:hidden_comment, 3, :user => @user) + comment_ids = comments.map(&:id) + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => comment_ids, + :unhide_selected => 'visible' } + + Comment.find(comment_ids).each { |comment| comment.should be_visible } + end + + it 'only modifes the given list of comments' do + unaffected_comment = FactoryGirl.create(:hidden_comment, :user => @user) + affected_comment = FactoryGirl.create(:hidden_comment, :user => @user) + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => affected_comment.id, + :unhide_selected => 'visible' } + + Comment.find(unaffected_comment).should_not be_visible + Comment.find(affected_comment).should be_visible + end + + it 'preserves the visibility if a comment is already of the requested visibility' do + hidden_comment = FactoryGirl.create(:hidden_comment, :user => @user) + visible_comment = FactoryGirl.create(:visible_comment, :user => @user) + comment_ids = [hidden_comment.id, visible_comment.id] + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => comment_ids, + :unhide_selected => 'visible' } + + Comment.find(comment_ids).each { |c| c.should be_visible } + end + + end + +end diff --git a/spec/factories.rb b/spec/factories.rb index 4ae99be5b..e3990977e 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -176,4 +176,21 @@ FactoryGirl.define do user body "Some text" end + + factory :comment do + user + info_request + + body 'This a wise and helpful annotation.' + comment_type 'request' + + factory :visible_comment do + visible true + end + + factory :hidden_comment do + visible false + end + end + end diff --git a/spec/helpers/admin_helper_spec.rb b/spec/helpers/admin_helper_spec.rb new file mode 100644 index 000000000..804fcc7fd --- /dev/null +++ b/spec/helpers/admin_helper_spec.rb @@ -0,0 +1,21 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe AdminHelper do + + include AdminHelper + + describe :comment_visibility do + + it 'shows the status of a visible comment' do + comment = Factory.build(:visible_comment) + comment_visibility(comment).should == 'Visible' + end + + it 'shows the status of a hidden comment' do + comment = Factory.build(:hidden_comment) + comment_visibility(comment).should == 'Hidden' + end + + end + +end |