Commit 7fcb888d10ffe72abdc892a6e84d4644acf3dfcb
Exists in
master
and in
22 other branches
Merge commit 'refs/merge-requests/129' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/129 (ActionItem1549)
Showing
27 changed files
with
50 additions
and
29 deletions
Show diff stats
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 < 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 < 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 < 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 < 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
app/models/feed_reader_block.rb
app/models/highlights_block.rb
app/models/link_list_block.rb
| ... | ... | @@ -47,7 +47,7 @@ class LinkListBlock < 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
app/models/login_block.rb
app/models/main_block.rb
app/models/my_network_block.rb
app/models/products_block.rb
app/models/profile_image_block.rb
app/models/profile_info_block.rb
| ... | ... | @@ -8,7 +8,7 @@ class ProfileInfoBlock < 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
app/models/profile_search_block.rb
app/models/raw_html_block.rb
app/models/recent_documents_block.rb
| ... | ... | @@ -15,7 +15,7 @@ class RecentDocumentsBlock < 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 < 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
app/models/tags_block.rb
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 < 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 | ... | ... |