Commit 7fcb888d10ffe72abdc892a6e84d4644acf3dfcb

Authored by Daniela Feitosa
2 parents 67e58158 e2fcf1a6

Merge commit 'refs/merge-requests/129' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/129

(ActionItem1549)
app/helpers/boxes_helper.rb
... ... @@ -81,8 +81,8 @@ module BoxesHelper
81 81 box_decorator == DontMoveBlocks
82 82 end
83 83  
84   - def display_block_content(block, main_content = nil)
85   - content = block.main? ? wrap_main_content(main_content) : block.content
  84 + def display_block_content(block, person, main_content = nil)
  85 + content = block.main? ? wrap_main_content(main_content) : block.content({:person => person})
86 86 result = extract_block_content(content)
87 87 footer_content = extract_block_content(block.footer)
88 88 unless footer_content.blank?
... ...
app/models/article_block.rb
... ... @@ -8,7 +8,7 @@ class ArticleBlock < Block
8 8 _('This block displays one of your articles. You can edit the block to select which one of your articles is going to be displayed in the block.')
9 9 end
10 10  
11   - def content
  11 + def content(args={})
12 12 block = self
13 13 lambda do
14 14 block_title(block.title) +
... ...
app/models/block.rb
... ... @@ -81,7 +81,7 @@ class Block < ActiveRecord::Base
81 81 # The method can also return <tt>nil</tt>, which means "no content".
82 82 #
83 83 # See BoxesHelper#extract_block_content for implementation details.
84   - def content
  84 + def content(args={})
85 85 "This is block number %d" % self.id
86 86 end
87 87  
... ...
app/models/blog_archives_block.rb
... ... @@ -20,11 +20,15 @@ class BlogArchivesBlock &lt; Block
20 20 blog_id && owner.blogs.exists?(blog_id) ? owner.blogs.find(blog_id) : owner.blog
21 21 end
22 22  
23   - def content
  23 + def visible_posts(person)
  24 + blog.posts.native_translations.select {|post| post.display_to?(person)}
  25 + end
  26 +
  27 + def content(args={})
24 28 owner_blog = self.blog
25 29 return nil unless owner_blog
26 30 results = ''
27   - owner_blog.posts.native_translations.group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year|
  31 + visible_posts(args[:person]).group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year|
28 32 results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})"))
29 33 results << "<ul class='#{year}-archive'>"
30 34 results_by_year.group_by{|i| [ ('%02d' % i.published_at.month()), gettext(MONTHS[i.published_at.month() - 1])]}.sort.reverse.each do |month, results_by_month|
... ...
app/models/categories_block.rb
... ... @@ -28,7 +28,7 @@ class CategoriesBlock &lt; Block
28 28 Category.top_level_for(self.owner).from_types(self.category_types)
29 29 end
30 30  
31   - def content
  31 + def content(args={})
32 32 block = self
33 33 lambda do
34 34 render :file => 'blocks/categories', :locals => { :block => block }
... ...
app/models/disabled_enterprise_message_block.rb
... ... @@ -12,7 +12,7 @@ class DisabledEnterpriseMessageBlock &lt; Block
12 12 _('Message')
13 13 end
14 14  
15   - def content
  15 + def content(args={})
16 16 message = self.owner.environment.message_for_disabled_enterprise || ''
17 17 lambda do
18 18 render :file => 'blocks/disabled_enterprise_message', :locals => {:message => message}
... ...
app/models/environment_statistics_block.rb
... ... @@ -12,7 +12,7 @@ class EnvironmentStatisticsBlock &lt; Block
12 12 _('This block presents some statistics about your environment.')
13 13 end
14 14  
15   - def content
  15 + def content(args={})
16 16 users = owner.people.visible.count
17 17 enterprises = owner.enterprises.visible.count
18 18 communities = owner.communities.visible.count
... ...
app/models/featured_products_block.rb
... ... @@ -25,7 +25,7 @@ class FeaturedProductsBlock &lt; Block
25 25 self.owner.highlighted_products_with_image
26 26 end
27 27  
28   - def content
  28 + def content(args={})
