Commit 80d971f1cf513a863099b3bd77d83c8d750748bf
1 parent
1c7ee398
Exists in
master
and in
29 other branches
ActionItem147: Article could not accept comments
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2435 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
44 additions
and
6 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -56,6 +56,7 @@ class CmsController < MyProfileController | @@ -56,6 +56,7 @@ class CmsController < MyProfileController | ||
56 | 56 | ||
57 | # user must choose an article type first | 57 | # user must choose an article type first |
58 | @type = params[:type] | 58 | @type = params[:type] |
59 | + | ||
59 | if @type.blank? | 60 | if @type.blank? |
60 | @article_types = [] | 61 | @article_types = [] |
61 | available_article_types.each do |type| | 62 | available_article_types.each do |type| |
app/controllers/my_profile/memberships_controller.rb
@@ -17,6 +17,7 @@ class MembershipsController < MyProfileController | @@ -17,6 +17,7 @@ class MembershipsController < MyProfileController | ||
17 | 17 | ||
18 | def leave | 18 | def leave |
19 | @to_leave = Profile.find(params[:id]) | 19 | @to_leave = Profile.find(params[:id]) |
20 | + | ||
20 | if request.post? && params[:confirmation] | 21 | if request.post? && params[:confirmation] |
21 | @to_leave.remove_member(profile) | 22 | @to_leave.remove_member(profile) |
22 | redirect_to :action => 'index' | 23 | redirect_to :action => 'index' |
app/controllers/public/content_viewer_controller.rb
@@ -46,7 +46,7 @@ class ContentViewerController < PublicController | @@ -46,7 +46,7 @@ class ContentViewerController < PublicController | ||
46 | return | 46 | return |
47 | end | 47 | end |
48 | 48 | ||
49 | - if request.post? && params[:comment] && params[self.icaptcha_field].blank? | 49 | + if request.post? && params[:comment] && params[self.icaptcha_field].blank? && @page.accept_comments? |
50 | add_comment | 50 | add_comment |
51 | end | 51 | end |
52 | 52 |
app/views/cms/edit.rhtml
@@ -28,6 +28,8 @@ | @@ -28,6 +28,8 @@ | ||
28 | <div> | 28 | <div> |
29 | <%= check_box :article, :published %> | 29 | <%= check_box :article, :published %> |
30 | <label for='article_published'><%= _('Published')%></label> | 30 | <label for='article_published'><%= _('Published')%></label> |
31 | + <%= check_box :article, :accept_comments %> | ||
32 | + <label for='article_accept_comments'><%= _('Accept Comments')%></label> | ||
31 | </div> | 33 | </div> |
32 | </div> | 34 | </div> |
33 | 35 |
app/views/content_viewer/view_page.rhtml
@@ -68,8 +68,14 @@ | @@ -68,8 +68,14 @@ | ||
68 | </div> | 68 | </div> |
69 | <% end %> | 69 | <% end %> |
70 | 70 | ||
71 | -<h3><%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %></h3> | ||
72 | -<%= render :partial => 'comment', :collection => @comments %> | ||
73 | -<%= render :partial => 'comment_form' %> | 71 | + <h3> |
72 | + <%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %> | ||
73 | + </h3> | ||
74 | + <%= render :partial => 'comment', :collection => @comments %> | ||
75 | +<% if !@page.accept_comments? %> | ||
76 | + <h3><%= _('This article does not accept comments')%></h3> | ||
77 | +<% else %> | ||
78 | + <%= render :partial => 'comment_form' %> | ||
79 | +<% end %> | ||
74 | 80 | ||
75 | </div><!-- end id="article" --> | 81 | </div><!-- end id="article" --> |
app/views/search/_search_form.rhtml
1 | <div class='search-form'> | 1 | <div class='search-form'> |
2 | - | ||
3 | <% simple_search = false unless defined? simple_search %> | 2 | <% simple_search = false unless defined? simple_search %> |
4 | 3 | ||
5 | <% form_tag( { :action => 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, | 4 | <% form_tag( { :action => 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +class AddAcceptCommentsToArticles < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + add_column :articles, :accept_comments, :boolean, :default => true | ||
4 | + add_column :article_versions, :accept_comments, :boolean, :default => true | ||
5 | + end | ||
6 | + | ||
7 | + def self.down | ||
8 | + remove_column :articles, :accept_comments | ||
9 | + remove_column :article_versions, :accept_comments | ||
10 | + end | ||
11 | +end |
test/functional/content_viewer_controller_test.rb
@@ -89,7 +89,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -89,7 +89,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
89 | page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text') | 89 | page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text') |
90 | page.save! | 90 | page.save! |
91 | profile.home_page = page; profile.save! | 91 | profile.home_page = page; profile.save! |
92 | - | 92 | + |
93 | assert_difference Comment, :count do | 93 | assert_difference Comment, :count do |
94 | post :view_page, :profile => 'popstar', :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap', :name => 'Anonymous coward', :email => 'coward@anonymous.com' } | 94 | post :view_page, :profile => 'popstar', :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap', :name => 'Anonymous coward', :email => 'coward@anonymous.com' } |
95 | end | 95 | end |
@@ -396,5 +396,12 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -396,5 +396,12 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
396 | assert_template 'view_page' | 396 | assert_template 'view_page' |
397 | end | 397 | end |
398 | 398 | ||
399 | + should 'not be able to post comment if article do not accept it' do | ||
400 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text', :accept_comments => false) | ||
401 | + | ||
402 | + assert_no_difference Comment, :count do | ||
403 | + post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap', :name => 'Anonymous coward', :email => 'coward@anonymous.com' } | ||
404 | + end | ||
405 | + end | ||
399 | 406 | ||
400 | end | 407 | end |
test/functional/my_profile_controller_test.rb
@@ -45,4 +45,15 @@ class MyProfileControllerTest < Test::Unit::TestCase | @@ -45,4 +45,15 @@ class MyProfileControllerTest < Test::Unit::TestCase | ||
45 | get :index, :profile => 'hacking_institute' | 45 | get :index, :profile => 'hacking_institute' |
46 | assert_response 403 # forbidden | 46 | assert_response 403 # forbidden |
47 | end | 47 | end |
48 | + | ||
49 | + def test_accept_comments | ||
50 | + article=profile.articles.create!(:name=>'my article',:body =>'my text',:accept_comments=>true) | ||
51 | + assert article.comments.create(:author=>profile,:title=>'A new comment', :body =>'Go go go!') | ||
52 | + end | ||
53 | + | ||
54 | + def test_not_accept_comments | ||
55 | + article=profile.articles.create!(:name=>'my article',:body =>'my text',:accept_comments=>true) | ||
56 | + assert article.comments.create(:author=>profile,:title=>'A new comment', :body =>'Go go go!') | ||
57 | + end | ||
58 | + | ||
48 | end | 59 | end |