Commit f75d6d82939c3c1d57015b0d48f545ea1f074913
1 parent
04cb32bb
Exists in
master
and in
29 other branches
ActionItem389: not showing unpublished articles
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1867 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
27 additions
and
0 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
@@ -15,6 +15,10 @@ class ContentViewerController < PublicController | @@ -15,6 +15,10 @@ class ContentViewerController < PublicController | ||
15 | end | 15 | end |
16 | else | 16 | else |
17 | @page = profile.articles.find_by_path(path) | 17 | @page = profile.articles.find_by_path(path) |
18 | + | ||
19 | + # do not show unpublished articles | ||
20 | + @page = nil unless @page.published | ||
21 | + | ||
18 | if @page.nil? | 22 | if @page.nil? |
19 | render_not_found(@path) | 23 | render_not_found(@path) |
20 | return | 24 | return |
@@ -0,0 +1,17 @@ | @@ -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 < Test::Unit::TestCase | @@ -247,4 +247,10 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
247 | assert_response 200 | 247 | assert_response 200 |
248 | end | 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 | end | 256 | end |