29 29 block = self
30 30 lambda do
31 31 render :file => 'blocks/featured_products', :locals => { :block => block }
... ...
app/models/feed_reader_block.rb
... ... @@ -78,7 +78,7 @@ class FeedReaderBlock &lt; Block
78 78 self.save!
79 79 end
80 80  
81   - def content
  81 + def content(args={})
82 82 block_title(title) + formatted_feed_content
83 83 end
84 84  
... ...
app/models/highlights_block.rb
... ... @@ -28,7 +28,7 @@ class HighlightsBlock &lt; Block
28 28 shuffle ? block_images.shuffle : block_images
29 29 end
30 30  
31   - def content
  31 + def content(args={})
32 32 block = self
33 33 lambda do
34 34 render :file => 'blocks/highlights', :locals => { :block => block }
... ...
app/models/link_list_block.rb
... ... @@ -47,7 +47,7 @@ class LinkListBlock &lt; Block
47 47 _('This block can be used to create a menu of links. You can add, remove and update the links as you wish.')
48 48 end
49 49  
50   - def content
  50 + def content(args={})
51 51 block_title(title) +
52 52 content_tag('ul',
53 53 links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_html(i))}
... ...
app/models/location_block.rb
... ... @@ -11,7 +11,7 @@ class LocationBlock &lt; Block
11 11 _('Shows where the profile is on the material world.')
12 12 end
13 13  
14   - def content
  14 + def content(args={})
15 15 profile = self.owner
16 16 title = self.title
17 17 if profile.lat
... ...
app/models/login_block.rb
... ... @@ -8,7 +8,7 @@ class LoginBlock &lt; Block
8 8 _('This block presents a login/logout block.')
9 9 end
10 10  
11   - def content
  11 + def content(args={})
12 12 lambda do
13 13 render :file => 'blocks/login_block'
14 14 end
... ...
app/models/main_block.rb
... ... @@ -8,7 +8,7 @@ class MainBlock &lt; Block
8 8 _('This block presents the main content of your pages.')
9 9 end
10 10  
11   - def content
  11 + def content(args={})
12 12 nil
13 13 end
14 14  
... ...
app/models/my_network_block.rb
... ... @@ -14,7 +14,7 @@ class MyNetworkBlock &lt; Block
14 14 _('This block displays some info about your networking.')
15 15 end
16 16  
17   - def content
  17 + def content(args={})
