Commit f75d6d82939c3c1d57015b0d48f545ea1f074913

Authored by AntonioTerceiro
1 parent 04cb32bb

ActionItem389: not showing unpublished articles



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1867 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/content_viewer_controller.rb
... ... @@ -15,6 +15,10 @@ class ContentViewerController < PublicController
15 15 end
16 16 else
17 17 @page = profile.articles.find_by_path(path)
  18 +
  19 + # do not show unpublished articles
  20 + @page = nil unless @page.published
  21 +
18 22 if @page.nil?
19 23 render_not_found(@path)
20 24 return
... ...
db/migrate/036_add_published_field_to_article.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class AddPublishedFieldToArticle < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :articles, :published, :boolean, :default => true
  4 + execute('update articles set published = 1')
  5 +
  6 + add_column :article_versions, :published, :boolean, :default => true
  7 + end
  8 +
  9 + def self.down
  10 + if self.select('select id from articles where not published').size > 0
  11 + raise ActiveRecord::IrreversibleMigration, 'cannot remove published column, there are articles marked as not published'
  12 + else
  13 + remove_column :articles, :published
  14 + remove_column :article_versions, :published
  15 + end
  16 + end
  17 +end
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -247,4 +247,10 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
247 247 assert_response 200
248 248 end
249 249  
  250 + should 'show unpublished articles as unexisting' do
  251 + profile.articles.create!(:name => 'test', :published => false)
  252 + get :view_page, :profile => profile.identifier, :page => [ 'test' ]
  253 + assert_response 404
  254 + end
  255 +
250 256 end
... ...