From f75d6d82939c3c1d57015b0d48f545ea1f074913 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 4 Jun 2008 18:31:29 +0000 Subject: [PATCH] ActionItem389: not showing unpublished articles --- app/controllers/public/content_viewer_controller.rb | 4 ++++ db/migrate/036_add_published_field_to_article.rb | 17 +++++++++++++++++ test/functional/content_viewer_controller_test.rb | 6 ++++++ 3 files changed, 27 insertions(+), 0 deletions(-) create mode 100644 db/migrate/036_add_published_field_to_article.rb diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index c0fac24..e2bf33c 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -15,6 +15,10 @@ class ContentViewerController < PublicController end else @page = profile.articles.find_by_path(path) + + # do not show unpublished articles + @page = nil unless @page.published + if @page.nil? render_not_found(@path) return diff --git a/db/migrate/036_add_published_field_to_article.rb b/db/migrate/036_add_published_field_to_article.rb new file mode 100644 index 0000000..ebaf5be --- /dev/null +++ b/db/migrate/036_add_published_field_to_article.rb @@ -0,0 +1,17 @@ +class AddPublishedFieldToArticle < ActiveRecord::Migration + def self.up + add_column :articles, :published, :boolean, :default => true + execute('update articles set published = 1') + + add_column :article_versions, :published, :boolean, :default => true + end + + def self.down + if self.select('select id from articles where not published').size > 0 + raise ActiveRecord::IrreversibleMigration, 'cannot remove published column, there are articles marked as not published' + else + remove_column :articles, :published + remove_column :article_versions, :published + end + end +end diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index d1ab7cf..4a1b675 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -247,4 +247,10 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_response 200 end + should 'show unpublished articles as unexisting' do + profile.articles.create!(:name => 'test', :published => false) + get :view_page, :profile => profile.identifier, :page => [ 'test' ] + assert_response 404 + end + end -- libgit2 0.21.2