diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index 6c22a0b..c94ebad 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -56,6 +56,7 @@ class CmsController < MyProfileController
# user must choose an article type first
@type = params[:type]
+
if @type.blank?
@article_types = []
available_article_types.each do |type|
diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb
index bd08e66..74daf44 100644
--- a/app/controllers/my_profile/memberships_controller.rb
+++ b/app/controllers/my_profile/memberships_controller.rb
@@ -17,6 +17,7 @@ class MembershipsController < MyProfileController
def leave
@to_leave = Profile.find(params[:id])
+
if request.post? && params[:confirmation]
@to_leave.remove_member(profile)
redirect_to :action => 'index'
diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb
index c57e326..d2f7645 100644
--- a/app/controllers/public/content_viewer_controller.rb
+++ b/app/controllers/public/content_viewer_controller.rb
@@ -46,7 +46,7 @@ class ContentViewerController < PublicController
return
end
- if request.post? && params[:comment] && params[self.icaptcha_field].blank?
+ if request.post? && params[:comment] && params[self.icaptcha_field].blank? && @page.accept_comments?
add_comment
end
diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml
index ba0aa72..205f30d 100644
--- a/app/views/cms/edit.rhtml
+++ b/app/views/cms/edit.rhtml
@@ -28,6 +28,8 @@
<%= check_box :article, :published %>
+ <%= check_box :article, :accept_comments %>
+
diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml
index fee9cd5..e5f7fcd 100644
--- a/app/views/content_viewer/view_page.rhtml
+++ b/app/views/content_viewer/view_page.rhtml
@@ -68,8 +68,14 @@
<% end %>
-<%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %>
-<%= render :partial => 'comment', :collection => @comments %>
-<%= render :partial => 'comment_form' %>
+
+ <%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %>
+
+ <%= render :partial => 'comment', :collection => @comments %>
+<% if !@page.accept_comments? %>
+ <%= _('This article does not accept comments')%>
+<% else %>
+ <%= render :partial => 'comment_form' %>
+<% end %>
diff --git a/app/views/search/_search_form.rhtml b/app/views/search/_search_form.rhtml
index 59843f7..6b57b94 100644
--- a/app/views/search/_search_form.rhtml
+++ b/app/views/search/_search_form.rhtml
@@ -1,5 +1,4 @@
-
<% simple_search = false unless defined? simple_search %>
<% form_tag( { :action => 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) },
diff --git a/db/migrate/053_add_accept_comments_to_articles.rb b/db/migrate/053_add_accept_comments_to_articles.rb
new file mode 100644
index 0000000..dce463e
--- /dev/null
+++ b/db/migrate/053_add_accept_comments_to_articles.rb
@@ -0,0 +1,11 @@
+class AddAcceptCommentsToArticles < ActiveRecord::Migration
+ def self.up
+ add_column :articles, :accept_comments, :boolean, :default => true
+ add_column :article_versions, :accept_comments, :boolean, :default => true
+ end
+
+ def self.down
+ remove_column :articles, :accept_comments
+ remove_column :article_versions, :accept_comments
+ end
+end
diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb
index 5ecd448..defa90a 100644
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -89,7 +89,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase
page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text')
page.save!
profile.home_page = page; profile.save!
-
+
assert_difference Comment, :count do
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' }
end
@@ -396,5 +396,12 @@ class ContentViewerControllerTest < Test::Unit::TestCase
assert_template 'view_page'
end
+ should 'not be able to post comment if article do not accept it' do
+ page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text', :accept_comments => false)
+
+ assert_no_difference Comment, :count do
+ 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' }
+ end
+ end
end
diff --git a/test/functional/my_profile_controller_test.rb b/test/functional/my_profile_controller_test.rb
index 69f53e5..6d0c6ba 100644
--- a/test/functional/my_profile_controller_test.rb
+++ b/test/functional/my_profile_controller_test.rb
@@ -45,4 +45,15 @@ class MyProfileControllerTest < Test::Unit::TestCase
get :index, :profile => 'hacking_institute'
assert_response 403 # forbidden
end
+
+ def test_accept_comments
+ article=profile.articles.create!(:name=>'my article',:body =>'my text',:accept_comments=>true)
+ assert article.comments.create(:author=>profile,:title=>'A new comment', :body =>'Go go go!')
+ end
+
+ def test_not_accept_comments
+ article=profile.articles.create!(:name=>'my article',:body =>'my text',:accept_comments=>true)
+ assert article.comments.create(:author=>profile,:title=>'A new comment', :body =>'Go go go!')
+ end
+
end
--
libgit2 0.21.2