18 18 block = self
19 19 lambda do
20 20 render :file => 'blocks/my_network', :locals => {
... ...
app/models/products_block.rb
... ... @@ -16,7 +16,7 @@ class ProductsBlock &lt; Block
16 16 _('This block presents a list of your products.')
17 17 end
18 18  
19   - def content
  19 + def content(args={})
20 20 block_title(title) +
21 21 content_tag(
22 22 'ul',
... ...
app/models/profile_image_block.rb
... ... @@ -10,7 +10,7 @@ class ProfileImageBlock &lt; Block
10 10 _('This block presents the profile image')
11 11 end
12 12  
13   - def content
  13 + def content(args={})
14 14 block = self
15 15 s = show_name
16 16 lambda do
... ...
app/models/profile_info_block.rb
... ... @@ -8,7 +8,7 @@ class ProfileInfoBlock &lt; Block
8 8 _('Basic information about <i>%{user}</i>: how long <i>%{user}</i> is part of <i>%{env}</i> and useful links.') % { :user => self.owner.name(), :env => self.owner.environment.name() }
9 9 end
10 10  
11   - def content
  11 + def content(args={})
12 12 block = self
13 13 lambda do
14 14 render :file => 'blocks/profile_info', :locals => { :block => block }
... ...
app/models/profile_list_block.rb
... ... @@ -37,7 +37,7 @@ class ProfileListBlock &lt; Block
37 37 _('Clicking on the people or groups will take you to their home page.')
38 38 end
39 39  
40   - def content
  40 + def content(args={})
41 41 profiles = self.profile_list
42 42 title = self.view_title
43 43 nl = "\n"
... ...
app/models/profile_search_block.rb
... ... @@ -4,7 +4,7 @@ class ProfileSearchBlock &lt; Block
4 4 _('Display a form to search the profile')
5 5 end
6 6  
7   - def content
  7 + def content(args={})
8 8 title = self.title
9 9 lambda do
10 10 render :file => 'blocks/profile_search', :locals => { :title => title }
... ...
app/models/raw_html_block.rb
... ... @@ -6,7 +6,7 @@ class RawHTMLBlock &lt; Block
6 6  
7 7 settings_items :html, :type => :text
8 8  
9   - def content
  9 + def content(args={})
10 10 (title.blank? ? '' : block_title(title)) + html.to_s
11 11 end
12 12  
... ...
app/models/recent_documents_block.rb
... ... @@ -15,7 +15,7 @@ class RecentDocumentsBlock &lt; Block
15 15 settings_items :limit, :type => :integer, :default => 5
16 16  
17 17 include ActionController::UrlWriter
18   - def content
  18 + def content(args={})
19 19 docs = self.limit.nil? ? owner.recent_documents : owner.recent_documents(self.limit)
20 20  
21 21 block_title(title) +
... ...
app/models/sellers_search_block.rb
... ... @@ -16,7 +16,7 @@ class SellersSearchBlock &lt; Block
16 16 _('This block presents a search engine for products.')
17 17 end
18 18  
19   - def content
  19 + def content(args={})
20 20 title = self.title
21 21 lambda do
22 22 render :file => 'search/_sellers_form', :locals => { :title => title }
... ...
app/models/slideshow_block.rb
... ... @@ -31,7 +31,7 @@ class SlideshowBlock &lt; Block
31 31 gallery.images.reject {|item| item.folder?}
32 32 end
33 33  
34   - def content
  34 + def content(args={})
35 35 block = self
36 36 if gallery
37 37 images = block_images
... ...
app/models/tags_block.rb
... ... @@ -19,7 +19,7 @@ class TagsBlock &lt; Block
19 19 Try to add some tags to some articles and you'l see your tag cloud growing.")
20 20 end
21 21  
22   - def content
  22 + def content(args={})
23 23 tags = owner.article_tags
24 24 return '' if tags.empty?
25 25  
... ...
app/views/shared/block.rhtml
1 1 <% if block.cacheable? && use_cache %>
2 2 <% cache_timeout(block.cache_key, block.timeout.from_now) do %>
3   - <%= display_block_content(block, main_content) %>
  3 + <%= display_block_content(block, user, main_content) %>
4 4 <% end %>
5 5 <% else %>
6   - <%= display_block_content(block, main_content) %>
  6 + <%= display_block_content(block, user, main_content) %>
7 7 <% end %>
... ...
test/unit/blog_archives_block_test.rb
... ... @@ -157,4 +157,21 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
157 157 end
158 158 end
159 159  
  160 + should 'not count articles if the user can\'t see them' do
  161 + person = create_user('testuser').person
  162 + blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path')
  163 + block = fast_create(BlogArchivesBlock)
  164 +
  165 + feed = mock()
  166 + feed.stubs(:url).returns('feed_url')
  167 + blog.stubs(:feed).returns(feed)
  168 + block.stubs(:blog).returns(blog)
  169 + block.stubs(:owner).returns(profile)
  170 +
  171 + public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan'))
  172 + private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan'))
  173 +
  174 + assert_match /January \(1\)/, block.content({:person => person})
  175 + assert_match /January \(2\)/, block.content({:person => profile})
  176 + end
160 177 end
... ...