Commit d27a79ec04bd611e328d30a976bef7c8ad02526f
Committed by
Antonio Terceiro
1 parent
8f09db6a
Exists in
master
and in
8 other branches
Feed articles are listed even in private profiles
The access to the feed must be controlled by the content viewer access logic, not by the feed. P.S.: I'm not pretty sure if my solution have performance issues! (ActionItem1619)
Showing
3 changed files
with
32 additions
and
4 deletions
Show diff stats
app/models/profile.rb
@@ -332,6 +332,16 @@ class Profile < ActiveRecord::Base | @@ -332,6 +332,16 @@ class Profile < ActiveRecord::Base | ||
332 | self.articles.recent(limit, options) | 332 | self.articles.recent(limit, options) |
333 | end | 333 | end |
334 | 334 | ||
335 | + def last_articles(limit = 10, options = {}) | ||
336 | + options = { :limit => limit, | ||
337 | + :conditions => ["advertise = ? AND published = ? AND | ||
338 | + ((articles.type != ? and articles.type != ? and articles.type != ?) OR | ||
339 | + articles.type is NULL)", | ||
340 | + true, true, 'UploadedFile', 'RssFeed', 'Blog'], | ||
341 | + :order => 'articles.published_at desc, articles.id desc' }.merge(options) | ||
342 | + self.articles.find(:all, options) | ||
343 | + end | ||
344 | + | ||
335 | class << self | 345 | class << self |
336 | 346 | ||
337 | # finds a profile by its identifier. This method is a shortcut to | 347 | # finds a profile by its identifier. This method is a shortcut to |
app/models/rss_feed.rb
@@ -68,7 +68,7 @@ class RssFeed < Article | @@ -68,7 +68,7 @@ class RssFeed < Article | ||
68 | if (self.include == 'parent_and_children') && self.parent | 68 | if (self.include == 'parent_and_children') && self.parent |
69 | self.parent.map_traversal | 69 | self.parent.map_traversal |
70 | else | 70 | else |
71 | - profile.recent_documents(self.limit) | 71 | + profile.last_articles(self.limit) |
72 | end | 72 | end |
73 | end | 73 | end |
74 | def data | 74 | def data |
test/unit/rss_feed_test.rb
@@ -58,7 +58,7 @@ class RssFeedTest < Test::Unit::TestCase | @@ -58,7 +58,7 @@ class RssFeedTest < Test::Unit::TestCase | ||
58 | feed = RssFeed.new | 58 | feed = RssFeed.new |
59 | feed.expects(:profile).returns(profile).at_least_once | 59 | feed.expects(:profile).returns(profile).at_least_once |
60 | array = [] | 60 | array = [] |
61 | - profile.expects(:recent_documents).returns(array) | 61 | + profile.expects(:last_articles).returns(array) |
62 | feed.data | 62 | feed.data |
63 | end | 63 | end |
64 | 64 | ||
@@ -150,11 +150,11 @@ class RssFeedTest < Test::Unit::TestCase | @@ -150,11 +150,11 @@ class RssFeedTest < Test::Unit::TestCase | ||
150 | feed.profile = profile | 150 | feed.profile = profile |
151 | feed.save! | 151 | feed.save! |
152 | 152 | ||
153 | - feed.profile.expects(:recent_documents).with(10).returns([]).once | 153 | + feed.profile.expects(:last_articles).with(10).returns([]).once |
154 | feed.data | 154 | feed.data |
155 | 155 | ||
156 | feed.limit = 5 | 156 | feed.limit = 5 |
157 | - feed.profile.expects(:recent_documents).with(5).returns([]).once | 157 | + feed.profile.expects(:last_articles).with(5).returns([]).once |
158 | feed.data | 158 | feed.data |
159 | end | 159 | end |
160 | 160 | ||
@@ -218,4 +218,22 @@ class RssFeedTest < Test::Unit::TestCase | @@ -218,4 +218,22 @@ class RssFeedTest < Test::Unit::TestCase | ||
218 | assert_match published_article.to_html, feed.data | 218 | assert_match published_article.to_html, feed.data |
219 | end | 219 | end |
220 | 220 | ||
221 | + should 'display articles even within a private profile' do | ||
222 | + profile = create_user('testuser').person | ||
223 | + profile.public_profile = false | ||
224 | + profile.save! | ||
225 | + a1 = profile.articles.build(:name => 'article 1'); a1.save! | ||
226 | + a2 = profile.articles.build(:name => 'article 2'); a2.save! | ||
227 | + a3 = profile.articles.build(:name => 'article 3'); a3.save! | ||
228 | + | ||
229 | + feed = RssFeed.new(:name => 'testfeed') | ||
230 | + feed.profile = profile | ||
231 | + feed.save! | ||
232 | + | ||
233 | + rss = feed.data | ||
234 | + assert_match /<item><title>article 1<\/title>/, rss | ||
235 | + assert_match /<item><title>article 2<\/title>/, rss | ||
236 | + assert_match /<item><title>article 3<\/title>/, rss | ||
237 | + end | ||
238 | + | ||
221 | end | 239 | end |