diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index f761bba..123703e 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -110,7 +110,7 @@ class ContentViewerController < ApplicationController @comment.destroy flash[:notice] = _('Comment succesfully deleted') end - redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path + redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] end end diff --git a/app/views/content_viewer/_comment.rhtml b/app/views/content_viewer/_comment.rhtml index 0a05e8b..13b2e17 100644 --- a/app/views/content_viewer/_comment.rhtml +++ b/app/views/content_viewer/_comment.rhtml @@ -3,7 +3,7 @@ <% if logged_in? && (user == @page.profile || user == comment.author || user.has_permission?(:moderate_comments, @page.profile)) %> <% button_bar(:style => 'float: right; margin-top: 0px;') do %> - <%= icon_button(:delete, _('Remove this comment'), { :profile => params[:profile], :remove_comment => comment.id }, :method => :post, :confirm => _('Are you sure you want to remove this comment?')) %> + <%= icon_button(:delete, _('Remove this comment'), { :profile => params[:profile], :remove_comment => comment.id, :view => params[:view] }, :method => :post, :confirm => _('Are you sure you want to remove this comment?')) %> <% end %> <% end %> diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 2e8cc47..3300302 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -118,6 +118,20 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_tag :tag => 'a', :attributes => { :href => '/testuser/test?remove_comment=' + comment.id.to_s } end + should 'display remove comment button with param view when image' do + profile = create_user('testuser').person + + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + image.save! + + comment = image.comments.build(:author => profile, :title => 'a comment', :body => 'lalala') + comment.save! + + login_as 'testuser' + get :view_page, :profile => 'testuser', :page => [ image.filename ], :view => true + assert_tag :tag => 'a', :attributes => { :href => "/testuser/#{image.filename}?remove_comment=" + comment.id.to_s + '&view=true'} + end + should 'not add unneeded params for remove comment button' do profile = create_user('testuser').person article = profile.articles.build(:name => 'test') @@ -177,6 +191,25 @@ class ContentViewerControllerTest < Test::Unit::TestCase end end + should 'be able to remove comments of their images' do + profile = create_user('testuser').person + + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + image.save! + + commenter = create_user('otheruser').person + comment = image.comments.build(:author => commenter, :title => 'a comment', :body => 'lalala') + comment.save! + + login_as 'testuser' # testuser must be able to remove comments in his articles + assert_difference Comment, :count, -1 do + post :view_page, :profile => profile.identifier, :page => [ image.filename ], :remove_comment => comment.id, :view => true + + assert_response :redirect + assert_redirected_to :profile => profile.identifier, :page => image.explode_path, :view => true + end + end + should 'not be able to post comment while inverse captcha field filled' do profile = create_user('popstar').person page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text') -- libgit2 0.21.2