Commit 0541cc4a14da751d744dcfd132ee4bbef0db4266
1 parent
e7153498
Exists in
staging
and in
42 other branches
Searching comments on page before editing it
- Added render_not_found screen when comment id doesn't exist - Displaying message when trying to edit a comment from other page - Fixed a test on ToleranceTimePlugin
Showing
5 changed files
with
71 additions
and
22 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
... | ... | @@ -127,15 +127,20 @@ class ContentViewerController < ApplicationController |
127 | 127 | path = params[:page].join('/') |
128 | 128 | @page = profile.articles.find_by_path(path) |
129 | 129 | @form_div = 'opened' |
130 | - @comment = Comment.find(params[:id]) | |
131 | - if request.post? | |
132 | - begin | |
133 | - @comment.update_attributes(params[:comment]) | |
134 | - session[:notice] = _('Comment updated.') | |
135 | - redirect_to :action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path | |
136 | - rescue | |
137 | - session[:notice] = _('Comment could not be updated.') | |
130 | + @comment = @page.comments.find_by_id(params[:id]) | |
131 | + if @comment | |
132 | + if request.post? | |
133 | + begin | |
134 | + @comment.update_attributes(params[:comment]) | |
135 | + session[:notice] = _('Comment succesfully updated') | |
136 | + redirect_to :action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path | |
137 | + rescue | |
138 | + session[:notice] = _('Comment could not be updated') | |
139 | + end | |
138 | 140 | end |
141 | + else | |
142 | + redirect_to @page.view_url | |
143 | + session[:notice] = _('Could not find the comment in the article') | |
139 | 144 | end |
140 | 145 | end |
141 | 146 | |
... | ... | @@ -217,8 +222,12 @@ class ContentViewerController < ApplicationController |
217 | 222 | end |
218 | 223 | |
219 | 224 | def comment_author |
220 | - comment = Comment.find(params[:id]) | |
221 | - render_access_denied if comment.author.blank? || comment.author != user | |
225 | + comment = Comment.find_by_id(params[:id]) | |
226 | + if comment | |
227 | + render_access_denied if comment.author.blank? || comment.author != user | |
228 | + else | |
229 | + render_not_found | |
230 | + end | |
222 | 231 | end |
223 | 232 | |
224 | 233 | end | ... | ... |
app/views/content_viewer/_comment_form.rhtml
... | ... | @@ -32,15 +32,17 @@ function submit_comment_form(button) { |
32 | 32 | |
33 | 33 | <div class="post_comment_box <%= @form_div %>"> |
34 | 34 | |
35 | -<h4 onclick="var d = jQuery(this).parent('.post_comment_box'); | |
36 | - if (d.hasClass('closed')) { | |
37 | - d.removeClass('closed'); | |
38 | - d.addClass('opened'); | |
39 | - d.find('input[name=comment[title]], textarea').val(''); | |
40 | - d.find('.comment_form input[name=comment[<%= focus_on %>]]').focus(); | |
41 | - }"> | |
42 | - <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') if display_link %> | |
43 | -</h4> | |
35 | +<% if display_link %> | |
36 | + <h4 onclick="var d = jQuery(this).parent('.post_comment_box'); | |
37 | + if (d.hasClass('closed')) { | |
38 | + d.removeClass('closed'); | |
39 | + d.addClass('opened'); | |
40 | + d.find('input[name=comment[title]], textarea').val(''); | |
41 | + d.find('.comment_form input[name=comment[<%= focus_on %>]]').focus(); | |
42 | + }"> | |
43 | + <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %> | |
44 | + </h4> | |
45 | +<% end %> | |
44 | 46 | |
45 | 47 | <% unless pass_without_comment_captcha? %> |
46 | 48 | <div id="recaptcha-container" style="display: none"> | ... | ... |
plugins/tolerance_time/lib/tolerance_time_plugin.rb
... | ... | @@ -35,7 +35,7 @@ class ToleranceTimePlugin < Noosfero::Plugin |
35 | 35 | block = lambda do |
36 | 36 | content = Article.find(params[:id]) |
37 | 37 | if ToleranceTimePlugin.expired?(content) |
38 | - session[:notice] = _('This content can\'t be edited anymore because it expired the tolerance time') | |
38 | + session[:notice] = _("This content can't be edited anymore because it expired the tolerance time") | |
39 | 39 | redirect_to content.url |
40 | 40 | end |
41 | 41 | end |
... | ... | @@ -51,7 +51,7 @@ class ToleranceTimePlugin < Noosfero::Plugin |
51 | 51 | block = lambda do |
52 | 52 | content = Comment.find(params[:id]) |
53 | 53 | if ToleranceTimePlugin.expired?(content) |
54 | - session[:notice] = _('This content can\'t be edited anymore because it expired the tolerance time') | |
54 | + session[:notice] = _("This content can't be edited anymore because it expired the tolerance time") | |
55 | 55 | redirect_to content.article.url |
56 | 56 | end |
57 | 57 | end | ... | ... |
plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb
test/functional/content_viewer_controller_test.rb
... | ... | @@ -1464,4 +1464,42 @@ end |
1464 | 1464 | assert spam.spam? |
1465 | 1465 | end |
1466 | 1466 | |
1467 | + should 'be able to edit a comment' do | |
1468 | + login_as profile.identifier | |
1469 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text', :accept_comments => false) | |
1470 | + comment = fast_create(Comment, :body => 'Original comment', :author_id => profile.id, :source_id => page.id, :source_type => 'Article') | |
1471 | + | |
1472 | + post :edit_comment, :id => comment.id, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :body => 'Comment edited' } | |
1473 | + assert_equal 'Comment edited', Comment.find(comment.id).body | |
1474 | + end | |
1475 | + | |
1476 | + should 'edit comment from a page' do | |
1477 | + login_as profile.identifier | |
1478 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') | |
1479 | + comment = fast_create(Comment, :body => 'Original comment', :author_id => profile.id, :source_id => page.id, :source_type => 'Article') | |
1480 | + | |
1481 | + get :edit_comment, :id => comment.id, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :body => 'Comment edited' } | |
1482 | + assert_tag :tag => 'h1', :content => 'Edit comment' | |
1483 | + end | |
1484 | + | |
1485 | + should 'not edit comment from other page' do | |
1486 | + login_as profile.identifier | |
1487 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') | |
1488 | + comment = fast_create(Comment, :body => 'Original comment', :author_id => profile.id, :source_id => page.id, :source_type => 'Article') | |
1489 | + | |
1490 | + other_page = profile.articles.create!(:name => 'my other article', :body => 'the body of the text') | |
1491 | + comment_on_other_page = fast_create(Comment, :body => 'Comment on other article', :author_id => profile.id, :source_id => other_page.id, :source_type => 'Article') | |
1492 | + | |
1493 | + get :edit_comment, :id => comment_on_other_page.id, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :body => 'Comment edited' } | |
1494 | + assert_redirected_to page.url | |
1495 | + end | |
1496 | + | |
1497 | + should 'not crash on edit comment if comment does not exist' do | |
1498 | + login_as profile.identifier | |
1499 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') | |
1500 | + | |
1501 | + get :edit_comment, :id => 1000, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :body => 'Comment edited' } | |
1502 | + assert_response 404 | |
1503 | + end | |
1504 | + | |
1467 | 1505 | end | ... | ... |