Commit bccf7c4265edfe8fc3b309359bcc396ab1d6aeae

Authored by Aurelio A. Heckert
1 parent f13dcf68

ActionItem690: recent content block do not lists private articles. finaly.

app/models/article.rb
... ... @@ -77,7 +77,23 @@ class Article < ActiveRecord::Base
77 77 #
78 78 # Only includes articles where advertise == true
79 79 def self.recent(limit)
80   - options = { :limit => limit, :conditions => { :advertise => true, :public_article => true }, :order => 'created_at desc, articles.id desc' }
  80 + # FIXME this method is a horrible hack
  81 + options = { :limit => limit,
  82 + :conditions => {
  83 + :advertise => true,
  84 + :public_article => true,
  85 + :published => true,
  86 + 'profiles.public_profile' => true
  87 + },
  88 + :include => 'profile',
  89 + :order => 'articles.created_at desc, articles.id desc'
  90 + }
  91 + if ( scoped_methods && scoped_methods.last &&
  92 + scoped_methods.last[:find] &&
  93 + scoped_methods.last[:find][:joins] &&
  94 + scoped_methods.last[:find][:joins].index('profiles') )
  95 + options.delete(:include)
  96 + end
81 97 self.find(:all, options)
82 98 end
83 99  
... ...
test/unit/article_test.rb
... ... @@ -137,6 +137,38 @@ class ArticleTest < Test::Unit::TestCase
137 137 assert_equal [other_first, fifth, fourth, third, second, first], Article.recent(6)
138 138 end
139 139  
  140 + should 'not show private documents as recent' do
  141 + p = create_user('usr1').person
  142 + Article.destroy_all
  143 +
  144 + first = p.articles.build(:name => 'first', :public_article => true); first.save!
  145 + second = p.articles.build(:name => 'second', :public_article => false); second.save!
  146 +
  147 + assert_equal [ first ], Article.recent(nil)
  148 + end
  149 +
  150 + should 'not show unpublished documents as recent' do
  151 + p = create_user('usr1').person
  152 + Article.destroy_all
  153 +
  154 + first = p.articles.build(:name => 'first', :published => true); first.save!
  155 + second = p.articles.build(:name => 'second', :published => false); second.save!
  156 +
  157 + assert_equal [ first ], Article.recent(nil)
  158 + end
  159 +
  160 + should 'not show documents from a private profile as recent' do
  161 + p = create_user('usr1').person
  162 + p.public_profile = false
  163 + p.save!
  164 + Article.destroy_all
  165 +
  166 + first = p.articles.build(:name => 'first', :published => true); first.save!
  167 + second = p.articles.build(:name => 'second', :published => false); second.save!
  168 +
  169 + assert_equal [ ], Article.recent(nil)
  170 + end
  171 +
140 172 should 'require that subclasses define description' do
141 173 assert_raise NotImplementedError do
142 174 Article.description
... ...