diff --git a/app/helpers/folder_helper.rb b/app/helpers/folder_helper.rb
index 288d1cb..13b8917 100644
--- a/app/helpers/folder_helper.rb
+++ b/app/helpers/folder_helper.rb
@@ -1,11 +1,15 @@
module FolderHelper
- def list_articles(articles, recursive = false)
- content_tag(
- 'table',
- content_tag('tr', content_tag('th', _('Title')) + content_tag('th', _('Last update'))) +
- articles.select { |item| item.public? }.map {|item| display_article_in_listing(item, recursive, 0)}.join('')
- )
+ def list_articles(articles, user, recursive = false)
+ if !articles.blank?
+ content_tag(
+ 'table',
+ content_tag('tr', content_tag('th', _('Title')) + content_tag('th', _('Last update'))) +
+ articles.select { |item| item.display_to?(user)}.map {|item| display_article_in_listing(item, recursive, 0)}.join('')
+ )
+ else
+ content_tag('em', _('(empty folder)'))
+ end
end
def display_article_in_listing(article, recursive = false, level = 0)
diff --git a/app/models/folder.rb b/app/models/folder.rb
index 52da75e..d02847d 100644
--- a/app/models/folder.rb
+++ b/app/models/folder.rb
@@ -39,7 +39,7 @@ class Folder < Article
end
def folder
- content_tag('div', body) + tag('hr') + (children.empty? ? content_tag('em', _('(empty folder)')) : list_articles(children))
+ content_tag('div', body) + tag('hr')
end
def image_gallery
diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml
index ee16534..b405289 100644
--- a/app/views/content_viewer/view_page.rhtml
+++ b/app/views/content_viewer/view_page.rhtml
@@ -85,6 +85,9 @@
<% cache(@page.cache_key(params, user)) do %>
">
<%= article_to_html(@page) %>
+ <% if @page.folder? %>
+ <%= list_articles(@page.children, user)%>
+ <% end %>
<% end %>
diff --git a/app/views/profile/sitemap.rhtml b/app/views/profile/sitemap.rhtml
index fd74211..4f7c8da 100644
--- a/app/views/profile/sitemap.rhtml
+++ b/app/views/profile/sitemap.rhtml
@@ -1,3 +1,3 @@
<%= _("%s: site map") % profile.name %>
-<%= list_articles(@articles, false) %>
+<%= list_articles(@articles, user) %>
diff --git a/test/unit/folder_helper_test.rb b/test/unit/folder_helper_test.rb
index c0cb378..cbc2805 100644
--- a/test/unit/folder_helper_test.rb
+++ b/test/unit/folder_helper_test.rb
@@ -15,4 +15,82 @@ class FolderHelperTest < Test::Unit::TestCase
assert_equal 'icons-mime/unknown.png', icon_for_article(art2)
end
+ should 'list all the folder\'s children to the owner' do
+ profile = create_user('Folder Owner').person
+ folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id})
+ sub_folder = fast_create(Folder, {:name => 'Child Folder', :parent_id => folder.id,
+ :profile_id => profile.id})
+ sub_blog = fast_create(Blog, {:name => 'Child Blog', :parent_id => folder.id,
+ :profile_id => profile.id})
+ sub_article = fast_create(Article, {:name => 'Not Public Child Article', :parent_id =>
+ folder.id, :profile_id => profile.id, :published => false})
+
+ result = folder.list_articles(folder.children, profile)
+
+ assert_match 'Child Folder', result
+ assert_match 'Not Public Child Article', result
+ assert_match 'Child Blog', result
+ end
+
+ should 'list the folder\'s children that are public to the user' do
+ profile = create_user('Folder Owner').person
+ profile2 = create_user('Folder Viwer').person
+ folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id})
+ public_article = fast_create(Article, {:name => 'Public Article', :parent_id =>
+ folder.id, :profile_id => profile.id, :published => true})
+ not_public_article = fast_create(Article, {:name => 'Not Public Article', :parent_id =>
+ folder.id, :profile_id => profile.id, :published => false})
+
+ result = folder.list_articles(folder.children, profile2)
+
+ assert_match 'Public Article', result
+ assert_no_match /Not Public Article/, result
+ end
+
+ should ' not list the folder\'s children to the user because the owner\'s profile is not public' do
+ profile = create_user('folder-owner').person
+ profile.public_profile = false
+ profile.save!
+ profile2 = create_user('Folder Viwer').person
+ folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id})
+ article = fast_create(Article, {:name => 'Article', :parent_id => folder.id, :profile_id => profile.id})
+
+ result = folder.list_articles(folder.children, profile2)
+
+ assert_no_match /Article/, result
+ end
+
+ should ' not list the folder\'s children to the user because the owner\'s profile is not visible' do
+ profile = create_user('folder-owner').person
+ profile.visible = false
+ profile.save!
+ profile2 = create_user('Folder Viwer').person
+ folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id})
+ article = fast_create(Article, {:name => 'Article', :parent_id => folder.id, :profile_id => profile.id})
+
+ result = folder.list_articles(folder.children, profile2)
+
+ assert_no_match /Article/, result
+ end
+
+ should 'list subitems as HTML content' do
+ profile = create_user('folder-owner').person
+ folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id})
+ article = fast_create(Article, {:name => 'Article1', :parent_id => folder.id, :profile_id => profile.id})
+ article = fast_create(Article, {:name => 'Article2', :parent_id => folder.id, :profile_id => profile.id})
+
+ result = folder.list_articles(folder.children, profile)
+
+ assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article1/
+ assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article2/
+ end
+
+ should 'explictly advise if empty' do
+ profile = create_user('folder-owner').person
+ folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id})
+ result = folder.list_articles(folder.children, profile)
+
+ assert_match '(empty folder)', result
+ end
+
end
diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb
index a22f96f..bc7d31b 100644
--- a/test/unit/folder_test.rb
+++ b/test/unit/folder_test.rb
@@ -18,23 +18,6 @@ class FolderTest < ActiveSupport::TestCase
assert_not_equal Article.new.icon_name, Folder.new.icon_name
end
- should 'list subitems as HTML content' do
- p = create_user('testuser').person
- f = Folder.create!(:profile => p, :name => 'f')
- f.children.create!(:profile => p, :name => 'onearticle')
- f.children.create!(:profile => p, :name => 'otherarticle')
- f.reload
-
- assert_tag_in_string f.to_html, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/onearticle(\?|$)/ } }, :content => /onearticle/
- assert_tag_in_string f.to_html, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/otherarticle(\?|$)/ } }, :content => /otherarticle/
- end
-
- should 'explictly advise if empty' do
- p = create_user('testuser').person
- f = Folder.create!(:profile => p, :name => 'f')
- assert_tag_in_string f.to_html, :content => '(empty folder)'
- end
-
should 'show text body in HTML content' do
p = create_user('testuser').person
f = Folder.create!(:name => 'f', :profile => p, :body => 'this-is-the-text')
--
libgit2 0.21.2